From 678e5b08ac0a3f5fc7fa1a33c28bf3df29c3c5df Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Tue, 25 Sep 2018 12:55:59 -0700 Subject: [PATCH] More audio stuff --- libretroBuildSystem/libretro.c | 1 + src/emulator.c | 4 ++-- src/emulator.h | 4 ++-- src/hardwareRegistersAccessors.c.h | 7 ++++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libretroBuildSystem/libretro.c b/libretroBuildSystem/libretro.c index d35e6ac..25016e4 100644 --- a/libretroBuildSystem/libretro.c +++ b/libretroBuildSystem/libretro.c @@ -259,6 +259,7 @@ void retro_run(void) //TODO make mouse cursor } + audio_batch_cb(palmAudio, AUDIO_SAMPLES); video_cb(palmFramebuffer, screenWidth, screenHeight, screenWidth * sizeof(uint16_t)); } diff --git a/src/emulator.c b/src/emulator.c index e767bb3..9fc1085 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -40,7 +40,7 @@ sd_card_t palmSdCard; misc_hw_t palmMisc; uint16_t palmFramebuffer[160 * (160 + 60)];//really 160*160, the extra pixels are the silkscreened digitizer area uint16_t* palmExtendedFramebuffer; -int16_t palmAudio[AUDIO_SAMPLES]; +int16_t palmAudio[AUDIO_SAMPLES * 2]; uint32_t palmAudioSampleIndex; uint32_t palmSpecialFeatures; double palmCrystalCycles;//how many cycles before toggling the 32.768 kHz crystal @@ -95,7 +95,7 @@ uint32_t emulatorInit(buffer_t palmRomDump, buffer_t palmBootDump, uint32_t spec memset(palmExtendedFramebuffer, 0x00, 320 * 320 * sizeof(uint16_t)); //add 320*320 silkscreen image later, 2xBRZ should be able to make 320*320 version of the 160*160 silkscreen } - memset(palmAudio, 0x00, AUDIO_SAMPLES * sizeof(int16_t)); + memset(palmAudio, 0x00, AUDIO_SAMPLES * 2 * sizeof(int16_t)); m68328Reset(); sed1376Reset(); ads7846Reset(); diff --git a/src/emulator.h b/src/emulator.h index da54728..3e1d9bf 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -10,8 +10,8 @@ extern "C" { #include #include -//#include "memoryAccess.h"//for size macros -#include "specs/emuFeatureRegistersSpec.h" +#include "memoryAccess.h"//for size macros +#include "specs/emuFeatureRegistersSpec.h"//for feature names //to enable degguging define EMU_DEBUG, all options below do nothing unless EMU_DEBUG is defined //to enable sandbox debugging define EMU_SANDBOX diff --git a/src/hardwareRegistersAccessors.c.h b/src/hardwareRegistersAccessors.c.h index cfb09b0..3964653 100644 --- a/src/hardwareRegistersAccessors.c.h +++ b/src/hardwareRegistersAccessors.c.h @@ -622,7 +622,7 @@ static inline uint16_t getCurrentSpeakerSample(){ static inline void samplePwmXClk32(){ //call every clk32, adds samples to audio buffer - if(palmAudioSampleIndex < AUDIO_SAMPLES){ + if(palmAudioSampleIndex < AUDIO_SAMPLES * 2){ double dutyCycle; uint16_t firstLowSample; uint8_t audioMode = registerArrayRead8(PCR) >> 2 & 0x03; @@ -656,8 +656,9 @@ static inline void samplePwmXClk32(){ //add samples to audio buffer firstLowSample = dutyCycle * AUDIO_DUTY_CYCLE_SIZE; for(uint16_t count = 0; count < AUDIO_DUTY_CYCLE_SIZE; count++){ - palmAudio[palmAudioSampleIndex] = (count < firstLowSample) ? 32767 : -32768; - palmAudioSampleIndex++; + palmAudio[palmAudioSampleIndex] = (count < firstLowSample) ? 0x6666 : -0x6666;//not full volume, leave 20% for audio spikes + palmAudio[palmAudioSampleIndex + 1] = palmAudio[palmAudioSampleIndex]; + palmAudioSampleIndex += 2; } } }