Merge branch 'master' into ppu_window
This commit is contained in:
commit
60f01fe947
@ -309,16 +309,17 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
|
|||||||
GB_set_sample_rate(&gb, 96000);
|
GB_set_sample_rate(&gb, 96000);
|
||||||
self.audioClient = [[GBAudioClient alloc] initWithRendererBlock:^(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer) {
|
self.audioClient = [[GBAudioClient alloc] initWithRendererBlock:^(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer) {
|
||||||
[audioLock lock];
|
[audioLock lock];
|
||||||
if (stopping) {
|
|
||||||
memset(buffer, 0, nFrames * sizeof(*buffer));
|
|
||||||
[audioLock unlock];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audioBufferPosition < nFrames) {
|
if (audioBufferPosition < nFrames) {
|
||||||
audioBufferNeeded = nFrames;
|
audioBufferNeeded = nFrames;
|
||||||
[audioLock wait];
|
[audioLock wait];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stopping) {
|
||||||
|
memset(buffer, 0, nFrames * sizeof(*buffer));
|
||||||
|
[audioLock unlock];
|
||||||
|
}
|
||||||
|
|
||||||
if (audioBufferPosition >= nFrames && audioBufferPosition < nFrames + 4800) {
|
if (audioBufferPosition >= nFrames && audioBufferPosition < nFrames + 4800) {
|
||||||
memcpy(buffer, audioBuffer, nFrames * sizeof(*buffer));
|
memcpy(buffer, audioBuffer, nFrames * sizeof(*buffer));
|
||||||
memmove(audioBuffer, audioBuffer + nFrames, (audioBufferPosition - nFrames) * sizeof(*buffer));
|
memmove(audioBuffer, audioBuffer + nFrames, (audioBufferPosition - nFrames) * sizeof(*buffer));
|
||||||
@ -376,6 +377,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample)
|
|||||||
}
|
}
|
||||||
[audioLock lock];
|
[audioLock lock];
|
||||||
stopping = true;
|
stopping = true;
|
||||||
|
[audioLock signal];
|
||||||
[audioLock unlock];
|
[audioLock unlock];
|
||||||
running = false;
|
running = false;
|
||||||
while (stopping);
|
while (stopping);
|
||||||
|
20
Core/apu.c
20
Core/apu.c
@ -230,13 +230,13 @@ static void render(GB_gameboy_t *gb)
|
|||||||
gb->apu_output.sample_callback(gb, &filtered_output);
|
gb->apu_output.sample_callback(gb, &filtered_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t new_sweep_sample_legnth(GB_gameboy_t *gb)
|
static uint16_t new_sweep_sample_length(GB_gameboy_t *gb)
|
||||||
{
|
{
|
||||||
uint16_t delta = gb->apu.shadow_sweep_sample_legnth >> (gb->io_registers[GB_IO_NR10] & 7);
|
uint16_t delta = gb->apu.shadow_sweep_sample_length >> (gb->io_registers[GB_IO_NR10] & 7);
|
||||||
if (gb->io_registers[GB_IO_NR10] & 8) {
|
if (gb->io_registers[GB_IO_NR10] & 8) {
|
||||||
return gb->apu.shadow_sweep_sample_legnth - delta;
|
return gb->apu.shadow_sweep_sample_length - delta;
|
||||||
}
|
}
|
||||||
return gb->apu.shadow_sweep_sample_legnth + delta;
|
return gb->apu.shadow_sweep_sample_length + delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_square_sample(GB_gameboy_t *gb, unsigned index)
|
static void update_square_sample(GB_gameboy_t *gb, unsigned index)
|
||||||
@ -400,8 +400,8 @@ void GB_apu_div_event(GB_gameboy_t *gb)
|
|||||||
if (!--gb->apu.square_sweep_countdown) {
|
if (!--gb->apu.square_sweep_countdown) {
|
||||||
if ((gb->io_registers[GB_IO_NR10] & 0x70) && (gb->io_registers[GB_IO_NR10] & 0x07)) {
|
if ((gb->io_registers[GB_IO_NR10] & 0x70) && (gb->io_registers[GB_IO_NR10] & 0x07)) {
|
||||||
gb->apu.square_channels[GB_SQUARE_1].sample_length =
|
gb->apu.square_channels[GB_SQUARE_1].sample_length =
|
||||||
gb->apu.shadow_sweep_sample_legnth =
|
gb->apu.shadow_sweep_sample_length =
|
||||||
gb->apu.new_sweep_sample_legnth;
|
gb->apu.new_sweep_sample_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gb->io_registers[GB_IO_NR10] & 0x70) {
|
if (gb->io_registers[GB_IO_NR10] & 0x70) {
|
||||||
@ -435,8 +435,8 @@ void GB_apu_run(GB_gameboy_t *gb)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* APU bug: sweep frequency is checked after adding the sweep delta twice */
|
/* APU bug: sweep frequency is checked after adding the sweep delta twice */
|
||||||
gb->apu.new_sweep_sample_legnth = new_sweep_sample_legnth(gb);
|
gb->apu.new_sweep_sample_length = new_sweep_sample_length(gb);
|
||||||
if (gb->apu.new_sweep_sample_legnth > 0x7ff) {
|
if (gb->apu.new_sweep_sample_length > 0x7ff) {
|
||||||
gb->apu.is_active[GB_SQUARE_1] = false;
|
gb->apu.is_active[GB_SQUARE_1] = false;
|
||||||
update_sample(gb, GB_SQUARE_1, 0, gb->apu.square_sweep_calculate_countdown - cycles);
|
update_sample(gb, GB_SQUARE_1, 0, gb->apu.square_sweep_calculate_countdown - cycles);
|
||||||
gb->apu.sweep_enabled = false;
|
gb->apu.sweep_enabled = false;
|
||||||
@ -724,8 +724,8 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value)
|
|||||||
gb->apu.square_channels[index].sample_length &= 0xFF;
|
gb->apu.square_channels[index].sample_length &= 0xFF;
|
||||||
gb->apu.square_channels[index].sample_length |= (value & 7) << 8;
|
gb->apu.square_channels[index].sample_length |= (value & 7) << 8;
|
||||||
if (index == GB_SQUARE_1) {
|
if (index == GB_SQUARE_1) {
|
||||||
gb->apu.shadow_sweep_sample_legnth =
|
gb->apu.shadow_sweep_sample_length =
|
||||||
gb->apu.new_sweep_sample_legnth =
|
gb->apu.new_sweep_sample_length =
|
||||||
gb->apu.square_channels[0].sample_length;
|
gb->apu.square_channels[0].sample_length;
|
||||||
}
|
}
|
||||||
if (value & 0x80) {
|
if (value & 0x80) {
|
||||||
|
@ -64,8 +64,8 @@ typedef struct
|
|||||||
|
|
||||||
uint8_t square_sweep_countdown; // In 128Hz
|
uint8_t square_sweep_countdown; // In 128Hz
|
||||||
uint8_t square_sweep_calculate_countdown; // In 2 MHz
|
uint8_t square_sweep_calculate_countdown; // In 2 MHz
|
||||||
uint16_t new_sweep_sample_legnth;
|
uint16_t new_sweep_sample_length;
|
||||||
uint16_t shadow_sweep_sample_legnth;
|
uint16_t shadow_sweep_sample_length;
|
||||||
bool sweep_enabled;
|
bool sweep_enabled;
|
||||||
bool sweep_decreasing;
|
bool sweep_decreasing;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user