ADPCM codec?

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

Moderator: Moderators

NotTheCommonDose
Posts: 523
Joined: Thu Jun 29, 2006 7:44 pm
Location: lolz!
Contact:

Post by NotTheCommonDose » Sun Nov 18, 2007 1:41 pm

If your asking me to do that, I can't even subtract or add numbers yet.

tepples
Posts: 21946
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sun Nov 18, 2007 3:18 pm

I haven't yet made an NES-side decoder, but I've simulated the compression and decompression process in C. Have a listen:

Audio file
"What should a Nintendo sound like?"
1. original wave; 2. through my 4-bit codec; 3. through dpcm at 4x oversampling (close to rate $F)

NotTheCommonDose
Posts: 523
Joined: Thu Jun 29, 2006 7:44 pm
Location: lolz!
Contact:

Post by NotTheCommonDose » Sun Nov 18, 2007 3:51 pm

probably 2. Was that you saying that?

tepples
Posts: 21946
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sun Nov 18, 2007 4:31 pm

NotTheCommonDose wrote:Was that you saying that?
Yes.

Does this rom work at all on NES hardware?

strangenesfreak
Posts: 155
Joined: Thu May 03, 2007 3:07 pm
Contact:

Post by strangenesfreak » Sun Nov 18, 2007 4:38 pm

tepples wrote:Yes.

Does this rom work at all on NES hardware?
I dunno about actual NES hardware (I cannot test it myself yet), but it does work on the latest versions of Nestopia and Nintendulator. Is that enough accuracy, or do you really need the NES itself? By the way, your demo's pretty cool - it has a pretty good sound quality.
Last edited by strangenesfreak on Sun Nov 18, 2007 4:41 pm, edited 1 time in total.

tepples
Posts: 21946
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sun Nov 18, 2007 4:41 pm

strangenesfreak wrote:I dunno about actual NES hardware (I cannot test it myself yet), but it does work on the latest versions of Nestopia and Nintendulator. Is that enough accuracy, or do you really need the NES itself?
I too tried it on Nestopia and Nintendulator. But I seem to remember a long time ago when someone said that if nobody runs it on an NES, I might as well develop for DirectX instead.

User avatar
dXtr
Posts: 375
Joined: Tue Sep 21, 2004 12:11 am
Location: Karlshamn (Sweden)

Post by dXtr » Sun Nov 18, 2007 5:57 pm

Works fine* on my PAL NES using a PowerPak.

* Different pitch or what it is called = sounds like Nintendulator in PAL mode :)
Sorry for misspellings, I'm from Sweden ^^

tepples
Posts: 21946
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sun Nov 18, 2007 7:47 pm

Thanks. That's good enough for now. But what else can I do with this engine?

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

Post by Bregalad » Tue Dec 18, 2007 12:42 pm

Hey ! I'm now playing with the PCM channel (manual $4011 mode) and I don't feel like starting a new thread for this.
Since using plain 8-bit PCM samples is pure waste (especially since the LSB is ignored) and because the ROM capacity of the NES is small, I did it in 4 bit DPCM (the wav can decrease by down to 8 or increase up to 7 each step). However, I got terrible results. A lot of time this slew rate is just too much for the sampling rate I use, and this sound terrible, almost as bad as 1-bit hardware DPCM.
I'd like to implement some kind of other compression such as Adaptative DPCM or something like this. I don't know much about ADPCM, but would 2 bits for the number of shits and 6 bits for 2 samples (3 bit per samples) all packed in a byte do the trick ? Would I end up with better quality than before ? I'm not sure how to encode for this format efficiently either.

tepples
Posts: 21946
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Tue Dec 18, 2007 8:10 pm

Bregalad wrote:Since using plain 8-bit PCM samples is pure waste (especially since the LSB is ignored) and because the ROM capacity of the NES is small, I did it in 4 bit DPCM (the wav can decrease by down to 8 or increase up to 7 each step). However, I got terrible results. A lot of time this slew rate is just too much for the sampling rate I use, and this sound terrible, almost as bad as 1-bit hardware DPCM.
To avoid slope overload on "loud" portions, use bigger steps in loud portions. You can do this either by varying the step scale (like IMA ADPCM and SNES ADPCM do) or just by using nonlinear stepsizes:
{-64, -49, -36, -25, -16, -9, -4, -1, 0, 1, 4, 9, 16, 25, 36, 49}
I'd like to implement some kind of other compression such as Adaptative DPCM or something like this. I don't know much about ADPCM, but would 2 bits for the number of shits and 6 bits for 2 samples (3 bit per samples) all packed in a byte do the trick ?
You might want to spread the number of shifts over a longer block of samples. SNES ADPCM encodes each block of 16 samples in 9 bytes: 4 bits for step scale (your "number of shits"), 2 bits for prediction method (in effect, a choice between literal and delta interpretation of the sample values), 2 bits for other shit related to looping, followed by 4*16 bits for sample values. IMA ADPCM (used on Nintendo DS and several other systems) uses a running count based on the delta values to predict the step scale.

But my question remains: What kind of game design would use a lot of audio that pauses the game?

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

Post by Bregalad » Wed Dec 19, 2007 9:43 am

I'll try to get the parabolic step size thing in, I'll tell if it gives better results. That does seem like a good idea, however I don't know if it will sound a lot better or just slightly better.

You might want to spread the number of shifts over a longer block of samples. SNES ADPCM encodes each block of 16 samples in 9 bytes: 4 bits for step scale (your "number of shits"), 2 bits for prediction method (in effect, a choice between literal and delta interpretation of the sample values), 2 bits for other shit related to looping, followed by 4*16 bits for sample values.
Yeah, I know how SNES ADPCM works, it's fairly good however not all bits are used and there is those different filters that require advanced maths that definitely cannot be done on the NES (in real time). Buffering the samples is out of question due to low RAM (even with SRAM). And I'd like to avoid to have a whole byte as a "header" of a block, as it's hard to make full good use to the whole 8 bits of the header.
IMA ADPCM (used on Nintendo DS and several other systems) uses a running count based on the delta values to predict the step scale.
Sounds very interesting. Could the NES perform a such process in real-time ? If so where can I have more details about that thing ?
But my question remains: What kind of game design would use a lot of audio that pauses the game?
RPG, tactical-RPG or anything that doesn't require the player to interact with the game in real time.

EDIT : Parabolic DPCM seems to do much better results ! Thank you tepples ! While not sounding absolutely perfect, my stuff now sounds decent. I wonder if there is any way of making sounding even better, but I doubt.

Bananmos
Posts: 496
Joined: Wed Mar 09, 2005 9:08 am
Contact:

Post by Bananmos » Tue Dec 25, 2007 8:07 am

Tepples:
Nice work. How about trying a 2-bit ADPCM codec as well? Even if most 2-bit codecs I've heard have a noticable degrade in sound quality, it might still be acceptable if you need lots of speech samples. =)

Then again, for speech-specific compression, there are better codecs to use. But most of them are very CPU-demanding IIRC.

mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Post by mic_ » Fri Dec 28, 2007 1:58 am

Then again, for speech-specific compression, there are better codecs to use. But most of them are very CPU-demanding IIRC.
Yeah, try to do an AMR decoder. It might be doable if the NES' CPU was running at, say, 30-40 MHz..
Sounds very interesting. Could the NES perform a such process in real-time ? If so where can I have more details about that thing ?
http://nocash.emubase.de/gbatek.htm#dssound
http://wiki.multimedia.cx/index.php?title=IMA_ADPCM

User avatar
B00daW
Posts: 584
Joined: Thu Jan 03, 2008 1:48 pm

Practical application.

Post by B00daW » Thu Jan 03, 2008 2:10 pm

As I am an infamously useless troll of sorts, I will just make a request for the betterment of the sk3n3 and get the codemonkeys to do the hard work.

1.) jsr and thefox, please hack up a way to apply this into the NES/Fami tracking experience in FamiTracker, NerdTracker, and PornoTracker plz plz, Scandi-niggahs.

2.) Please rewrite the NSF specs, kev so that we may be lovins some good ADPCM vocodings and/or sexamples.

+,

Tidings of lub, j'all.

--

teh b00, crusader for j00z.

NotTheCommonDose
Posts: 523
Joined: Thu Jun 29, 2006 7:44 pm
Location: lolz!
Contact:

Re: Practical application.

Post by NotTheCommonDose » Thu Jan 03, 2008 4:59 pm

B00daW wrote:As I am an infamously useless troll of sorts, I will just make a request for the betterment of the sk3n3 and get the codemonkeys to do the hard work.

1.) jsr and thefox, please hack up a way to apply this into the NES/Fami tracking experience in FamiTracker, NerdTracker, and PornoTracker plz plz, Scandi-niggahs.

2.) Please rewrite the NSF specs, kev so that we may be lovins some good ADPCM vocodings and/or sexamples.

+,

Tidings of lub, j'all.

--

teh b00, crusader for j00z.
Are drunk or something? :?:

Post Reply