PCM->Hex conversion question

Topics on software tools like TileStudio, comments on documentation and tutorials (or the lack of) should go here.
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

PCM->Hex conversion question

Post by D3thAdd3r »

Looked around the forums and tried google, but I am not finding any method to convert PCM data to formatted hex. The sound crash course mentions Cool Edit but I've tried a few versions and don't see how this is done. All I'm trying to accomplish is a small PCM drum kit with bass,snare,hat,ride,crash and I figure others might find it useful if it sounds good/is reasonable size. Another question, anyone(Uze?) know a way to play back a song at double speed without resorting to storing 2 different versions in flash?
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: PCM->Hex conversion question

Post by uze6666 »

By formatted Hex I guess you mean an include file. For that a conversion tool is required (ideally generic). Either someone code one in C or you can always use a tool from the GNU toolchain that can convert read only data to some pre-compiled, linkable object ( something like objcopyroda or sometghing like that ).

For the song, there is no way to do it with the current code, but it can be done relatively easily. A MIDI song would need to be generated with the PPQN at 240 instead of 120 and the MIDI replayed could then be updated to skip every other tick.

Btw I'm in vacation right now so I'll probably... be.... very...slow... replying...because, considering I'm in Dominican republic , I'm already lucky my hotel has some wifi connection...ok back to my Daiquiri now! :lol:

-Uze
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: PCM->Hex conversion question

Post by D3thAdd3r »

I was mostly wondering how you converted the kernels default waves into hex, I think that's all I'll need. Have fun on vacation!
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

PCM2Hex Utility

Post by D3thAdd3r »

Alright I put together a little tool that should be of use to people wanting to try out PCM in their project. It will take an 8 bit RAW unsigned mono PCM file and save it to a formatted array, with optional variable name, ready to copy and paste into your project. Cool Edit and many other programs have this as a save option, you will likely need to convert the samples before saving. The sample rate you choose will directly correspond to how you call it, ie:

TriggerNote(3,1,23,0xff); //this would playback an 8 khz sample correctly

TriggerNote(3,1,0,0xff);//this would play the same sample very slowly(giving you more bang for your byte if you were to convert the sound to be high pitched in the audio editor and play it back slow).



There's a bit to talk about on that and how you could use it well, I will add a little blurb about using this in my sound effects tutorial. Run the program with no parameters for an example. Source is included, if you notice any stupid bugs let me know. Might be useful to have in with the standard Uzebox tools?
Attachments
Pcm2Hex.zip
(6.43 KiB) Downloaded 880 times
User avatar
paul
Posts: 457
Joined: Sat May 02, 2009 8:41 am
Location: Brisbane, Australia

Re: PCM->Hex conversion question

Post by paul »

Hey I can try this out for frogger sfx. Anything to make it easier (you know how much I hate doing sfx ;) ).
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: PCM->Hex conversion question

Post by uze6666 »

Great tool, the way I used to convert sound was using the Java tool I made, one of the function is to convert PCM data if I recall. I was thinking why not make it a generic 8 bit BIN to INC type of tool? Could convert any type of raw data, sound, graphics, or whatever.

-Uze
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: PCM->Hex conversion question

Post by D3thAdd3r »

I was thinking why not make it a generic 8 bit BIN to INC type of tool?
Yeah the name PCM2Hex is a bit too specific now that I think of it. It assumes everything is unsigned char and spits it out into whatever file/array name setup for inc, so you could use it for any data. Raw has no header, so I guess this generic easy approach could have other uses too. Hereby renamed Bin2Hex :)

I always feel the need to provide more questions than answers so...when I call TriggerNote on a PCM patch what does the note mean exactly? It definitely makes it play back slower with a lower note, but I guess I'd like to figure a little formula for how high of note to play it back versus what frequency the PCM is sampled at. Right now it seems note 23 works perfectly with PCM originally encoded at 8khz. Is it feasible to sample PCM data at a faster rate(compress it time wise, giving a higher pitch less length), but play it back slower thereby minimizing flash usage at the sake of quality or am I wrong? Probably exotic past real usefulness.

Hey I can try this out for frogger sfx.
That will be a very cool game to have on Uzebox, can't wait to see that. I realized when I was trying to make a good drum set, although it sounds great, PCM takes killer space! I could see it working for frogger since there's not that many and/or short sfx. What video mode are you thinking for it?
User avatar
paul
Posts: 457
Joined: Sat May 02, 2009 8:41 am
Location: Brisbane, Australia

Re: PCM->Hex conversion question

Post by paul »

What video mode are you thinking for it?
I think mode 2 was made for Frogger. So far I have gone with the C64 graphics, but maybe I'll change to arcade.
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: PCM->Hex conversion question

Post by uze6666 »

when I call TriggerNote on a PCM patch what does the note mean exactly? It definitely makes it play back slower with a lower note, but I guess I'd like to figure a little formula for how high of note to play it back versus what frequency the PCM is sampled at. Right now it seems note 23 works perfectly with PCM originally encoded at 8khz. Is it feasible to sample PCM data at a faster rate(compress it time wise, giving a higher pitch less length), but play it back slower thereby minimizing flash usage at the sake of quality or am I wrong? Probably exotic past real usefulness.
For PCM samples, note 35 (MIDI B-3) means 1:1 playback at 15734 Hz (look at steptable.inc). So you can indeed record it faster then play it at a lower note to get the proper speed. I did that for a simple drumkit for a demo song I never finished. Since we are on the subject I never realy liked the way PCM was implemented since it cuts away the noise channel. Instead I would have prefered to have it as an extra channel, like the NES PCM channel. Naturally that would take more CPU but it could somewhat be reduced by limiting the functionality like no loop, volume and pitch control just like the NES. Perhaps it could be fixed 8Khz samples? or 4Khz? I'm open to suggestions.

-Uze
User avatar
D3thAdd3r
Posts: 3222
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: PCM->Hex conversion question

Post by D3thAdd3r »

I do like the idea of having both noise and PCM, personally if no loop/volume would work I'd vote for that. I like the pitch control, it is handy in the sense you get to choose your own sampling rate for an individual sound based on what it needs. But I think it's likely to confuse and complicate things for people messing around with the sound and playback timing like that, the extra time and steps involved(add "calculator" to tool?), probably 4 or 8 khz fixed would sound good for most anything especially if it saves cycles. Don't know how good 4k/sec sounds yet, but if it's decent you could probably have a full drum set for well, ~4k.
So far I have gone with the C64 graphics, but maybe I'll change to arcade.
Either graphics will be great, though you've quite a streak going with arcade style. Mode 2 seems pretty fitting if you make the cars 1 sprite or cut back the demands some other way. If cars could never be right behind another and same offsets you could cheat with mode3+ram tile tricks, but that sounds like a messy and hard approach.
Post Reply