aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNebuleon Fumika2013-01-20 22:26:24 -0500
committerNebuleon Fumika2013-01-20 22:26:24 -0500
commit7d788578b2cfe454d5c266552411820b50075d08 (patch)
treea258bca977946df3c2dfde86837f58b7979d8e90
parent0f91ed22f32bae7e8fb924fa4458142fa5894f83 (diff)
downloadsnes9x2005-7d788578b2cfe454d5c266552411820b50075d08.tar.gz
snes9x2005-7d788578b2cfe454d5c266552411820b50075d08.tar.bz2
snes9x2005-7d788578b2cfe454d5c266552411820b50075d08.zip
Initial 8-bit sound commit. For the lulz!
-rw-r--r--source/nds/entry.cpp2
-rw-r--r--source/snes9x.h2
-rw-r--r--source/soundux.cpp132
-rw-r--r--source/soundux.h2
4 files changed, 84 insertions, 54 deletions
diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp
index 8cd5c06..792608a 100644
--- a/source/nds/entry.cpp
+++ b/source/nds/entry.cpp
@@ -370,6 +370,7 @@ void init_sfc_setting(void)
//sound settings
Settings.APUEnabled = Settings.NextAPUEnabled = TRUE;
Settings.FixFrequency = 1;
+ S9xSetEightBitConsoleSound (TRUE);
Settings.H_Max = SNES_CYCLES_PER_SCANLINE;
@@ -377,7 +378,6 @@ void init_sfc_setting(void)
Settings.ShutdownMaster = TRUE;
Settings.FrameTimePAL = 20000;
Settings.FrameTimeNTSC = 16667;
- Settings.DisableSampleCaching = FALSE;
Settings.DisableMasterVolume = FALSE;
Settings.Mouse = TRUE;
Settings.SuperScope = TRUE;
diff --git a/source/snes9x.h b/source/snes9x.h
index 6c93855..ab70efa 100644
--- a/source/snes9x.h
+++ b/source/snes9x.h
@@ -337,11 +337,11 @@ struct SSettings{
#ifndef FOREVER_16_BIT_SOUND
bool8 SixteenBitSound;
#endif
+ bool8 EightBitConsoleSound; // due to caching, this needs S9xSetEightBitConsoleSound()
int SoundBufferSize;
int SoundMixInterval;
bool8 SoundEnvelopeHeightReading;
bool8 DisableSoundEcho;
- bool8 DisableSampleCaching;
bool8 DisableMasterVolume;
bool8 SoundSync;
bool8 InterpolatedSound;
diff --git a/source/soundux.cpp b/source/soundux.cpp
index acddd0a..45e303b 100644
--- a/source/soundux.cpp
+++ b/source/soundux.cpp
@@ -166,6 +166,21 @@ extern "C" void DecodeBlockAsm2 (int8 *, int16 *, int32 *, int32 *);
#define LAST_SAMPLE 0xffffff
#define JUST_PLAYED_LAST_SAMPLE(c) ((c)->sample_pointer >= LAST_SAMPLE)
+const int16 SQUARE_WAVE_SAMPLE[16] = {32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, -32768, -32768, -32768, -32768, -32768, -32768, -32768, -32768,};
+
+void S9xSetEightBitConsoleSound (bool8 Enabled)
+{
+ if (Settings.EightBitConsoleSound != Enabled)
+ {
+ Settings.EightBitConsoleSound = Enabled;
+ int i;
+ for (i = 0; i < 8; i++)
+ {
+ SoundData.channels[i].needs_decode = TRUE;
+ }
+ }
+}
+
STATIC inline uint8 *S9xGetSampleAddress (int sample_number)
{
uint32 addr = (((APU.DSP[APU_DIR] << 8) + (sample_number << 2)) & 0xffff);
@@ -804,7 +819,7 @@ void DecodeBlock (Channel *ch)
signed char sample1, sample2;
unsigned char i;
bool invalid_header;
-
+
if (Settings.AltSampleDecode)
{
if (Settings.AltSampleDecode < 3)
@@ -820,74 +835,87 @@ void DecodeBlock (Channel *ch)
ch->block = ch->decoded;
return;
}
- signed char *compressed = (signed char *) &IAPU.RAM [ch->block_pointer];
+
+ if (Settings.EightBitConsoleSound)
+ {
+ signed char *compressed = (signed char *) &IAPU.RAM [ch->block_pointer];
+
+ filter = *compressed;
+ if ((ch->last_block = filter & 1))
+ ch->loop = (filter & 2) != 0;
+ ch->block = ch->decoded;
+ memcpy(ch->decoded, SQUARE_WAVE_SAMPLE, sizeof(SQUARE_WAVE_SAMPLE));
+ }
+ else
+ {
+ signed char *compressed = (signed char *) &IAPU.RAM [ch->block_pointer];
- filter = *compressed;
- if ((ch->last_block = filter & 1))
- ch->loop = (filter & 2) != 0;
+ filter = *compressed;
+ if ((ch->last_block = filter & 1))
+ ch->loop = (filter & 2) != 0;
- compressed++;
- signed short *raw = ch->block = ch->decoded;
+ compressed++;
+ signed short *raw = ch->block = ch->decoded;
- // Seperate out the header parts used for decoding
+ // Seperate out the header parts used for decoding
- shift = filter >> 4;
+ shift = filter >> 4;
- // 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);
+ // 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);
- filter = filter&0x0c;
+ filter = filter&0x0c;
- int32 prev0 = ch->previous [0];
- int32 prev1 = ch->previous [1];
+ int32 prev0 = ch->previous [0];
+ int32 prev1 = ch->previous [1];
- for (i = 8; i != 0; i--)
- {
- sample1 = *compressed++;
- sample2 = sample1 << 4;
- //Sample 2 = Bottom Nibble, Sign Extended.
- sample2 >>= 4;
- //Sample 1 = Top Nibble, shifted down and Sign Extended.
- sample1 >>= 4;
- if (invalid_header) { sample1>>=3; sample2>>=3; }
+ for (i = 8; i != 0; i--)
+ {
+ sample1 = *compressed++;
+ sample2 = sample1 << 4;
+ //Sample 2 = Bottom Nibble, Sign Extended.
+ sample2 >>= 4;
+ //Sample 1 = Top Nibble, shifted down and Sign Extended.
+ sample1 >>= 4;
+ if (invalid_header) { sample1>>=3; sample2>>=3; }
- for (int nybblesmp = 0; nybblesmp<2; nybblesmp++){
- out=(((nybblesmp) ? sample2 : sample1) << shift);
- out >>= 1;
+ for (int nybblesmp = 0; nybblesmp<2; nybblesmp++){
+ out=(((nybblesmp) ? sample2 : sample1) << shift);
+ out >>= 1;
- switch(filter)
- {
- case 0x00:
- // Method0 - [Smp]
- break;
+ switch(filter)
+ {
+ case 0x00:
+ // Method0 - [Smp]
+ break;
- case 0x04:
- // Method1 - [Delta]+[Smp-1](15/16)
- out+=(prev0>>1)+((-prev0)>>5);
- break;
+ case 0x04:
+ // Method1 - [Delta]+[Smp-1](15/16)
+ out+=(prev0>>1)+((-prev0)>>5);
+ break;
- case 0x08:
- // Method2 - [Delta]+[Smp-1](61/32)-[Smp-2](15/16)
- out+=(prev0)+((-(prev0 +(prev0>>1)))>>5)-(prev1>>1)+(prev1>>5);
- break;
+ case 0x08:
+ // Method2 - [Delta]+[Smp-1](61/32)-[Smp-2](15/16)
+ out+=(prev0)+((-(prev0 +(prev0>>1)))>>5)-(prev1>>1)+(prev1>>5);
+ break;
- default:
- // Method3 - [Delta]+[Smp-1](115/64)-[Smp-2](13/16)
- out+=(prev0)+((-(prev0 + (prev0<<2) + (prev0<<3)))>>7)-(prev1>>1)+((prev1+(prev1>>1))>>4);
- break;
+ default:
+ // Method3 - [Delta]+[Smp-1](115/64)-[Smp-2](13/16)
+ out+=(prev0)+((-(prev0 + (prev0<<2) + (prev0<<3)))>>7)-(prev1>>1)+((prev1+(prev1>>1))>>4);
+ break;
+ }
+ CLIP16(out);
+ *raw++ = (signed short)(out<<1);
+ prev1=(signed short)prev0;
+ prev0=(signed short)(out<<1);
}
- CLIP16(out);
- *raw++ = (signed short)(out<<1);
- prev1=(signed short)prev0;
- prev0=(signed short)(out<<1);
}
+ ch->previous [0] = prev0;
+ ch->previous [1] = prev1;
}
- ch->previous [0] = prev0;
- ch->previous [1] = prev1;
-
- ch->block_pointer += 9;
+ ch->block_pointer += 9;
}
diff --git a/source/soundux.h b/source/soundux.h
index 8fb8396..224d24a 100644
--- a/source/soundux.h
+++ b/source/soundux.h
@@ -220,6 +220,8 @@ typedef struct
EXTERN_C SSoundData SoundData;
+void S9xSetEightBitConsoleSound (bool8 Enabled);
+
void S9xSetSoundVolume (int channel, short volume_left, short volume_right);
void S9xSetSoundFrequency (int channel, int hertz);
void S9xSetSoundHertz (int channel, int hertz);