Core: Add core.setAudioBufferSize
Jeffrey Pfau jeffrey@endrift.com
Mon, 08 Feb 2016 21:21:17 -0800
10 files changed,
30 insertions(+),
6 deletions(-)
M
src/core/core.h
→
src/core/core.h
@@ -54,6 +54,7 @@ void (*setVideoBuffer)(struct mCore*, color_t* buffer, size_t stride);
void (*getVideoBuffer)(struct mCore*, color_t** buffer, size_t* stride); struct blip_t* (*getAudioChannel)(struct mCore*, int ch); + void (*setAudioBufferSize)(struct mCore*, size_t samples); void (*setAVStream)(struct mCore*, struct mAVStream*);
M
src/gb/audio.c
→
src/gb/audio.c
@@ -76,6 +76,15 @@ audio->playingCh3 = false;
audio->playingCh4 = false; } +void GBAudioResizeBuffer(struct GBAudio* audio, size_t samples) { + mCoreSyncLockAudio(audio->p->sync); + audio->samples = samples; + blip_clear(audio->left); + blip_clear(audio->right); + audio->clock = 0; + mCoreSyncConsumeAudio(audio->p->sync); +} + void GBAudioWriteNR10(struct GBAudio* audio, uint8_t value) { audio->ch1.shift = GBAudioRegisterSquareSweepGetShift(value); audio->ch1.direction = GBAudioRegisterSquareSweepGetDirection(value);
M
src/gb/audio.h
→
src/gb/audio.h
@@ -187,6 +187,8 @@ void GBAudioInit(struct GBAudio* audio, size_t samples);
void GBAudioDeinit(struct GBAudio* audio); void GBAudioReset(struct GBAudio* audio); +void GBAudioResizeBuffer(struct GBAudio* audio, size_t samples); + void GBAudioWriteNR10(struct GBAudio* audio, uint8_t); void GBAudioWriteNR11(struct GBAudio* audio, uint8_t); void GBAudioWriteNR12(struct GBAudio* audio, uint8_t);
M
src/gb/core.c
→
src/gb/core.c
@@ -96,6 +96,11 @@ return NULL;
} } +static void _GBCoreSetAudioBufferSize(struct mCore* core, size_t samples) { + struct GB* gb = core->board; + GBAudioResizeBuffer(&gb->audio, samples); +} + static void _GBCoreSetAVStream(struct mCore* core, struct mAVStream* stream) { // TODO }@@ -225,6 +230,7 @@ core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions;
core->setVideoBuffer = _GBCoreSetVideoBuffer; core->getVideoBuffer = _GBCoreGetVideoBuffer; core->getAudioChannel = _GBCoreGetAudioChannel; + core->setAudioBufferSize = _GBCoreSetAudioBufferSize; core->setAVStream = _GBCoreSetAVStream; core->isROM = GBIsROM; core->loadROM = _GBCoreLoadROM;
M
src/gba/core.c
→
src/gba/core.c
@@ -127,6 +127,11 @@ return NULL;
} } +static void _GBACoreSetAudioBufferSize(struct mCore* core, size_t samples) { + struct GBA* gba = core->board; + GBAAudioResizeBuffer(&gba->audio, samples); +} + static void _GBACoreSetAVStream(struct mCore* core, struct mAVStream* stream) { struct GBA* gba = core->board; gba->stream = stream;@@ -261,6 +266,7 @@ core->desiredVideoDimensions = _GBACoreDesiredVideoDimensions;
core->setVideoBuffer = _GBACoreSetVideoBuffer; core->getVideoBuffer = _GBACoreGetVideoBuffer; core->getAudioChannel = _GBACoreGetAudioChannel; + core->setAudioBufferSize = _GBACoreSetAudioBufferSize; core->setAVStream = _GBACoreSetAVStream; core->isROM = GBAIsROM; core->loadROM = _GBACoreLoadROM;
M
src/platform/3ds/main.c
→
src/platform/3ds/main.c
@@ -273,7 +273,7 @@ if (mCoreConfigGetUIntValue(&runner->core->config, "screenMode", &mode) && mode < SM_MAX) {
screenMode = mode; } - GBAAudioResizeBuffer(&((struct GBA*) runner->core->board)->audio, AUDIO_SAMPLES); + runner->core->setAudioBufferSize(runner->core, AUDIO_SAMPLES); } static void _gameLoaded(struct mGUIRunner* runner) {
M
src/platform/libretro/libretro.c
→
src/platform/libretro/libretro.c
@@ -205,7 +205,7 @@ core = GBACoreCreate();
mCoreInitConfig(core, NULL); core->init(core); struct GBA* gba = core->board; - gba->stream = &stream; + core->setAVStream(core, &stream); if (rumbleCallback) { gba->rumble = &rumble; }@@ -224,7 +224,7 @@
outputBuffer = malloc(256 * VIDEO_VERTICAL_PIXELS * BYTES_PER_PIXEL); core->setVideoBuffer(core, outputBuffer, 256); - GBAAudioResizeBuffer(&gba->audio, SAMPLES); + core->setAudioBufferSize(core, SAMPLES); blip_set_rates(core->getAudioChannel(core, 0), GBA_ARM7TDMI_FREQUENCY, 32768); blip_set_rates(core->getAudioChannel(core, 1), GBA_ARM7TDMI_FREQUENCY, 32768);
M
src/platform/openemu/mGBAGameCore.m
→
src/platform/openemu/mGBAGameCore.m
@@ -73,9 +73,9 @@ unsigned width, height;
core->desiredVideoDimensions(core, &width, &height); outputBuffer = malloc(width * height * BYTES_PER_PIXEL); core->setVideoBuffer(core, outputBuffer, width); + core->setAudioBufferSize(core, SAMPLES); gba = core->board; - GBAAudioResizeBuffer(&gba->audio, SAMPLES); GBACheatDeviceCreate(&cheats); GBACheatAttachDevice(gba, &cheats); cheatSets = [[NSMutableDictionary alloc] init];
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -932,7 +932,7 @@
void GameController::redoSamples(int samples) { // TODO: Put back audio buffers if (m_threadContext.core) { - GBAAudioResizeBuffer(&static_cast<GBA*>(m_threadContext.core->board)->audio, samples); + m_threadContext.core->setAudioBufferSize(m_threadContext.core, samples); } QMetaObject::invokeMethod(m_audioProcessor, "inputParametersChanged"); }
M
src/platform/wii/main.c
→
src/platform/wii/main.c
@@ -569,7 +569,7 @@
outputBuffer = memalign(32, 256 * 256 * BYTES_PER_PIXEL); runner->core->setVideoBuffer(runner->core, outputBuffer, 256); - GBAAudioResizeBuffer(&((struct GBA*) runner->core->board)->audio, SAMPLES); + runner->core->setAudioBufferSize(runner->core, SAMPLES); double ratio = GBAAudioCalculateRatio(1, 60 / 1.001, 1); blip_set_rates(runner->core->getAudioChannel(runner->core, 0), GBA_ARM7TDMI_FREQUENCY, 48000 * ratio);