GB: Add back volume
Jeffrey Pfau jeffrey@endrift.com
Tue, 09 Feb 2016 23:29:25 -0800
4 files changed,
9 insertions(+),
4 deletions(-)
M
src/gb/audio.c
→
src/gb/audio.c
@@ -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 @@ audio->forceDisableCh[0] = false;
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;
M
src/gb/audio.h
→
src/gb/audio.h
@@ -183,6 +183,7 @@ bool enable;
size_t samples; bool forceDisableCh[4]; + int masterVolume; }; void GBAudioInit(struct GBAudio* audio, size_t samples);
M
src/gb/core.c
→
src/gb/core.c
@@ -66,9 +66,10 @@ gb->sync = 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) {
M
src/gba/core.c
→
src/gba/core.c
@@ -76,6 +76,7 @@ }
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;