SetChannelRate, what's the valid pitch values?

Monkey Forums/Monkey Programming/SetChannelRate, what's the valid pitch values?

Erik(Posted 2014) [#1]
In XNA the valid pitch goes from -1 (down one octave) to 1 (up one)

Can this mojo code really be right? It crashes with rate 0, log(0).

	
public virtual int SetRate( int channel,float rate ){
  gxtkChannel chan=channels[channel];
		
  if( chan.state!=0 ) chan.inst.Pitch=(float)( Math.Log(rate)/Math.Log(2) );
		
  chan.rate=rate;
  return 0;
}


More importantly, what values are supposed to be allowed to SetChannelRate in mojo? And perhaps it would be a good idea to clamp them on the receiving side so they don't crash.


Nobuyuki(Posted 2014) [#2]
it's a float value where 1 represents the native playback speed, so theoretically the allowed playback rates are probably from around 1/48000 to 65536 for a 16-bit 48khz sample. In reality, the target system places the limits on playback rate. On Android, the rate limit is 0.5 - 2.0 (defined in SoundPool docs). OpenAL specifies AL_PITCH to be the same range on GLFW, however this isn't necessarily true -- On ios, I've read a post on another forum saying that you can set pretty wild ranges. But generally speaking you shouldn't assume pitch rates to be available beyond 0.5-2.0f from normal, and on certain platforms you can't guarantee it will exist at all (html5).


Erik(Posted 2014) [#3]
Great, thanks