GB: Add back volume

This commit is contained in:
Jeffrey Pfau 2016-02-09 23:29:25 -08:00
parent 5bcf56c5ca
commit f1f9dee111
4 changed files with 9 additions and 4 deletions

View File

@ -14,6 +14,7 @@
const uint32_t DMG_LR35902_FREQUENCY = 0x400000;
static const int CLOCKS_PER_BLIP_FRAME = 0x1000;
static const unsigned BLIP_BUFFER_SIZE = 0x4000;
const int GB_AUDIO_VOLUME_MAX = 0x100;
static void _writeDuty(struct GBAudioEnvelope* envelope, uint8_t value);
static bool _writeSweep(struct GBAudioEnvelope* envelope, uint8_t value);
@ -38,6 +39,7 @@ void GBAudioInit(struct GBAudio* audio, size_t samples) {
audio->forceDisableCh[1] = false;
audio->forceDisableCh[2] = false;
audio->forceDisableCh[3] = false;
audio->masterVolume = GB_AUDIO_VOLUME_MAX;
}
void GBAudioDeinit(struct GBAudio* audio) {
@ -641,8 +643,8 @@ void _sample(struct GBAudio* audio, int32_t cycles) {
int16_t sampleLeft = 0;
int16_t sampleRight = 0;
GBAudioSamplePSG(audio, &sampleLeft, &sampleRight);
sampleLeft <<= 1;
sampleRight <<= 1;
sampleLeft = (sampleLeft * audio->masterVolume) >> 6;
sampleRight = (sampleRight * audio->masterVolume) >> 6;
mCoreSyncLockAudio(audio->p->sync);
unsigned produced;

View File

@ -183,6 +183,7 @@ struct GBAudio {
size_t samples;
bool forceDisableCh[4];
int masterVolume;
};
void GBAudioInit(struct GBAudio* audio, size_t samples);

View File

@ -66,9 +66,10 @@ static void _GBCoreSetSync(struct mCore* core, struct mCoreSync* sync) {
}
static void _GBCoreLoadConfig(struct mCore* core, const struct mCoreConfig* config) {
UNUSED(core);
UNUSED(config);
// TODO
struct GB* gb = core->board;
gb->audio.masterVolume = core->opts.volume;
}
static void _GBCoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) {

View File

@ -76,6 +76,7 @@ static void _GBACoreSetSync(struct mCore* core, struct mCoreSync* sync) {
static void _GBACoreLoadConfig(struct mCore* core, const struct mCoreConfig* config) {
struct GBA* gba = core->board;
gba->audio.masterVolume = core->opts.volume;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
struct GBACore* gbacore = (struct GBACore*) core;