From 139c793b584a76acd42d72ec019d2cabab7d3ee7 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Tue, 25 Dec 2012 22:44:39 -0500 Subject: Smoother sound. Raise the sound sampling frequency to 48000 Hz. --- source/nds/ds2_main.c | 5 +++-- source/nds/ds2sound.h | 24 ++++++++++++++++++++++++ source/nds/entry.cpp | 24 ++++++------------------ 3 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 source/nds/ds2sound.h (limited to 'source') diff --git a/source/nds/ds2_main.c b/source/nds/ds2_main.c index 2d73313..7229727 100644 --- a/source/nds/ds2_main.c +++ b/source/nds/ds2_main.c @@ -23,6 +23,7 @@ #include "ds2io.h" #include "ds2_timer.h" #include "ds2_malloc.h" +#include "ds2sound.h" #define BLACK_COLOR RGB15(0, 0, 0) #define WHITE_COLOR RGB15(31, 31, 31) @@ -45,9 +46,9 @@ void ddump_mem(unsigned char* addr, unsigned int len) void ds2_main(void) { int err; -ds2_setCPUclocklevel(13); + ds2_setCPUclocklevel(13); //Initial video and audio and other input and output - err = ds2io_initb(512, 22050, 0, 0); + err = ds2io_initb(DS2_BUFFER_SIZE, SND_SAMPLE_RATE, 0, 0); if(err) goto _failure; //Initial file system diff --git a/source/nds/ds2sound.h b/source/nds/ds2sound.h new file mode 100644 index 0000000..cf37f6f --- /dev/null +++ b/source/nds/ds2sound.h @@ -0,0 +1,24 @@ +// The sound buffer sizes used on the DS2's side, for each value of +// Settings.SoundPlaybackRate. +#define DS2_BUFFER_SIZE_1 256 +#define DS2_BUFFER_SIZE_2 256 +#define DS2_BUFFER_SIZE_3 256 +#define DS2_BUFFER_SIZE_4 512 +#define DS2_BUFFER_SIZE_5 512 +#define DS2_BUFFER_SIZE_6 1024 +#define DS2_BUFFER_SIZE_7 1024 + +// The sampling rate for the sound, in Hz, for each value of +// Settings.SoundPlaybackRate. +#define SND_SAMPLE_RATE_1 8000 +#define SND_SAMPLE_RATE_2 11025 +#define SND_SAMPLE_RATE_3 16000 +#define SND_SAMPLE_RATE_4 22050 +#define SND_SAMPLE_RATE_5 32000 +#define SND_SAMPLE_RATE_6 44100 +#define SND_SAMPLE_RATE_7 48000 + +// Settings in use. The number should match in all three settings. +#define DS2_BUFFER_SIZE DS2_BUFFER_SIZE_7 +#define SND_SAMPLE_RATE SND_SAMPLE_RATE_7 +#define SNES9X_SRATE_ID 7 diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index ce8d732..a8e2217 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -20,6 +20,7 @@ #include "draw.h" #include "gui.h" +#include "ds2sound.h" void S9xProcessSound (unsigned int); @@ -359,9 +360,9 @@ void init_sfc_setting(void) Settings.JoystickEnabled = FALSE; #endif - Settings.SoundPlaybackRate = 4; //2 = 11025, 4 = 22050, 6 = 44100 + Settings.SoundPlaybackRate = SNES9X_SRATE_ID; // -> ds2sound.h for defs Settings.Stereo = TRUE; - Settings.SoundBufferSize = 0; + Settings.SoundBufferSize = DS2_BUFFER_SIZE; Settings.CyclesPercentage = 100; Settings.DisableSoundEcho = FALSE; //sound settings @@ -767,28 +768,15 @@ void S9xSyncSpeed () #endif } -/* -* Open sound device -*/ -static int Rates[8] = -{ - 0, 8000, 11025, 16000, 22050, 32000, 44100, 48000 -}; - -static int BufferSizes [8] = -{ - 0, 256, 256, 256, 512, 512, 1024, 1024 -}; - bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size) { so.sixteen_bit = TRUE; so.stereo = stereo; - so.playback_rate = Rates[mode & 0x07]; + so.playback_rate = SND_SAMPLE_RATE; S9xSetPlaybackRate (so.playback_rate); if (buffer_size == 0) - buffer_size = BufferSizes [mode & 7]; + buffer_size = DS2_BUFFER_SIZE; if (buffer_size > MAX_BUFFER_SIZE / 4) buffer_size = MAX_BUFFER_SIZE / 4; @@ -936,7 +924,7 @@ void S9xProcessSound (unsigned int) // block_generate_sound = FALSE; unsigned short *dst_pt = audiobuff; - unsigned short *dst_pt1 = dst_pt + 512; + unsigned short *dst_pt1 = dst_pt + DS2_BUFFER_SIZE; /* Feed the samples to the soundcard until nothing is left */ for(;;) -- cgit v1.2.3