1 2 /* 3 * REminiscence - Flashback interpreter 4 * Copyright (C) 2005-2019 Gregory Montoir (cyx@users.sourceforge.net) 5 */ 6 7 #ifndef MIXER_H__ 8 #define MIXER_H__ 9 10 #include "intern.h" 11 #include "cpc_player.h" 12 #include "mod_player.h" 13 #include "ogg_player.h" 14 #include "sfx_player.h" 15 16 struct MixerChunk { 17 const uint8_t *data; 18 uint32_t len; 19 MixerChunkMixerChunk20 MixerChunk() 21 : data(0), len(0) { 22 } 23 getPCMMixerChunk24 int8_t getPCM(int offset) const { 25 if (offset < 0) { 26 offset = 0; 27 } else if (offset >= (int)len) { 28 offset = len - 1; 29 } 30 return (int8_t)data[offset]; 31 } 32 }; 33 34 struct MixerChannel { 35 uint8_t active; 36 uint8_t volume; 37 MixerChunk chunk; 38 uint32_t chunkPos; 39 uint32_t chunkInc; 40 }; 41 42 struct FileSystem; 43 struct SystemStub; 44 45 struct Mixer { 46 typedef bool (*PremixHook)(void *userData, int16_t *buf, int len); 47 48 enum MusicType { 49 MT_NONE, 50 MT_MOD, 51 MT_OGG, 52 MT_SFX, 53 MT_CPC, 54 }; 55 56 enum { 57 MUSIC_TRACK = 1000, 58 NUM_CHANNELS = 4, 59 FRAC_BITS = 12, 60 MAX_VOLUME = 64 61 }; 62 63 FileSystem *_fs; 64 SystemStub *_stub; 65 MixerChannel _channels[NUM_CHANNELS]; 66 PremixHook _premixHook; 67 void *_premixHookData; 68 MusicType _backgroundMusicType; 69 MusicType _musicType; 70 CpcPlayer _cpc; 71 ModPlayer _mod; 72 OggPlayer _ogg; 73 SfxPlayer _sfx; 74 int _musicTrack; 75 76 Mixer(FileSystem *fs, SystemStub *stub); 77 void init(); 78 void free(); 79 void setPremixHook(PremixHook premixHook, void *userData); 80 void play(const uint8_t *data, uint32_t len, uint16_t freq, uint8_t volume); 81 bool isPlaying(const uint8_t *data) const; 82 uint32_t getSampleRate() const; 83 void stopAll(); 84 void playMusic(int num); 85 void stopMusic(); 86 void mix(int16_t *buf, int len); 87 88 static void mixCallback(void *param, int16_t *buf, int len); 89 }; 90 91 #endif // MIXER_H__ 92