//
// 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
// --- ---------- ------------------------------------------------------------
//
// 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...
//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)
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;
// 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
//
}
}
-
//
// Sound card callback handler
//
{
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;
}
}
}
-