Page 1 of 2

Yamaha RX-5 ROM format parser/extractor

PostPosted: Fri Mar 10, 2017 12:53 am
by ʝɵʝɵ
Back in 2010, a friend was going to circuit-bend a Yamaha RX-5 for me, including the possibility to replace the samples ROM. Sadly this project was never finished, I still don't have an RX-5 but I just found this old piece of FreeBASIC code from back then (I was just transitioning to mainly programming in C++ at that time) which parses the sample headers, prints out some debug info and dumps the sample data. Some stuff remains unknown since I did not know the exact parameters used on the device back then. But hey, maybe someone will find this code snippet to be helpful someday.

Code: Select all
' RX-5 ROM extractor
' By Saga Games
' https://sagagames.de/
' BSD license

#Define ROM_FILE "M5M23C100-512P.bin"
'#Define ROM_FILE "M5M23C100-513P-4.bin"
#Define DUMP_SAMPLES

#Include "vbcompat.bi"

#Macro BSWAP32(a)
Asm
   mov eax, [a]
   bswap eax
   mov [a], eax
End Asm
#EndMacro

#Define BSWAP16(a) a = (((a And &HFF) Shl 8) Or ((a And &HFF00) Shr 8))

Function Checksum(Bytes As Byte Ptr, BLen As Integer) As Integer
   Dim As UShort chsum = 0, origsum = 0
   For i As Integer = 0 To BLen - 3
      chsum += *Cast(UByte Ptr, @Bytes[i])
   Next
   origsum = *Cast(UShort Ptr, @Bytes[BLen - 2])
   BSWAP16(origsum)
   If(origsum = chsum) Then Return chsum Else Return -1
End Function

Type filehead Field = 1
   Dim As UInteger nulls
   Dim As UByte unknown
   Dim As UByte numsamples
End Type

Type smphead Field = 1
   Dim As UShort unknown1   ' $02, $78
   Dim As UByte flags      ' 01 = 12-bit, 00 = 8-bit
   Dim As UByte unknown2   ' AND 01 is loop on??? what is AND $40?
   Dim As UShort offset
   Dim As UShort unknown3
   Dim As UInteger endoffset
   Dim As UShort loopend
   Dim As ZString * 12 unknown4
   Dim As ZString * 6 sname
End Type

Assert(SizeOf(smphead) = 32)

Open ROM_FILE For Binary As #1

Dim As filehead  fhead
Get #1, 1, fhead

Dim As smphead sheader
Dim As UInteger fulloffset, fulllength, loopend

Print fhead.numsamples & " samples..."
Print

For i As Integer = 1 To fhead.numsamples
   Get #1, , sheader

   fulloffset = (sheader.offset And &H0FFF) Shl 8 ' the low 8 bits of the offset are not stored (this allows 24-bit addressing)

   fulllength = sheader.endoffset
   BSWAP32(fulllength)
   fulllength = ((fulllength And &H0FFFFF00) Shr 8) - fulloffset

   loopend = sheader.loopend
   BSWAP16(loopend)
   loopend = (loopend And &H0FFFFF) - fulloffset

   Print Hex(i, 2) & " " & sheader.sname; ": Offset $" & Hex(fulloffset, 5) & " - Length $" & Hex(fulllength, 5) & " - LEnd $" & Hex(loopend, 5) & " - ";
   If(sheader.flags And &H01) Then Print "12-bit" Else Print "8-bit"
   If(sheader.flags > 1) Then Print "UNKNOWN FLAG ERROR!"

   ' dumping samples
   #Ifdef DUMP_SAMPLES
   Dim As Integer oldpos = Loc(1)
   Kill Trim(sheader.sname)
   Open Trim(sheader.sname) For Binary As #2
   Dim As String buffer = Space(fulllength)
   Get #1, fulloffset + 1,buffer
   Put #2, 1,buffer
   Close #2
   Seek #1, oldpos + 1
   #EndIf
Next

Print

Dim As Integer romChSum
Dim As Byte Ptr romData = Allocate(Lof(1))
Get #1, 1, *romData, Lof(1)

#Macro CalcChecksum(sName, nLen)
romChSum = Checksum(romData, nLen)
If(romChSum <> - 1) Then Print sName & " checksum OK (" & Hex(romChSum) & ")" Else Print sName & " checksum error!"
#EndMacro

CalcChecksum("Header", 1024)
CalcChecksum("ROM", Lof(1))

Close #1

Sleep


Note: Not tested on recent FreeBASIC compiler. They have removed a lot of old cruft from the main language dialect (which is good!) so I don't know if it still compiles.

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Fri Mar 10, 2017 11:12 am
by madtheory
That's pretty cool! If someone could go ahead and just extract the samples to WAVs, I'd be happy :) It's fascinating to play back samples from ancient machines with modern hardware. IMO the greater part of the character comes from the sampling/ encoding process, not the playback, as long as there is no transposing in playback of course.

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Fri Mar 10, 2017 12:53 pm
by ʝɵʝɵ
madtheory wrote:That's pretty cool! If someone could go ahead and just extract the samples to WAVs, I'd be happy :)

I can do that later. I do still have the two ROM files, M5M23C100-512P.bin and M5M23C100-513P-4.bin, but I don't remember exactly where those came from, and in particular if the RX-5 used two ROMs or if one of them was an expansion, etc.

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Mon Mar 13, 2017 9:46 pm
by ʝɵʝɵ
Waveform data (8bit / 16bit)

The layout of the 12-bit sample data is as follows:
Read three bytes and split them into nibbles: B0Low, B0High, B1Low, B1High, B2Low, B2High
This gives us two 16-bit samples:
Sample1 = (B1High << 12) | (B1Low << 8) | (B2High << 4)
Sample2 = (B2Low << 12) | (B3High << 8) | (B3Low << 4)

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Sun Mar 19, 2017 2:22 pm
by madtheory
O cool. These sound a bit different to what I remember on the machine though. Is there compansion?

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Sun Mar 19, 2017 2:29 pm
by ʝɵʝɵ
madtheory wrote:O cool. These sound a bit different to what I remember on the machine though. Is there compansion?

I would guess that the samples are compressed and there are volume envelopes to shape the sound, simply to have the best possible SNR on the stored samples. I didn't fully reverse-engineer the ROM format, so I don't know the details.

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Mon Mar 20, 2017 12:56 am
by gmeredith
The actual raw samples, especially of those 80s era sampled machines, sound very different from the sound that comes out of the analog outputs. People have extracted the TR707 wav files and found them to be almost unrecognisable. 4-bit samples compressed to within an inch of their lives! The companding and VCA circuitry did all the work, so that tiny amounts of RAM could be used and still have good S/N ratios and sample times, which was expensive back then.

It's much better to sample the actual outputs of the machines, if you want to use the samples in modern, equipment, that's what I do. The sound of the machine is much more than just its samples, it's the whole package that gives the characteristic sound. Do a search, especially on Freesound, there are lots of instrument sounds from drum machines already sampled there for you to load

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Mon Mar 20, 2017 11:22 am
by ʝɵʝɵ
It's also worth noting that the awesome kb6 drum collection has RX-5 samples.

It's much better to sample the actual outputs of the machines, if you want to use the samples in modern, equipment, that's what I do. The sound of the machine is much more than just its samples, it's the whole package that gives the characteristic sound.

In principal I do agree, but sometimes you want to do things with the original waveforms that are not possible with the original machine. :) In that case, applying a volume envelope to the ripped samples and then processing them further might be the best solution.

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Mon Mar 20, 2017 1:48 pm
by madtheory
Agreed. It's not necessarily better to have the ROMs or the DAC output. False dichotomy. Both have wide sonic possibilities. This case here of the ROMs is pretty cool, because that's not been available before AFAIK. There's a ton of samples of RX-5 DAC outputs out there. It's also interesting to discover which machines companded and which did not.

So did Yamaha use some kind of fairly simple companding? I guess a file comparison of DAC out vs ROM would reveal the envelope used?

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Fri Nov 23, 2018 11:29 am
by Anders Schroder
I have all the ROMS. can someone help me with dumping them to wavs?

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Sun Nov 25, 2018 10:28 pm
by ʝɵʝɵ
Hello Anders,
I have compiled the program from my first post of this topic into a Windows EXE file. You can download it here:
https://sagagames.de/stuff/rx5extract.zip
Drop a ROM file on the executable and it should extract the WAV files in the same folder as the EXE file.
This was only tested on the stock ROM so I cannot guarantee that it works with other ROMs.
Hope this helps.

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Mon Nov 26, 2018 9:36 pm
by madtheory
Do you think you could do the same for the Alesis SR-16? The raw ROM is an interleaved format stored as 8 bit data IIRC. Doesn't seem to be companded. Could do it manually, but it's a lot of editing, with the velocity layers.

Problem is burnkit site, where it was uploaded, is currently down :(

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Mon Nov 26, 2018 9:56 pm
by ʝɵʝɵ
Truth is, I am already swamped in project so I'd rather spend the time I would have to invest into this into more urgent things.

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Tue Nov 27, 2018 8:42 am
by madtheory
That's cool, thanks again for doing this RX-5 one! PS your awesome MRAM card is still going strong in this studio :)

Re: Yamaha RX-5 ROM format parser/extractor

PostPosted: Wed Nov 28, 2018 3:07 pm
by Rasputin
madtheory wrote:Do you think you could do the same for the Alesis SR-16? The raw ROM is an interleaved format stored as 8 bit data IIRC. Doesn't seem to be companded. Could do it manually, but it's a lot of editing, with the velocity layers.

Problem is burnkit site, where it was uploaded, is currently down :(


If you need an Alesis SR16 sound ROM extractor tool, I could probably make one for you in a day or two.