Sound Engines for Homebrew

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
ashterix
Posts: 11
Joined: Tue Dec 29, 2015 2:42 pm

Sound Engines for Homebrew

Post by ashterix »

Are there freely-usable sound engines for homebrew SNES projects available (something like Echo for Genesis)?
Kannagi
Posts: 100
Joined: Sun May 11, 2014 8:36 am
Location: France

Re: Sound Engines for Homebrew

Post by Kannagi »

I am never tested but there are SnesMod and SnesGss.

I try to finish my audio driver too.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Sound Engines for Homebrew

Post by psycopathicteen »

Something that I find a bottleneck is the lack of BRR sample libraries.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Sound Engines for Homebrew

Post by tepples »

There are tools to convert WAV files to BRR. What WAV sound libraries do developers of low-budget games for other platforms use?
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Sound Engines for Homebrew

Post by psycopathicteen »

Earlier today I had the idea of a "polygon synthesizer" where the waves could be stored as straight lines of various slopes and legnths, as a way to create custom sounds without having to manipulate long BRR samples in hex. Have either the 65816 or SPC700 convert samples from the "polygon synth" format into BRR samples before a level starts.
Last edited by psycopathicteen on Thu Dec 29, 2016 4:32 pm, edited 1 time in total.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Sound Engines for Homebrew

Post by Bregalad »

SNES Game Sound System was released recently for exacly that purpose.

Also I'd always have loved to release mine, but for some reason didn't go through the effort yet.
imamelia
Posts: 16
Joined: Wed Sep 01, 2010 12:17 am

Re: Sound Engines for Homebrew

Post by imamelia »

psycopathicteen wrote:Something that I find a bottleneck is the lack of BRR sample libraries.
That's one thing I've found annoying, too, even when just doing ROM hacking. And even if you can convert WAV to BRR, that assumes that you both have WAVs that would work (not too big, loopable) and that you have a way to convert them accurately.
KungFuFurby
Posts: 275
Joined: Wed Jul 09, 2008 8:46 pm

Re: Sound Engines for Homebrew

Post by KungFuFurby »

That's why there's always downsampling to deal with that peculiar problem. I use Schism Tracker (for editing and downsampling, particularly since the resulting length has to be divisible by 16) and the SNESMod program so that I can just simply convert them over on the fly (and have working prototypes, since these days I'm getting less and less interested SNESMod, although I still keep it since I know it has at least one critical operation that I use: making the BRR samples... then I can extract them straight out of the .spc file!).
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Sound Engines for Homebrew

Post by psycopathicteen »

Do any games use an in-cart sound chip?
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Sound Engines for Homebrew

Post by lidnariq »

The MSU-1 and the Super Game Boy. You can argue whether those count...
User avatar
mikejmoffitt
Posts: 1353
Joined: Sun May 27, 2012 8:43 pm

Re: Sound Engines for Homebrew

Post by mikejmoffitt »

A neat tool would be a FamiTracker export converter, that spits out working SPC700 code. The simple 2A03 waveforms as BRR samples wouldn't be too complicated, and some expansion audio wouldn't even be too difficult to throw in. MMC5 would basically be free, and it would not be a far cry to get VRC6 in there.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Sound Engines for Homebrew

Post by psycopathicteen »

I would like to see someone making a WAV to BRR code using either the 65816 or SPC700, including filter and range selecting, so it can synthesize it's own samples, and then fill up the sound RAM with everything. The problem is it would take several seconds if you're going to fill up 64kB of RAM.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Sound Engines for Homebrew

Post by psycopathicteen »

Here is some spc700 code I've been working on that could generate BRR samples for simple wave shapes stored as line segment data. It computes an 8-bit PCM wave, and then truncates it to 4-bit BRR. Line segments are allowed to wrap when passing 255 or 0.
generate_brr_sample_library:
ldx #$00
-;
ldy #$00
lda ({source}),y
beq +
phx
jsr polygon_synth
plx
lda {brr_buffer}
sta {directory},x
sta {directory}+2,x
lda {brr_buffer}+1
sta {directory}+1,x
sta {directory}+3,x
inx
inx
inx
inx
tya
ldy #$00
adw {brr_buffer}
stw {brr_buffer}
bra -
+;
rts

polygon_synth:
ldx #$00
ldy #$00
str {temp}=#$00
lda ({source}),y
sta {countdown}
iny
lda ({source}),y
sta {header_byte}

-;
iny
lda ({source}),y
sta {temp2}
lda {temp}
iny
-;
clc
adc ({source}),y
sta {wave_buffer},x
inx
dec {temp2}
bne -
sta {temp}
dec {countdown}
bne --
txa
xcn
and #$0f
sta {#_of_blocks}

iny

tya
ldy #$00
adw {source}
stw {source}

jsr convert_wav_to_brr
rts


convert_wav_to_brr:
ldx #$00
ldy #$00
-;
lda {header_byte}
cmp {#_of_blocks}=#$01
bne +
inc
+;
sta ({brr_buffer}),y
str {temp2}=#$08
-;
lda {wave_buffer},x
and #$f0
sta {temp}
inx
lda {wave_buffer},x
and #$f0
xcn
ora {temp}
inx
iny
sta ({brr_buffer}),y
dec {temp2}
bne -
iny
dec {#_of_blocks}
bne --

rts
...and for the format:

Code: Select all

byte 0: number of line segments in wave shape (0 means no more BRR samples)
byte 1: BRR header byte

repeats for "byte 0" amount of times
byte 2n+2: length in samples of line segment
byte 2n+3: 8-bit slope

Then it repeats for the next BRR sample until "byte 0" is 0.

Waves that are not divisible by 16, get clipped to the nearest multiple of 16.
Some examples:

Code: Select all

square_wave:
db $04,$92                             //4 line segments, with BRR header of $92
db $01,$7f                              //first line, 1 sample long, with slope of 127
db $1f,$00                              //second line, 31 samples long, with no slope
db $01,$01                             //third line, 1 sample long, slope is 1 but wraps around to -128
db $1f,$00                              //forth line, 31 samples long, with no slope

saw_wave:
db $01,$92                             //only 1 line segment needed, with BRR header of $92
db $40,$04                             //64 samples long with a slope of 4, wraps around
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Sound Engines for Homebrew

Post by Bregalad »

psycopathicteen wrote:Something that I find a bottleneck is the lack of BRR sample libraries.
Such a library could be rather easy to make by taking a General MIDI sample set and turning all of them into BRR... although the quality to use is always a space/quality tradeoff we cannot take in advance without knowing the application.
that assumes that you both have WAVs that would work (not too big, loopable)
You're supposed to record them from your syntesizer. All WAVs are loopable, whether the loop actually sounds good however is a different debate.

You can also synthesise simple wavform in BRR directly, such as square vave, saw wave, etc...
I would like to see someone making a WAV to BRR code using either the 65816 or SPC700
And what'd be the point exactly ?! It'd be the same trouble to find WAV files, *and* it would take more memory. The only point I see is that the 65C816 (or the SPC700) could automatically adjust the sample's quality depending on the song which is playing, so that it uses memory most efficiently at all times. Yet such a system would still be incredibly complex for small benefits (i.e. better sound quality for music pieces using few different samples), it sounds better to do this work manually on a case-by-case basis.
Earlier today I had the idea of a "polygon synthesizer" where the waves could be stored as straight lines of various slopes and legnths, as a way to create custom sounds without having to manipulate long BRR samples in hex
Very interesting idea ! Especially if you can move the "polygon" during playback to create effects. Chrono Trigger does something like that but it just changes a pulse wave's duty cycle permanently.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Sound Engines for Homebrew

Post by psycopathicteen »

Bregalad wrote:
I would like to see someone making a WAV to BRR code using either the 65816 or SPC700
And what'd be the point exactly ?! It'd be the same trouble to find WAV files, *and* it would take more memory. The only point I see is that the 65C816 (or the SPC700) could automatically adjust the sample's quality depending on the song which is playing, so that it uses memory most efficiently at all times. Yet such a system would still be incredibly complex for small benefits (i.e. better sound quality for music pieces using few different samples), it sounds better to do this work manually on a case-by-case basis.
If you're doing polygon synth, you can doing the easy way and just generate 4-bit PCM samples (BRR filter is always 0), or do it the more CPU intensive way of figuring out which filter/range settting is best for which BRR block.
Post Reply