Core: Add core.setAudioBufferSize

This commit is contained in:
Jeffrey Pfau 2016-02-08 21:21:17 -08:00
parent 9ec62368bc
commit 2af1bf68e0
10 changed files with 30 additions and 6 deletions

View File

@ -54,6 +54,7 @@ struct mCore {
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*);

View File

@ -76,6 +76,15 @@ void GBAudioReset(struct GBAudio* audio) {
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);

View File

@ -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);

View File

@ -96,6 +96,11 @@ static struct blip_t* _GBCoreGetAudioChannel(struct mCore* core, int ch) {
}
}
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 @@ struct mCore* GBCoreCreate(void) {
core->setVideoBuffer = _GBCoreSetVideoBuffer;
core->getVideoBuffer = _GBCoreGetVideoBuffer;
core->getAudioChannel = _GBCoreGetAudioChannel;
core->setAudioBufferSize = _GBCoreSetAudioBufferSize;
core->setAVStream = _GBCoreSetAVStream;
core->isROM = GBIsROM;
core->loadROM = _GBCoreLoadROM;

View File

@ -127,6 +127,11 @@ static struct blip_t* _GBACoreGetAudioChannel(struct mCore* core, int ch) {
}
}
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 @@ struct mCore* GBACoreCreate(void) {
core->setVideoBuffer = _GBACoreSetVideoBuffer;
core->getVideoBuffer = _GBACoreGetVideoBuffer;
core->getAudioChannel = _GBACoreGetAudioChannel;
core->setAudioBufferSize = _GBACoreSetAudioBufferSize;
core->setAVStream = _GBACoreSetAVStream;
core->isROM = GBAIsROM;
core->loadROM = _GBACoreLoadROM;

View File

@ -273,7 +273,7 @@ static void _setup(struct mGUIRunner* runner) {
screenMode = mode;
}
GBAAudioResizeBuffer(&((struct GBA*) runner->core->board)->audio, AUDIO_SAMPLES);
runner->core->setAudioBufferSize(runner->core, AUDIO_SAMPLES);
}
static void _gameLoaded(struct mGUIRunner* runner) {

View File

@ -205,7 +205,7 @@ void retro_init(void) {
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 @@ void retro_init(void) {
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);

View File

@ -73,9 +73,9 @@
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];

View File

@ -932,7 +932,7 @@ void GameController::updateKeys() {
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");
}

View File

@ -569,7 +569,7 @@ void _setup(struct mGUIRunner* runner) {
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);