]> Shamusworld >> Repos - stargem2/blobdiff - src/sound.cpp
Finally fixed problems with demo mode.
[stargem2] / src / sound.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 4462e27..b4e9f1d
@@ -1,10 +1,10 @@
 //
 // Sound Interface v2.0
 //
-// by James L. Hammons
+// by James Hammons
 // (c) 2006 Underground Software
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
@@ -16,7 +16,8 @@
 //
 // Notes:
 //   The sound CPU (6808) runs at 894,750 (3,579,000 / 4) Hz.
-//   At 44.1 KHz, this works out to 894750 / 44100 = 20.289115646... cycles per sample.
+//   At 44.1 KHz, this works out to 894750 / 44100 = 20.289115646... cycles per
+//   sample.
 //
 
 // Still need to add volume control...
@@ -31,7 +32,6 @@
 
 //using namespace std;
 
-//#define AUDIO_SAMPLE_RATE                            44100.0
 #define AUDIO_SAMPLE_RATE                              48000.0
 #define CYCLES_TO_EXECUTE                              (M6808_CLOCK_SPEED_IN_HZ / AUDIO_SAMPLE_RATE)
 
@@ -46,22 +46,18 @@ static double cyclesToExecuteFractionalPart;
 
 void SDLSoundCallback(void * userdata, Uint8 * buffer, int length);
 
-
 //
 // Initialize the SDL sound system
 //
 void SoundInit(void)
 {
-//     memory_malloc_secure((void **)&DACBuffer, BUFFER_SIZE * sizeof(uint16), "DAC buffer");
-
-       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.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)
-       desired.samples = 2048;                                                 // Let's try a 2K buffer (can always go lower)
+       desired.samples = 2048;                                 // Let's try a 2K buffer (can always go lower)
        desired.callback = SDLSoundCallback;
 
-       if (SDL_OpenAudio(&desired, NULL) < 0)                  // NULL means SDL guarantees what we want
+       if (SDL_OpenAudio(&desired, NULL) < 0)  // NULL means SDL guarantees what we want
        {
                WriteLog("Sound: Failed to initialize SDL sound.\n");
                return;
@@ -70,16 +66,12 @@ void SoundInit(void)
        // Setup clock cycles & etc.
        cyclesToExecuteWholePart = (uint32_t)CYCLES_TO_EXECUTE;
        cyclesToExecuteFractionalPart = CYCLES_TO_EXECUTE - (double)cyclesToExecuteWholePart;
-#if 0
-printf("Cycles to execute: %lf; cycles W: %u; cycles F: %lf\n", CYCLES_TO_EXECUTE, cyclesToExecuteWholePart, cyclesToExecuteFractionalPart);
-#endif
 
        SDL_PauseAudio(false);                                                  // Start playback!
        soundInitialized = true;
        WriteLog("Sound: Successfully initialized.\n");
 }
 
-
 //
 // Close down the SDL sound subsystem
 //
@@ -93,7 +85,6 @@ void SoundDone(void)
        }
 }
 
-
 //
 // Sound card callback handler
 //
@@ -110,7 +101,9 @@ void SDLSoundCallback(void * userdata, Uint8 * buffer, int length)
        {
                Execute6808(&soundCPU, time);
                soundCPU.clock -= time;
-               buffer[cnt++] = sram[0x0400];                           // Fill the buffer with the PIA output value
+//             buffer[cnt++] = sram[0x0400];                           // Fill the buffer with the PIA output value
+               // Do some simple volume control...
+               buffer[cnt++] = sram[0x0400] / 4;                       // Fill the buffer with the PIA output value
                time = cyclesToExecuteWholePart;
                overflow += cyclesToExecuteFractionalPart;
 
@@ -121,4 +114,3 @@ void SDLSoundCallback(void * userdata, Uint8 * buffer, int length)
                }
        }
 }
-