On Fri, Nov 10, 2017 at 3:12 AM, Amarjeet Singh <[email protected]> wrote:
> Hi Frode,
>
> I really appreciate the response and guidance you provided. It helped me to
> look for more options and created lot of questions in my mind as well.
>
> *1. How can I skip these  lines in toAudioBuffer ?*
>
>   var packetTime = context.currentTime;
>         if (nextPacketTime < packetTime)
>             nextPacketTime = packetTime;
>   var audioBuffer = context.createBuffer(format.channels, samples,
> format.rate);
>
> It requires *context.currentTime* but in case of IE context is NULL and
> nothing will be returned in *packetTime*.

For the purpose of only converting to a float array, you could try
something like:

var toAudioBuffer = function toAudioBuffer(data) {

    // Calculate total number of samples
    var samples = data.length / format.channels;

    // Create the Float output audio buffer
    var audioBuffer = new window.Float32Array(data.length);

    // Convert each channel
    for (var channel = 0; channel < format.channels; channel++) {

        // Fill audio buffer with data for channel
        var offset = channel;
        for (var i = 0; i < samples; i++) {
            audioData[offset] = data[offset] / maxSampleValue;
            offset += format.channels;
        }

    }

    return audioBuffer;

};


> *2. Can I skip pushAudioPacket () and shiftAudioPacket() methods as well ?
> ( I don't know what these methods are trying to do.. )*

These methods are used to buffer, synchronize audio packet playback,
and rearrange (and split) the packets so that the packets are cut
where the audio volume is at a low point to reduce the amount of
audible clipping between packets played back. Fot the purpose of
getting your prototype working I wouldn't worry about this for now;
but when you are going for a complete implementation you should look
at creating a new AudioPlayer implementation for your Flash audio
player.

> *3. Do I need nextPacketTime as well ? *
>
>      ( source.start(nextPacketTime); )

Not yet (see above comment)

> *4. Can I directly call  toAudioBuffer function passing ArrayBuffer of 6048
> byte  and skip the packetTime and context.createBuffer ?*

The toAudioBuffer function expects a SampleArray which in this case is
an Int16Array. You could do toAudioBuffer(new
SampleArray(arrayBuffer));
If you look at the implementation of RawAudioPlayer, it receives the
raw audio data in playReceivedAudio from ArrayBufferReader.ondata.

> *5. If I use Int16Array over ArrayBuffer It view the data in integers of 16
> byte and if use the following for loop:
> [snip]
> It will push the data for left channel together and right channel together
> into an array.
> Now, Can I pass this data to my Flash Action Script in a string to play at
> 44.1Khz with 2 channels ?

You would need to pass the underlying ArrayBuffer to your Flash
script. I am not sure if it can consume it directly though.

var floatBuffer = toAudioBuffer(new SampleArray(arrayBuffer));
sendToFlash(floatBuffer.buffer);


> I would be very grateful if you look into the above queries and give some
> guidance so that I can move forward.
>
> Thanks and Regards,
> Amarjeet Singh
>

Reply via email to