Need Help scanning SNES roms for BRR audio

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
alexsmith
Posts: 2
Joined: Wed Apr 11, 2018 1:19 am

Need Help scanning SNES roms for BRR audio

Post by alexsmith » Mon Feb 24, 2020 10:26 am

Hi,
I'd like to make a hardware device capable of scanning SNES roms and extracting the audio BRR.
Basically a hardware implementation of SNESSOR - does anyone have the source code for this tool or willing to help me port it?
Thanks
Alex

User avatar
Bregalad
Posts: 7881
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Need Help scanning SNES roms for BRR audio

Post by Bregalad » Mon Feb 24, 2020 11:52 am

I don't have the source, but very, very probably SNESSOR relies on bits 2-3 in the header byte of the BRR block data which are always cleared (*)
Also the lower 2 bits are used but follow a very predictable pattern, bit 1 is either always set (looped samples) or always cleared (one-shot samples) (**), and bit 0 is cleared on all blocks but set to indicate the last block. Finally the upper nybble (4-7) should always be in the $0-$C range.

I'd implement this by interleaving the ROM in 9 sets of bytes which are all 9 bytes apart, each set being 1 byte apart eachother. Consider all those bytes as potential BRR sample headers, and reject them if you can see they're not. So if bit 2 or 3 is set, or if the upper nybble is in equal to $D, $E or $F, you know for sure it's not a BRR sample header.
Then it's possible to detect if the pattern described above is visible, it might be a BRR sample. You'll notice that SNESSOR has lots of fake positives, in that it will detect random data as BRR samples and play back garbage. Also, it misses very short samples used by games such as sine or square waves.

(*)Technically they're unused bits but de-facto SNES games clears them. it would be very easy to defeat the algorithm by setting those bits or having them taking random values instead.
(**) Technically this bit is used only in the last block, but SNES games just repeat the value to all blocks. It would be easy to defeat the algorithm by having this bit taking random values instead.
Last edited by Bregalad on Mon Feb 24, 2020 12:18 pm, edited 1 time in total.

lidnariq
Posts: 9403
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Need Help scanning SNES roms for BRR audio

Post by lidnariq » Mon Feb 24, 2020 12:10 pm

BRR samples have a period of 9 bytes, and almost nothing else should. Fourier transform or autocorrelation should find that easily. Getting specific alignment could then use the methods Bregalad mentioned.

alexsmith
Posts: 2
Joined: Wed Apr 11, 2018 1:19 am

Re: Need Help scanning SNES roms for BRR audio

Post by alexsmith » Tue Feb 25, 2020 1:09 am

Thanks for your tips Bregalad & lidnariq!
Cheers

Post Reply