/
audio_sdl.h
77 lines (65 loc) · 2.14 KB
/
audio_sdl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIO_SDL_H_
#define _AUDIO_SDL_H_
#include "audio.h"
#include "audio_decoder.h"
#include "audio_secache.h"
#include <map>
#include <SDL.h>
#include <SDL_mixer.h>
struct SdlAudio : public AudioInterface {
SdlAudio();
~SdlAudio();
void BGM_Play(std::string const&, int, int, int) override;
void BGM_Pause() override;
void BGM_Resume() override;
void BGM_Stop() override;
bool BGM_PlayedOnce() const override;
bool BGM_IsPlaying() const override;
unsigned BGM_GetTicks() const override;
void BGM_Fade(int) override;
void BGM_Volume(int) override;
void BGM_Pitch(int) override;
void BGS_Play(std::string const&, int, int, int);
void BGS_Pause();
void BGS_Resume();
void BGS_Stop();
void BGS_Fade(int);
void BGS_Volume(int);
void SE_Play(std::string const&, int, int) override;
void SE_Stop() override;
void Update() override;
void BGM_OnPlayedOnce();
AudioDecoder* GetDecoder();
SDL_AudioCVT& GetAudioCVT();
private:
void SetupAudioDecoder(FILE* handle, const std::string& filename, int volume, int pitch, int fadein);
std::shared_ptr<Mix_Music> bgm;
int bgm_volume;
unsigned bgm_starttick = 0;
bool bgm_stop = true;
std::shared_ptr<Mix_Chunk> bgs;
bool bgs_playing = false;
bool bgs_stop = true;
bool played_once = false;
typedef std::map<int, std::pair<std::shared_ptr<Mix_Chunk>, AudioSeRef>> sounds_type;
sounds_type sounds;
std::unique_ptr<AudioDecoder> audio_decoder;
SDL_AudioCVT cvt;
}; // class SdlAudio
#endif // _AUDIO_SDL_H_