X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdac.cpp;h=f08295448ceca78c4392aeb38c3461b1d680be55;hb=7228359373eb7602c26f7b098d6b2271ff5727a1;hp=6f9b5a8e57b01d393ec005fae3b2697644311885;hpb=ab4f660439ff855171f801e3fdfa3e9de69d991b;p=virtualjaguar diff --git a/src/dac.cpp b/src/dac.cpp index 6f9b5a8..f082954 100644 --- a/src/dac.cpp +++ b/src/dac.cpp @@ -19,10 +19,6 @@ // work correctly...! Perhaps just need to set up SSI stuff so BUTCH doesn't get // confused... -// ALSO: Need to implement some form of proper locking to replace the clusterfuck -// that is the current spinlock implementation. Since the DSP is a separate -// entity, could we get away with running it in the sound IRQ? - // After testing on a real Jaguar, it seems clear that the I2S interrupt drives // the audio subsystem. So while you can drive the audio at a *slower* rate than // set by SCLK, you can't drive it any *faster*. Also note, that if the I2S @@ -75,14 +71,14 @@ // Global variables // These are defined in memory.h/cpp -//uint16 lrxd, rrxd; // I2S ports (into Jaguar) +//uint16_t lrxd, rrxd; // I2S ports (into Jaguar) // Local variables static SDL_AudioSpec desired; static bool SDLSoundInitialized; -static uint8 SCLKFrequencyDivider = 19; // Default is roughly 22 KHz (20774 Hz in NTSC mode) -/*static*/ uint16 serialMode = 0; +//static uint8_t SCLKFrequencyDivider = 19; // Default is roughly 22 KHz (20774 Hz in NTSC mode) +// /*static*/ uint16_t serialMode = 0; // Private function prototypes @@ -97,9 +93,10 @@ void DACInit(void) { SDLSoundInitialized = false; - if (!vjs.audioEnabled) +// if (!vjs.audioEnabled) + if (!vjs.DSPEnabled) { - WriteLog("DAC: Host audio playback disabled.\n"); + WriteLog("DAC: DSP/host audio playback disabled.\n"); return; } @@ -120,6 +117,7 @@ void DACInit(void) } ltxd = lrxd = desired.silence; + sclk = 19; // Default is roughly 22 KHz uint32_t riscClockRate = (vjs.hardwareTypeNTSC ? RISC_CLOCK_RATE_NTSC : RISC_CLOCK_RATE_PAL); uint32_t cyclesPerSample = riscClockRate / DAC_AUDIO_RATE; @@ -137,6 +135,15 @@ void DACReset(void) } +// +// Pause/unpause the SDL audio thread +// +void DACPauseAudioThread(bool state/*= true*/) +{ + SDL_PauseAudio(state); +} + + // // Close down the SDL sound subsystem // @@ -188,8 +195,8 @@ void SDLSoundCallback(void * userdata, Uint8 * buffer, int length) // The length of time we're dealing with here is 1/48000 s, so we multiply this // by the number of cycles per second to get the number of cycles for one sample. - uint32_t riscClockRate = (vjs.hardwareTypeNTSC ? RISC_CLOCK_RATE_NTSC : RISC_CLOCK_RATE_PAL); - uint32_t cyclesPerSample = riscClockRate / DAC_AUDIO_RATE; +// uint32_t riscClockRate = (vjs.hardwareTypeNTSC ? RISC_CLOCK_RATE_NTSC : RISC_CLOCK_RATE_PAL); +// uint32_t cyclesPerSample = riscClockRate / DAC_AUDIO_RATE; // This is the length of time // timePerSample = (1000000.0 / (double)riscClockRate) * (); @@ -197,12 +204,14 @@ void SDLSoundCallback(void * userdata, Uint8 * buffer, int length) bufferIndex = 0; sampleBuffer = buffer; +// If length is the length of the sample buffer in BYTES, then shouldn't the # of +// samples be / 4? No, because we bump the sample count by 2, so this is OK. numberOfSamples = length / 2; bufferDone = false; SetCallbackTime(DSPSampleCallback, 1000000.0 / (double)DAC_AUDIO_RATE, EVENT_JERRY); - // These timings are tied to NTSC, need to fix that in event.cpp/h! + // These timings are tied to NTSC, need to fix that in event.cpp/h! [FIXED] do { double timeToNextEvent = GetTimeToNextEvent(EVENT_JERRY); @@ -255,15 +264,15 @@ int GetCalculatedFrequency(void) // // LTXD/RTXD/SCLK/SMODE ($F1A148/4C/50/54) // -void DACWriteByte(uint32 offset, uint8 data, uint32 who/*= UNKNOWN*/) +void DACWriteByte(uint32_t offset, uint8_t data, uint32_t who/*= UNKNOWN*/) { WriteLog("DAC: %s writing BYTE %02X at %08X\n", whoName[who], data, offset); if (offset == SCLK + 3) - DACWriteWord(offset - 3, (uint16)data); + DACWriteWord(offset - 3, (uint16_t)data); } -void DACWriteWord(uint32 offset, uint16 data, uint32 who/*= UNKNOWN*/) +void DACWriteWord(uint32_t offset, uint16_t data, uint32_t who/*= UNKNOWN*/) { if (offset == LTXD + 2) { @@ -275,14 +284,17 @@ void DACWriteWord(uint32 offset, uint16 data, uint32 who/*= UNKNOWN*/) } else if (offset == SCLK + 2) // Sample rate { - WriteLog("DAC: Writing %u to SCLK...\n", data); + WriteLog("DAC: Writing %u to SCLK (by %s)...\n", data, whoName[who]); - if ((uint8)data != SCLKFrequencyDivider) - SCLKFrequencyDivider = (uint8)data; + sclk = data & 0xFF; + JERRYI2SInterruptTimer = -1; + RemoveCallback(JERRYI2SCallback); + JERRYI2SCallback(); } else if (offset == SMODE + 2) { - serialMode = data; +// serialMode = data; + smode = data; WriteLog("DAC: %s writing to SMODE. Bits: %s%s%s%s%s%s [68K PC=%08X]\n", whoName[who], (data & 0x01 ? "INTERNAL " : ""), (data & 0x02 ? "MODE " : ""), (data & 0x04 ? "WSEN " : ""), (data & 0x08 ? "RISING " : ""), @@ -295,15 +307,15 @@ void DACWriteWord(uint32 offset, uint16 data, uint32 who/*= UNKNOWN*/) // // LRXD/RRXD/SSTAT ($F1A148/4C/50) // -uint8 DACReadByte(uint32 offset, uint32 who/*= UNKNOWN*/) +uint8_t DACReadByte(uint32_t offset, uint32_t who/*= UNKNOWN*/) { // WriteLog("DAC: %s reading byte from %08X\n", whoName[who], offset); return 0xFF; } -//static uint16 fakeWord = 0; -uint16 DACReadWord(uint32 offset, uint32 who/*= UNKNOWN*/) +//static uint16_t fakeWord = 0; +uint16_t DACReadWord(uint32_t offset, uint32_t who/*= UNKNOWN*/) { // WriteLog("DAC: %s reading word from %08X\n", whoName[who], offset); // return 0xFFFF; @@ -322,3 +334,4 @@ uint16 DACReadWord(uint32 offset, uint32 who/*= UNKNOWN*/) return 0xFFFF; // May need SSTAT as well... (but may be a Jaguar II only feature) } +