Configure the wave table the kernel uses for the bling sound

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
Post Reply
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Configure the wave table the kernel uses for the bling sound

Post by Artcfox »

In order to free up flash space in your Uzebox game, it's common to include this in your Makefile:

Code: Select all

## In order to save quite a bit of flash space, it is possible to include only
## the waves that your patches.inc file uses, by including a custom sounds.inc
## file rather than the one included in the kernel by default. The trickery
## below is required to escape spaces in mixer path (due to custom sounds.inc).
## Be aware that if you remove waves from the wavetable, the indices of the
## waves you specify in your patches.inc file may need to be changed to match!
## To use a custom sounds.inc file, copy the one from kernel/data/sounds.inc
## into your game's data directory, and uncomment the following lines:
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
SPACE_ESC := \\$(SPACE)
MIX_PATH := $(realpath ../data/sounds.inc)
MIX_PATH_ESC := $(subst $(SPACE),$(SPACE_ESC),$(MIX_PATH))
KERNEL_OPTIONS += -DMIXER_WAVES=\"$(MIX_PATH_ESC)\"
That's all well and good, and can save you up to a couple thousand bytes depending on how many wave tables you include in your custom sounds.inc, you just have to remember to renumber the indices in your patch files.

But if your Makefile also includes:

Code: Select all

KERNEL_OPTIONS += -DINTRO_LOGO=1
Then the startup sound may end up sounding like a horrific and terrible noise, because inside the kernel that patch is hardcoded to use table #8, which may not even exist if you use a custom sounds.inc!

I'm proposing the addition of a new define called INTRO_WAVETABLE, that can override the default wave table index used by the intro code in the kernel. For example:

Code: Select all

KERNEL_OPTIONS += -DINTRO_LOGO=1 -DINTRO_WAVETABLE=1
My proposed implementation looks like this:

Code: Select all

diff --git a/kernel/defines.h b/kernel/defines.h
index 7fd052e..65fa4be 100644
--- a/kernel/defines.h
+++ b/kernel/defines.h
@@ -124,6 +124,18 @@
 	#endif
 
 	/*
+	 * Wave table index for the "bling" sound that accompanies the Uzebox logo when the console is reset
+	 * 8 = default
+	 * N = Use the Nth wave table for the "bling" sound (very useful when you are using a custom sounds.inc)
+	 * 
+	 */
+	#if INTRO_LOGO == 1
+		#ifndef INTRO_WAVETABLE
+			#define INTRO_WAVETABLE 8
+		#endif
+	#endif
+
+	/*
 	 * Joystick type used on the board.
 	 * Note: Will be read from EEPROM in a future release. 
 	 *
diff --git a/kernel/intro.h b/kernel/intro.h
index 23921cd..85734f2 100644
--- a/kernel/intro.h
+++ b/kernel/intro.h
@@ -25,7 +25,7 @@
 
 	//Logo "kling" sound
 	const char initPatch[] PROGMEM ={	
-	0,PC_WAVE,8,
+	0,PC_WAVE,INTRO_WAVETABLE,
 	0,PC_PITCH,85,
 	4,PC_PITCH,90,
 	0,PC_ENV_SPEED,-8,   
What do you guys think?
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Configure the wave table the kernel uses for the bling sound

Post by D3thAdd3r »

I believe this should be done, since it seems a little rough to have such a standard Uzebox thing hardcoded when there is no cost to doing it more flexibly.
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Configure the wave table the kernel uses for the bling sound

Post by Jubatian »

I added it, hope OK. (I also ran into this with FoaD, but there I already butchered the kernel beyond hope when I faced this issue, eventually forgetting about it)
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Configure the wave table the kernel uses for the bling sound

Post by Artcfox »

Jubatian wrote:I added it, hope OK. (I also ran into this with FoaD, but there I already butchered the kernel beyond hope when I faced this issue, eventually forgetting about it)
Beautiful (and I see you simplified the code), thanks!
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Configure the wave table the kernel uses for the bling sound

Post by D3thAdd3r »

Cool thanks for adding that. Stuff like that needs to be done right away I believe, otherwise we forget about good features that never make the kernel.
Post Reply