X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fsound.cpp;h=2f7522047072082c2b3c32fba6a6e04be0f340d4;hb=f51c96856129613e8aefd07a777dc59812ded4c7;hp=8010d8985667c04bae056bcfe51c6f5d42cfa0fb;hpb=d1485d7c8a16bf3dd7601bbf6016998eb28bf989;p=stargem2 diff --git a/src/sound.cpp b/src/sound.cpp index 8010d89..2f75220 100755 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -26,9 +26,12 @@ #include "types.h" #include "log.h" #include "v6808.h" +#include "timing.h" //using namespace std; +#define AUDIO_SAMPLE_RATE 44100 + // Local variables SDL_AudioSpec desired; @@ -45,7 +48,7 @@ void SoundInit(void) { // memory_malloc_secure((void **)&DACBuffer, BUFFER_SIZE * sizeof(uint16), "DAC buffer"); - desired.freq = 44100; // SDL will do conversion on the fly, if it can't get the exact rate. Nice! + desired.freq = AUDIO_SAMPLE_RATE; // SDL will do conversion on the fly, if it can't get the exact rate. Nice! desired.format = AUDIO_U8; // This uses the native endian (for portability)... desired.channels = 1; // desired.samples = 4096; // Let's try a 4K buffer (can always go lower) @@ -77,13 +80,21 @@ void SoundDone(void) } } +/* +The way to determine the # of cycles for each sample is to take the CPU clock frequency +and divide by the sample rate. + +Like so: +double cycles = M6808_CLOCK_SPEED_IN_HZ / AUDIO_SAMPLE_RATE; +Then we need to separate out the fractional part from the integer part. +*/ + // // Sound card callback handler // void SDLSoundCallback(void * userdata, Uint8 * buffer, int length) { extern V6808REGS soundCPU; -// extern uint8 * sram; extern uint8 sram[]; int cnt = 0;