]> Shamusworld >> Repos - stargem2/blobdiff - src/sound.cpp
More cleanup, chasing down problems with the demo mode
[stargem2] / src / sound.cpp
index 8010d8985667c04bae056bcfe51c6f5d42cfa0fb..2f7522047072082c2b3c32fba6a6e04be0f340d4 100755 (executable)
 #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;