How are PCM samples ripped from NES ROMS?

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Post Reply
SuperWill24
Posts: 33
Joined: Sat May 13, 2017 7:54 pm

How are PCM samples ripped from NES ROMS?

Post by SuperWill24 »

Earlier, I tried to ask a similar question about GBC ROMS that I was having trouble with, but nobody answered (it should be somewhere on GBDev, so feel free to help if you are interested and have the skill), so I thought I'd make a much more relevant topic here.

Basically, in general, how are PCM samples ripped from ROMS? I know a lot of NSFs have PCM samples, so how do they rip them and add them to the NSFs?
Specifically, what I'm talking about is "raw" (non-DPCM) PCM. There are at least a couple of games in mind that I would particularly like to rip from (Star Wars Episode V, Hammerin' Harry, and Gauntlet II), but can't find a reliable way to do so.

What I want to know is the following: Does the process usually involve reverse-engineering of the sound engine? Are the sample table offsets randomly found? How is the precise sample rate found? Do you use data/code logger or whatever it is from FCEUX to do so? How is the format (number of bits, endianness) figured out? Also, although not as important: is there a reliable way to extract DPCM samples from NES ROMs (not necessarily NSFs)?

So, I apologize if I'm being too broad here, but I must say that for some reason, I am fascinated with the sample data of old systems, especially NES and Game Boy.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How are PCM samples ripped from NES ROMS?

Post by rainwarrior »

Endian concerns don't matter until you have 16-bit samples, which would probably never happen in an 8-bit game.

Most often a PCM sample is just encoded as a raw 8-bit PCM, you can just open a ROM in a sound editor as raw PCM and play it and you'll hear the samples in it.

Sometimes the samples are signed or unsigned, but that just means you have to listen to it twice.

On more rare occasions, PCM samples might be compressed into some other format.

Big Bird's Hide and Speak had a strange compression format: viewtopic.php?t=8675

Bayou Billy even has PCM output by software decoding from NES format DPCM samples: https://forums.nesdev.com/viewtopic.php ... 24#p211224

There are a lot of ways to compress sound, though. Nowadays most sound compression method is some variation of a fourier transform to convert waves to frequencies, and then discarding the less important frequencies, but before we had hardware that could do this effectively there were many other techniques experimented with. Tepples wrote an article on Forrest Mozer's compression technique used in some C64 games.
Last edited by rainwarrior on Sun Feb 25, 2018 9:43 pm, edited 2 times in total.
User avatar
MrNorbert1994
Posts: 985
Joined: Tue May 06, 2014 1:50 pm
Location: Szeged, Hungary
Contact:

Re: How are PCM samples ripped from NES ROMS?

Post by MrNorbert1994 »

You rip the samples just like music.
You have to find their respective play and init entry points, and after you ripped it, you have add it to the music + sfx nsf via the bankswithching.
The PCM NSFs can be very big since they eat up a lot of CPU time, and because of this, most of the time the samples are located on multiple banks (like Skate Or Die, Mickey Mouse Letterland + NumberLand), or sometimes you have to design your own engine bankswitch since for example Dirty Harry changes the samples during playback.

I actually ripped a few samples for Hammerin' Harry a while ago.
Last edited by MrNorbert1994 on Sun Feb 25, 2018 9:48 pm, edited 1 time in total.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How are PCM samples ripped from NES ROMS?

Post by rainwarrior »

Twenty years ago I wanted to make a Doom theme for Tetrinet, and I opened the WAD file as a raw PCM to extract a bunch of sound effects.

The other "easy" way to rip these samples is to mute all the channels its not playing on, and then just record the sound output of the emulator, especially if you can disable highpass/lowpass filters on the output. With some careful resampling and quantization you might be able to get back the original PCM exactly. With some less careful work, you at least have it it in a recorded form that you can use.


If you're trying to make an NSF play the sample, though, you don't need to worry about its samplerate or how its encoded, the task is really just to find the code routine that plays it and get it to run. The code will take care of the reset.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How are PCM samples ripped from NES ROMS?

Post by tepples »

rainwarrior wrote:Endian concerns don't matter until you have 16-bit samples, which would probably never happen in an 8-bit game.
4-bit samples stored in an 8-bit memory have endianness. For example, the Game Boy wavetable channel is opposite the Namco 163. And I've found that a lot of NES games using PCM use 4-bit PCM.
rainwarrior wrote:Bayou Billy even has PCM output by software decoding from NES format DPCM samples: https://forums.nesdev.com/viewtopic.php ... 24#p211224
As does Blades of Steel for "face off" and the like.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How are PCM samples ripped from NES ROMS?

Post by rainwarrior »

tepples wrote:4-bit samples stored in an 8-bit memory have endianness. For example, the Game Boy wavetable channel is opposite the Namco 163. And I've found that a lot of NES games using PCM use 4-bit PCM.
Fair enough. I wouldn''t have called that "endian" in the traditional sense, but sure it would fit some definitions.

What games use 4-bit PCM? (Excluding N163.)
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How are PCM samples ripped from NES ROMS?

Post by tepples »

Skate or Die 2 is the one that comes to mind first.
In [url=https://forums.nesdev.com/viewtopic.php?p=181499#p181499]this post[/url], tepples wrote:SoD2's samples are 4-bit linear PCM (or as linear as the APU DMC DAC allows). Years ago, I wrote an extractor that turns the whole ROM into a wave file; it shouldn't be too hard to write your own if you know any PC programming language.
I forget which others there were. But if you're curious, I could write a Python program that runs heuristics on a PRG ROM to see what parts look like 4-bit linear PCM (and which nibble order).
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How are PCM samples ripped from NES ROMS?

Post by rainwarrior »

I'm not asking for you to write a program, but I'm curious what your heuristic is to decide if some data is a sound sample? A high number of successive values that differ by a small number from each other?
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How are PCM samples ripped from NES ROMS?

Post by tepples »

rainwarrior wrote:I'm curious what your heuristic is to decide if some data is a sound sample? A high number of successive values that differ by a small number from each other?
That'd be the first thing I try, related to lag 1 autocorrelation. If I were actually writing a PCM finder, I would have refined it based on metrics gathered from test data.
SuperWill24
Posts: 33
Joined: Sat May 13, 2017 7:54 pm

Re: How are PCM samples ripped from NES ROMS?

Post by SuperWill24 »

tepples wrote:Skate or Die 2 is the one that comes to mind first.
In [url=https://forums.nesdev.com/viewtopic.php?p=181499#p181499]this post[/url], tepples wrote:SoD2's samples are 4-bit linear PCM (or as linear as the APU DMC DAC allows). Years ago, I wrote an extractor that turns the whole ROM into a wave file; it shouldn't be too hard to write your own if you know any PC programming language.
I forget which others there were. But if you're curious, I could write a Python program that runs heuristics on a PRG ROM to see what parts look like 4-bit linear PCM (and which nibble order).

Sorry I'm late, but I would appreciate if you wrote that program sometime in the future. It would also be very useful to tell which Game Boy or Game Boy Color games use PCM as well. :)
Post Reply