From ce68f366cb042993e3dbe5401b2d81e06ed0e099 Mon Sep 17 00:00:00 2001 From: Dan Sumorok Date: Sun, 9 Jun 2013 19:34:19 -0400 Subject: [PATCH] Added asc.c, and asc.h. Don't stop sound if we don't have to. --- BasiliskII/src/MacOSX/asc.cpp | 51 ++++++++++++++++++++++++ BasiliskII/src/include/asc.h | 13 ++++++ BasiliskII/src/uae_cpu/basilisk_glue.cpp | 36 ++++++++++------- 3 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 BasiliskII/src/MacOSX/asc.cpp create mode 100644 BasiliskII/src/include/asc.h diff --git a/BasiliskII/src/MacOSX/asc.cpp b/BasiliskII/src/MacOSX/asc.cpp new file mode 100644 index 00000000..2780d704 --- /dev/null +++ b/BasiliskII/src/MacOSX/asc.cpp @@ -0,0 +1,51 @@ +#include +#include +#include "MacOSX_sound_if.h" + +static OSXsoundOutput *soundOutput = NULL; + +static int audioInt(void); + +bool asc_init(int32 sample_rate) { + if(soundOutput != NULL) { + delete soundOutput; + soundOutput = NULL; + } + + soundOutput = new OSXsoundOutput(); + soundOutput->start(8, 1, sample_rate); + soundOutput->setCallback(audioInt); + + return true; +} + +bool asc_process_samples(const uae_u8 *samples, int count) { + if(soundOutput == NULL) { + return false; + } + + if(soundOutput->sendAudioBuffer((const void *)samples, count) != 0) { + return false; + } + + return true; +} + +static int audioInt(void) { + asc_callback(); + + return 0; +} + +int32 asc_get_buffer_size() { + if(soundOutput == NULL) { + return -1; + } + + return (int32) soundOutput->bufferSizeFrames(); +} + +void asc_stop() { + delete soundOutput; + soundOutput = NULL; +} diff --git a/BasiliskII/src/include/asc.h b/BasiliskII/src/include/asc.h new file mode 100644 index 00000000..2b52ed43 --- /dev/null +++ b/BasiliskII/src/include/asc.h @@ -0,0 +1,13 @@ +#ifndef ASC_H +#define ASC_H + +#include "sysdeps.h" +#include "cpu_emulation.h" + +bool asc_init(int32 sample_rate); +bool asc_process_samples(const uae_u8 *samples, int count); +int32 asc_get_buffer_size(); +void asc_callback(); +void asc_stop(); + +#endif diff --git a/BasiliskII/src/uae_cpu/basilisk_glue.cpp b/BasiliskII/src/uae_cpu/basilisk_glue.cpp index 5dd8704c..eb40d014 100644 --- a/BasiliskII/src/uae_cpu/basilisk_glue.cpp +++ b/BasiliskII/src/uae_cpu/basilisk_glue.cpp @@ -280,8 +280,8 @@ static uae_u8 fifoA[fifoCapacity]; static uae_u8 fifoB[fifoCapacity]; static int32 ascBufferSize = -1; static int soundRunning = 0; -static int soundStop = 0; static uae_u8 zeros[1024] = {0}; +static uae_u8 lastMode = 0; extern uae_u32 io_read(uaecptr addr, int width_bits) { if((addr & 0x00ff000) == 0x0014000) { @@ -334,12 +334,6 @@ extern void io_write(uaecptr addr, uae_u32 b, int width_bits) { static int downsample = 0; if((addr & 0x00ff000) == 0x0014000) { - if(soundStop) { - asc_stop(); - soundRunning = 0; - soundStop = 0; - } - // Apple Sound Chip if(width_bits > 8) { fprintf(stderr, @@ -383,8 +377,8 @@ extern void io_write(uaecptr addr, uae_u32 b, int width_bits) { ascBufferSize = asc_get_buffer_size(); soundRunning = 1; - while(((fifoWriteA - fifoOutA) < (ascBufferSize*2)) && - ((fifoInA - fifoWriteA) > ascBufferSize) ){ + while( //((fifoWriteA - fifoOutA) < (ascBufferSize*2)) && + ((fifoInA - fifoWriteA) > ascBufferSize) ) { asc_process_samples(&fifoA[fifoWriteA % fifoCapacity], ascBufferSize); fifoWriteA += ascBufferSize; @@ -401,11 +395,22 @@ extern void io_write(uaecptr addr, uae_u32 b, int width_bits) { // MODE // 1 = FIFO mode, 2 = wavetable mode ASCRegs[0x801] = b & 0x03; - asc_stop(); - soundRunning = 0; + if(b == 0) { + break; + } + + if(ASCRegs[0x801] != lastMode) { + asc_stop(); + soundRunning = 0; + fifoWriteA = fifoInA; + } + lastMode = ASCRegs[0x801]; break; case 0x802: + if(ASCRegs[0x802] == b) { + break; + } // CONTROL // bit 0: analog or PWM output // bit 1: stereo/mono @@ -416,9 +421,9 @@ extern void io_write(uaecptr addr, uae_u32 b, int width_bits) { case 0x803: // FIFO Mode if(b & 0x80) { - downsample = 0; - asc_stop(); - soundRunning = 0; + if(fifoInA > (fifoWriteA + ascBufferSize)) { + fifoInA = fifoWriteA + ascBufferSize; + } } break; @@ -463,7 +468,8 @@ void asc_callback() { fifoOutA += ascBufferSize; - if((fifoInA - fifoWriteA) >= ascBufferSize) { + if( ((fifoInA - fifoWriteA) >= ascBufferSize) && + (ASCRegs[0x801] == 1)) { asc_process_samples(&fifoA[fifoWriteA % fifoCapacity], ascBufferSize); fifoWriteA += ascBufferSize; } else {