void GBAudioReset(struct GBAudio* audio) { audio->nextEvent = 0; audio->nextCh1 = 0; audio->nextCh2 = 0; audio->nextCh3 = 0; audio->fadeCh3 = 0; audio->nextCh4 = 0; audio->ch1 = (struct GBAudioChannel1) { .envelope = { .dead = 2 } }; audio->ch2 = (struct GBAudioChannel2) { .envelope = { .dead = 2 } }; audio->ch3 = (struct GBAudioChannel3) { .bank = 0 }; audio->ch4 = (struct GBAudioChannel4) { .envelope = { .dead = 2 } }; audio->eventDiff = 0; audio->nextFrame = 0; audio->frame = 0; audio->nextSample = 0; audio->sampleInterval = 128; audio->lastLeft = 0; audio->lastRight = 0; audio->clock = 0; audio->volumeRight = 0; audio->volumeLeft = 0; audio->ch1Right = false; audio->ch2Right = false; audio->ch3Right = false; audio->ch4Right = false; audio->ch1Left = false; audio->ch2Left = false; audio->ch3Left = false; audio->ch4Left = false; audio->playingCh1 = false; audio->playingCh2 = false; 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); }
static void _mSDLAudioCallback(void* context, Uint8* data, int len) { struct mSDLAudio* audioContext = context; if (!context || !audioContext->core) { memset(data, 0, len); return; } blip_t* left = NULL; blip_t* right = NULL; int32_t clockRate = GBA_ARM7TDMI_FREQUENCY; if (audioContext->core) { left = audioContext->core->getAudioChannel(audioContext->core, 0); right = audioContext->core->getAudioChannel(audioContext->core, 1); clockRate = audioContext->core->frequency(audioContext->core); } double fauxClock = 1; if (audioContext->sync) { if (audioContext->sync->fpsTarget > 0) { fauxClock = GBAAudioCalculateRatio(1, audioContext->sync->fpsTarget, 1); } mCoreSyncLockAudio(audioContext->sync); } blip_set_rates(left, clockRate, audioContext->obtainedSpec.freq * fauxClock); blip_set_rates(right, clockRate, audioContext->obtainedSpec.freq * fauxClock); len /= 2 * audioContext->obtainedSpec.channels; int available = blip_samples_avail(left); if (available > len) { available = len; } blip_read_samples(left, (short*) data, available, audioContext->obtainedSpec.channels == 2); if (audioContext->obtainedSpec.channels == 2) { blip_read_samples(right, ((short*) data) + 1, available, 1); } if (audioContext->sync) { mCoreSyncConsumeAudio(audioContext->sync); } if (available < len) { memset(((short*) data) + audioContext->obtainedSpec.channels * available, 0, (len - available) * audioContext->obtainedSpec.channels * sizeof(short)); } }