REminiscence/mixer.h

95 lines
1.7 KiB
C
Raw Permalink Normal View History

2016-03-20 17:00:00 +01:00
/*
* REminiscence - Flashback interpreter
2019-10-27 17:00:00 +01:00
* Copyright (C) 2005-2019 Gregory Montoir (cyx@users.sourceforge.net)
2015-08-02 18:00:00 +02:00
*/
#ifndef MIXER_H__
#define MIXER_H__
#include "intern.h"
2019-10-27 17:00:00 +01:00
#include "cpc_player.h"
2015-08-02 18:00:00 +02:00
#include "mod_player.h"
#include "ogg_player.h"
2023-03-31 15:23:51 +02:00
#include "prf_player.h"
2015-08-02 18:00:00 +02:00
#include "sfx_player.h"
struct MixerChunk {
2019-10-27 17:00:00 +01:00
const uint8_t *data;
2015-08-02 18:00:00 +02:00
uint32_t len;
MixerChunk()
: data(0), len(0) {
}
int8_t getPCM(int offset) const {
if (offset < 0) {
offset = 0;
} else if (offset >= (int)len) {
offset = len - 1;
}
return (int8_t)data[offset];
}
};
struct MixerChannel {
uint8_t active;
uint8_t volume;
MixerChunk chunk;
uint32_t chunkPos;
uint32_t chunkInc;
};
struct FileSystem;
struct SystemStub;
struct Mixer {
2016-05-09 18:00:00 +02:00
typedef bool (*PremixHook)(void *userData, int16_t *buf, int len);
2015-08-02 18:00:00 +02:00
enum MusicType {
MT_NONE,
MT_MOD,
MT_OGG,
2023-03-31 15:23:51 +02:00
MT_PRF,
2015-08-02 18:00:00 +02:00
MT_SFX,
2019-10-27 17:00:00 +01:00
MT_CPC,
2015-08-02 18:00:00 +02:00
};
enum {
MUSIC_TRACK = 1000,
NUM_CHANNELS = 4,
FRAC_BITS = 12,
MAX_VOLUME = 64
};
FileSystem *_fs;
SystemStub *_stub;
MixerChannel _channels[NUM_CHANNELS];
PremixHook _premixHook;
void *_premixHookData;
2019-10-27 17:00:00 +01:00
MusicType _backgroundMusicType;
2015-08-02 18:00:00 +02:00
MusicType _musicType;
2019-10-27 17:00:00 +01:00
CpcPlayer _cpc;
2015-08-02 18:00:00 +02:00
ModPlayer _mod;
OggPlayer _ogg;
2023-03-31 15:23:51 +02:00
PrfPlayer _prf;
2015-08-02 18:00:00 +02:00
SfxPlayer _sfx;
int _musicTrack;
2023-03-31 15:23:51 +02:00
Mixer(FileSystem *fs, SystemStub *stub, int midiDriver);
2015-08-02 18:00:00 +02:00
void init();
void free();
void setPremixHook(PremixHook premixHook, void *userData);
2019-10-27 17:00:00 +01:00
void play(const uint8_t *data, uint32_t len, uint16_t freq, uint8_t volume);
bool isPlaying(const uint8_t *data) const;
2015-08-02 18:00:00 +02:00
uint32_t getSampleRate() const;
void stopAll();
2023-04-15 02:44:11 +02:00
void playMusic(int num, int tempo = 0);
2015-08-02 18:00:00 +02:00
void stopMusic();
2016-05-09 18:00:00 +02:00
void mix(int16_t *buf, int len);
2015-08-02 18:00:00 +02:00
2016-05-09 18:00:00 +02:00
static void mixCallback(void *param, int16_t *buf, int len);
2015-08-02 18:00:00 +02:00
};
#endif // MIXER_H__