1,295
edits
Line 136: | Line 136: | ||
attribute Function onprocessstream; | attribute Function onprocessstream; | ||
attribute float streamRewindMax; | attribute float streamRewindMax; | ||
void setAudioFormat(long sampleRate, short channels); | |||
}; | }; | ||
'onprocessstream' stores the callback function to be called whenever stream data needs to be processed. | |||
interface StreamEvent { | interface StreamEvent { | ||
Line 143: | Line 146: | ||
attribute long audioSampleRate; // e.g. 44100 | attribute long audioSampleRate; // e.g. 44100 | ||
attribute short | attribute short audioChannels; // Mapping per Vorbis specification | ||
attribute | attribute Float32Array audioInputSamples[]; | ||
void writeAudio( | void writeAudio(Float32Array data); | ||
}; | }; | ||
'inputParams' provides access to structured clones of the latest parameters set for each input stream. | 'inputParams' provides access to structured clones of the latest parameters set for each input stream. | ||
'audioSampleRate' and ' | 'audioSampleRate' and 'audioChannels' represent the format of the input and output samples. The sample buffers for all input streams are automatically converted to a common format by the UA. By default the UA will choose a format based on the format of the input streams, typically the highest-fidelity format (to avoid lossy conversion). If there are no inputs, the UA will choose 44.1KHz stereo. The format is not allowed to vary across event handlers; the first time onprocessstream is fired, the format will be fixed. If 'setAudioFormat' is called before the first event handler fires, that format will override the UA's default choice. | ||
'audioInputs' gives access to the audio samples for each input stream. The length of each sample buffer will be a multiple of 'audioChannels'. The samples are floats ranging from -1 to 1. The lengths of the sample buffers will be equal. Streams with no audio produce a buffer containing silence. | |||
'writeAudio' writes audio data to the stream output. If 'writeAudio' is not called before the event handler returns, the inputs are automatically mixed and written to the output. The format of the output is the same as the inputs; the 'data' array length must be a multiple of | 'writeAudio' writes audio data to the stream output. If 'writeAudio' is not called before the event handler returns, the inputs are automatically mixed and written to the output. The format of the output is the same as the inputs; the 'data' array length must be a multiple of audioChannels. 'writeAudio' can be called more than once during an event handler; the data will be appended to the output stream. | ||
There is no requirement that the amount of data output match the input buffer length. A filter with a delay will output less data than the size of the input buffer, at least during the first event; the UA will compensate by trying to buffer up more input data and firing the event again to get more output. A synthesizer with no inputs can output as much data as it wants; the UA will buffer data and fire events as necessary. Filters that misbehave, e.g. by continuously writing zero-length buffers, will cause the stream to block. | There is no requirement that the amount of data output match the input buffer length. A filter with a delay will output less data than the size of the input buffer, at least during the first event; the UA will compensate by trying to buffer up more input data and firing the event again to get more output. A synthesizer with no inputs can output as much data as it wants; the UA will buffer data and fire events as necessary. Filters that misbehave, e.g. by continuously writing zero-length buffers, will cause the stream to block. |
edits