Re: Setting a sample rate in the web audio API

Hi Grant,

With this line:
audioSource.buffer = audioContextHandle.createBuffer(1, 1,
settings[14]); //Create
a zero'd input buffer for the input to be valid.


You're creating a buffer whose length is only 1 sample-frame (the second
argument) which is pretty short!  And from what I understand, you're
ignoring the "audioSource" input.  The sample-rate *is* taken into account
in the "audioSource", it's just that you're ignoring what it's giving you
and generating your own output stream.  The sample-rate of the AudioContext
itself is fixed and is usually going to be the sample-rate of the audio
hardware (such as 44.1KHz).

Chris

On Fri, Feb 11, 2011 at 12:41 PM, Grant Galitz <grantgalitz@gmail.com>wrote:

> Hey, you probably already know my JS GameBoy Color emulator project
> https://github.com/grantgalitz/GameBoy-Online
> The thing is, I'm wondering why the web audio API refuses to allow me to
> set my own sample rate (I want 70khz). Right now I have to set the sample
> rate to that already found in the API itself:
>  audioSource = audioContextHandle.createBufferSource(); //We need to
> create a false input to get the chain started.
>  audioSource.loop = false; //Keep this alive forever (Event handler will
> know when to ouput.)
>  settings[14] = audioContextHandle.sampleRate;
>  audioSource.buffer = audioContextHandle.createBuffer(1, 1, settings[14]); //Create
> a zero'd input buffer for the input to be valid.
>  audioNode = audioContextHandle.createJavaScriptNode(settings[18], 1, 2); //Create
> 2 outputs and ignore the input buffer (Just copy buffer 1 over if mono)
>  audioNode.onaudioprocess = audioOutputEvent; //Connect the audio
> processing event to a handling function so we can manipulate output
>  audioSource.connect(audioNode); //Send and chain the input to the audio
> manipulation.
>  audioNode.connect(audioContextHandle.destination); //Send and chain the
> output of the audio manipulation to the system audio output.
>  audioSource.noteOn(0);
>
> settings[14] being the sample rate 70000.
> I need to do this to get it to work:
> settings[14] = audioContextHandle.sampleRate;
> Which effectively forces me to use the API's arbitrary sample rate instead
> of one I want to use.
>
>

Received on Saturday, 12 February 2011 23:21:22 UTC