aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNebuleon Fumika2013-01-11 18:58:07 -0500
committerNebuleon Fumika2013-01-11 19:22:59 -0500
commit7896e83aa9a3da428d3a56423a5c613782d1ac18 (patch)
treec56b9edbb67888950c76644ac0c2a5431228a62a
parent0028091d0f98f92a709dd2caa951e61ae28e5e34 (diff)
downloadsnes9x2005-7896e83aa9a3da428d3a56423a5c613782d1ac18.tar.gz
snes9x2005-7896e83aa9a3da428d3a56423a5c613782d1ac18.tar.bz2
snes9x2005-7896e83aa9a3da428d3a56423a5c613782d1ac18.zip
Stop constantly testing for 16-bit and stereo in sound handlers. Define FOREVER_16_BIT_SOUND and FOREVER_STEREO and use them throughout the code.
This is essentially commit 6b36e79013d4c9273a96a9783a2bccdb516f174a, but for sound instead of graphics.
-rw-r--r--Makefile2
-rw-r--r--source/nds/entry.cpp50
-rw-r--r--source/snes9x.h4
-rw-r--r--source/soundux.cpp30
-rw-r--r--source/soundux.h4
5 files changed, 85 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index c0b6793..7ba2a89 100644
--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,7 @@ CFLAGS := -mips32 -mno-abicalls -fno-pic -fno-builtin \
DEFS := -DSPC700_C -DEXECUTE_SUPERFX_PER_LINE -DSDD1_DECOMP \
-DVAR_CYCLES -DCPU_SHUTDOWN -DSPC700_SHUTDOWN \
-DNO_INLINE_SET_GET -DNOASM -DHAVE_MKSTEMP '-DACCEPT_SIZE_T=size_t' \
- -DUNZIP_SUPPORT
+ -DUNZIP_SUPPORT -DFOREVER_16_BIT_SOUND -DFOREVER_STEREO
# -DSYNC_JOYPAD_AT_HBLANK
.PHONY: clean makedirs
diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp
index f157f1c..7e6a2e5 100644
--- a/source/nds/entry.cpp
+++ b/source/nds/entry.cpp
@@ -367,7 +367,9 @@ void init_sfc_setting(void)
#endif
Settings.SoundPlaybackRate = SNES9X_SRATE_ID; // -> ds2sound.h for defs
+#ifndef FOREVER_STEREO
Settings.Stereo = TRUE;
+#endif
Settings.SoundBufferSize = DS2_BUFFER_SIZE;
Settings.CyclesPercentage = 100;
Settings.DisableSoundEcho = FALSE;
@@ -392,6 +394,9 @@ void init_sfc_setting(void)
#ifndef FOREVER_16_BIT
Settings.SixteenBit = TRUE;
#endif
+#ifndef FOREVER_16_BIT_SOUND
+ Settings.SixteenBitSound = TRUE;
+#endif
Settings.SupportHiRes = FALSE;
Settings.ThreadSound = FALSE;
@@ -534,7 +539,12 @@ int sfc_main (int argc, char **argv)
if (!S9xGraphicsInit())
OutOfMemory ();
- S9xInitSound (Settings.SoundPlaybackRate, Settings.Stereo,
+ S9xInitSound (Settings.SoundPlaybackRate,
+#ifndef FOREVER_STEREO
+ Settings.Stereo,
+#else
+ TRUE,
+#endif
Settings.SoundBufferSize);
// Start a timer for the sound
initTimer(0 /* timer channel, 0 or 1 */,
@@ -857,8 +867,12 @@ void S9xSyncSpeed ()
bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size)
{
+#ifndef FOREVER_16_BIT_SOUND
so.sixteen_bit = TRUE;
+#endif
+#ifndef FOREVER_STEREO
so.stereo = stereo;
+#endif
so.playback_rate = SND_SAMPLE_RATE;
S9xSetPlaybackRate (so.playback_rate);
@@ -867,9 +881,13 @@ bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size)
if (buffer_size > MAX_BUFFER_SIZE / 4)
buffer_size = MAX_BUFFER_SIZE / 4;
+#ifndef FOREVER_16_BIT_SOUND
if (so.sixteen_bit)
+#endif
buffer_size *= 2;
+#ifndef FOREVER_STEREO
if (so.stereo)
+#endif
buffer_size *= 2;
so.buffer_size = buffer_size;
@@ -893,8 +911,12 @@ void S9xGenerateSound ()
{
block_signal = TRUE;
+#ifndef FOREVER_16_BIT_SOUND
int bytes_so_far = so.sixteen_bit ? (so.samples_mixed_so_far << 1) :
so.samples_mixed_so_far;
+#else
+ int bytes_so_far = so.samples_mixed_so_far << 1;
+#endif
if (bytes_so_far >= so.buffer_size)
goto end;
@@ -907,7 +929,9 @@ void S9xGenerateSound ()
int byte_count;
so.err_counter &= FIXED_POINT_REMAINDER;
+#ifndef FOREVER_STEREO
if (so.stereo)
+#endif
sample_count <<= 1;
byte_offset = bytes_so_far + so.play_position;
@@ -915,14 +939,18 @@ void S9xGenerateSound ()
{
int sc = sample_count;
byte_count = sample_count;
+#ifndef FOREVER_16_BIT_SOUND
if (so.sixteen_bit)
+#endif
byte_count <<= 1;
if ((byte_offset & SOUND_BUFFER_SIZE_MASK) + byte_count > SOUND_BUFFER_SIZE)
{
sc = SOUND_BUFFER_SIZE - (byte_offset & SOUND_BUFFER_SIZE_MASK);
byte_count = sc;
+#ifndef FOREVER_16_BIT_SOUND
if (so.sixteen_bit)
+#endif
sc >>= 1;
}
@@ -932,15 +960,21 @@ void S9xGenerateSound ()
if (byte_count == 0)
break;
sc = byte_count;
+#ifndef FOREVER_16_BIT_SOUND
if (so.sixteen_bit)
+#endif
sc >>= 1;
}
S9xMixSamplesO (Buf, sc, byte_offset & SOUND_BUFFER_SIZE_MASK);
so.samples_mixed_so_far += sc;
sample_count -= sc;
+#ifndef FOREVER_16_BIT_SOUND
bytes_so_far = so.sixteen_bit ? (so.samples_mixed_so_far << 1) :
so.samples_mixed_so_far;
+#else
+ bytes_so_far = so.samples_mixed_so_far << 1;
+#endif
byte_offset += byte_count;
} while (sample_count > 0);
}
@@ -988,13 +1022,17 @@ void NDSSFCProduceSound (unsigned int unused)
/* Number of samples to generate now */
int sample_count;
sample_count = so.buffer_size;
+#ifndef FOREVER_16_BIT_SOUND
if (so.sixteen_bit)
{
+#endif
/* to prevent running out of buffer space,
* create less samples
*/
sample_count >>= 1;
+#ifndef FOREVER_16_BIT_SOUND
}
+#endif
// block_generate_sound = TRUE;
@@ -1008,8 +1046,13 @@ void NDSSFCProduceSound (unsigned int unused)
if (so.samples_mixed_so_far < sample_count)
{
/* Where to put the samples to */
+#ifndef FOREVER_16_BIT_SOUND
unsigned byte_offset = so.play_position +
(so.sixteen_bit ? (so.samples_mixed_so_far << 1) : so.samples_mixed_so_far);
+#else
+ unsigned byte_offset = so.play_position +
+ (so.samples_mixed_so_far << 1);
+#endif
//printf ("%d:", sample_count - so.samples_mixed_so_far); fflush (stdout);
if (Settings.SoundSync == 2)
@@ -1029,7 +1072,10 @@ void NDSSFCProduceSound (unsigned int unused)
// if (!so.mute_sound)
{
unsigned bytes_to_write = sample_count;
- if(so.sixteen_bit) bytes_to_write <<= 1;
+#ifndef FOREVER_16_BIT_SOUND
+ if(so.sixteen_bit)
+#endif
+ bytes_to_write <<= 1;
unsigned byte_offset = so.play_position;
so.play_position += bytes_to_write;
diff --git a/source/snes9x.h b/source/snes9x.h
index e9e29b8..ebcf5e3 100644
--- a/source/snes9x.h
+++ b/source/snes9x.h
@@ -328,9 +328,13 @@ struct SSettings{
/* Sound options */
uint32 SoundPlaybackRate;
bool8 TraceSoundDSP;
+#ifndef FOREVER_STEREO
bool8 Stereo;
+#endif
bool8 ReverseStereo;
+#ifndef FOREVER_16_BIT_SOUND
bool8 SixteenBitSound;
+#endif
int SoundBufferSize;
int SoundMixInterval;
bool8 SoundEnvelopeHeightReading;
diff --git a/source/soundux.cpp b/source/soundux.cpp
index b6ff440..7acbaa8 100644
--- a/source/soundux.cpp
+++ b/source/soundux.cpp
@@ -236,8 +236,10 @@ END_OF_FUNCTION(S9xSetEnvelopeRate);
void S9xSetSoundVolume (int channel, short volume_left, short volume_right)
{
Channel *ch = &SoundData.channels[channel];
+#ifndef FOREVER_STEREO
if (!so.stereo)
volume_left = (ABS(volume_right) + ABS(volume_left)) / 2;
+#endif
ch->volume_left = volume_left;
ch->volume_right = volume_right;
@@ -255,8 +257,10 @@ void S9xSetMasterVolume (short volume_left, short volume_right)
}
else
{
+#ifndef FOREVER_STEREO
if (!so.stereo)
volume_left = (ABS (volume_right) + ABS (volume_left)) / 2;
+#endif
SoundData.master_volume_left = volume_left;
SoundData.master_volume_right = volume_right;
SoundData.master_volume [Settings.ReverseStereo] = volume_left;
@@ -266,8 +270,10 @@ void S9xSetMasterVolume (short volume_left, short volume_right)
void S9xSetEchoVolume (short volume_left, short volume_right)
{
+#ifndef FOREVER_STEREO
if (!so.stereo)
volume_left = (ABS (volume_right) + ABS (volume_left)) / 2;
+#endif
SoundData.echo_volume_left = volume_left;
SoundData.echo_volume_right = volume_right;
SoundData.echo_volume [Settings.ReverseStereo] = volume_left;
@@ -304,7 +310,9 @@ void S9xSetEchoFeedback (int feedback)
void S9xSetEchoDelay (int delay)
{
SoundData.echo_buffer_size = (512 * delay * so.playback_rate) / 32000;
+#ifndef FOREVER_STEREO
if (so.stereo)
+#endif
SoundData.echo_buffer_size <<= 1;
if (SoundData.echo_buffer_size)
SoundData.echo_ptr %= SoundData.echo_buffer_size;
@@ -803,7 +811,7 @@ void DecodeBlock (Channel *ch)
// Header validity check: if range(shift) is over 12, ignore
// all bits of the data for that block except for the sign bit of each
- invalid_header = !(shift < 0xD);
+ invalid_header = (shift >= 0xD);
filter = filter&0x0c;
@@ -1155,6 +1163,7 @@ stereo_exit: ;
END_OF_FUNCTION(MixStereo);
#endif
+#ifndef FOREVER_STEREO
void MixMono (int sample_count)
{
static int wave[SOUND_BUFFER_SIZE];
@@ -1438,6 +1447,7 @@ mono_exit: ;
#ifdef __DJGPP
END_OF_FUNCTION(MixMono);
#endif
+#endif // !defined FOREVER_STEREO
#ifdef __sun
extern uint8 int2ulaw (int);
@@ -1462,16 +1472,22 @@ void S9xMixSamples (uint8 *buffer, int sample_count)
memset (MixBuffer, 0, sample_count * sizeof (MixBuffer [0]));
if (SoundData.echo_enable)
memset (EchoBuffer, 0, sample_count * sizeof (EchoBuffer [0]));
-
+
+#ifndef FOREVER_STEREO
if (so.stereo)
+#endif
MixStereo (sample_count);
+#ifndef FOREVER_STEREO
else
MixMono (sample_count);
+#endif
}
/* Mix and convert waveforms */
+#ifndef FOREVER_16_BIT_SOUND
if (so.sixteen_bit)
{
+#endif
int byte_count = sample_count << 1;
// 16-bit sound
@@ -1483,8 +1499,10 @@ void S9xMixSamples (uint8 *buffer, int sample_count)
{
if (SoundData.echo_enable && SoundData.echo_buffer_size)
{
+#ifndef FOREVER_STEREO
if (so.stereo)
{
+#endif
// 16-bit stereo sound with echo enabled ...
if (SoundData.no_filter)
{
@@ -1540,6 +1558,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count)
((signed short *) buffer)[J] = I;
}
}
+#ifndef FOREVER_STEREO
}
else
{
@@ -1596,6 +1615,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count)
}
}
}
+#endif
}
else
{
@@ -1610,6 +1630,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count)
}
}
}
+#ifndef FOREVER_16_BIT_SOUND
}
else
{
@@ -1758,6 +1779,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count)
}
}
}
+#endif
}
#ifdef __DJGPP
@@ -1854,8 +1876,12 @@ bool8 S9xInitSound (int mode, bool8 stereo, int buffer_size)
so.playback_rate = 0;
so.buffer_size = 0;
+#ifndef FOREVER_STEREO
so.stereo = stereo;
+#endif
+#ifndef FOREVER_16_BIT_SOUND
so.sixteen_bit = Settings.SixteenBitSound;
+#endif
so.encoded = FALSE;
S9xResetSound (TRUE);
diff --git a/source/soundux.h b/source/soundux.h
index 9892dcf..fe96f73 100644
--- a/source/soundux.h
+++ b/source/soundux.h
@@ -124,8 +124,12 @@ typedef struct {
int buffer_size;
int noise_gen;
bool8 mute_sound;
+#ifndef FOREVER_STEREO
int stereo;
+#endif
+#ifndef FOREVER_16_BIT_SOUND
bool8 sixteen_bit;
+#endif
bool8 encoded;
#ifdef __sun
int last_eof;