correct playback rate (pitch) for sound samples ?

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

correct playback rate (pitch) for sound samples ?

Post by diki »

concerning this thread, i was wondering how to determine the correct (as in original) playback speed / pitch for an imported sound sample? i approximated as best as i could, and assuming i did everything else right (44.1khz mono raw file, set the corresponding properties), i can't see any obvious relationship. is there an easy / accurate way to do this?
User avatar
Kjell
Posts: 1882
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:!:

Good question, I would like to know this as well! It's somewhere around 148.65 .. Unfortunately, even when you get it right, there is a big difference in playback quality between the raw file and what it sounds like in ZGE.

Here is a 16-bit Mono raw sample + a ZGE exe playing it .. significant difference :?

K
User avatar
VilleK
Site Admin
Posts: 2277
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

It is tricky unfortunately because the playback system uses midi-notenumbers to calculate pitch:

NoteNr = (PlaySound.NoteNr-69.0) + Sound.BaseNoteNr;
Frequency = 440.0 * Power(2, NoteNr/12);

In the calculations above you want to find the NoteNr to use in the PlaySound-component that makes Frequency equal the sample rate of your imported sample.
User avatar
VilleK
Site Admin
Posts: 2277
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Kjell, the internal playback speed of ZGE audio (both synthesized and sampled) is only 22050hz. That's the reason the playback of your 44kz sample does not sound as good as the original. I choose 22khz rate because I wasn't sure if my playback code was fast enough to manage the higher rate. But it can be changed easily, just change a constant and recompile, so perhaps I can test and see if we should increase the rate for better playback quality.
User avatar
Kjell
Posts: 1882
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hej Ville,

Ah, that's good to hear :) What about a drop-down property on App that let's you select the playback rate ( default being the current 22khz )? Not sure whether the audio library you're using supports changing that after the app has been initialized / loaded though ..

By the way, the correct Note is 148.76557586169102803354847486147 8)

K
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

see above for 44100 Hz; it's 12 less (136.76557586169102803354847486147) for 22050 Hz. </nitpick> ;)
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

a pull down would indeed be nice for tha playback rate,. as depending on the project and sounds used, higher quality could work well,. and low-fi woulds always be an option,.
iterationGAMES.com
User avatar
VilleK
Site Admin
Posts: 2277
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

That makes sense because: 12 midi notes = one octave = double/half the frequency.

At the moment the audio rate can only be changed by recompiling ZGE, so making it configurable requires a bit of work. I will start by defaulting to 44khz in next beta so we can test if we encounter any problems with the higher rate. Then we can make it configurable later. Maybe add a dropdown for it in the options-dialog for the end-user.
Post Reply