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);
* toAudioBuffer Function :- *
var toAudioBuffer = function toAudioBuffer(data) {
> // Calculate total number of samples
> var samples = data.length / format.channels;
> // Determine exactly when packet CAN play
>
>
> * var packetTime = context.currentTime; // context will be Null in
> IE if (nextPacketTime < packetTime) nextPacketTime =
> packetTime;*
> // Get audio buffer for specified format
> *var audioBuffer = context.createBuffer(format.channels, samples,
> format.rate);*
> // Convert each channel
> for (var channel = 0; channel < format.channels; channel++) {
> * var audioData = audioBuffer.getChannelData(channel); **//
> context will be Null in IE*
> // Fill audio buffer with data for channel
> var offset = channel;
> for (var i = 0; i < samples; i++) {
> audioData[i] = data[offset] / maxSampleValue;
> offset += format.channels;
> }
> }
> return audioBuffer;
> };
It requires *context.currentTime* but in case of IE context is NULL and
nothing will be returned in *packetTime*.
*2. Can I skip pushAudioPacket () and shiftAudioPacket() methods as well ?
( I don't know what these methods are trying to do.. )*
*3. Do I need nextPacketTime as well ? *
( source.start(nextPacketTime); )
*4. Can I directly call toAudioBuffer function passing ArrayBuffer of 6048
byte and skip the packetTime and context.createBuffer ?*
*5. If I use Int16Array over ArrayBuffer It view the data in integers of 16
byte and if use the following for loop:-*
* data = new Int16Array(ArrayBuffer)); // View of 16 byte integers
length = 3024 *
for (var channel = 0; channel < format.channels; channel++) {
> var audioData [ samples.length] = 0;
> // Fill audio buffer with data for channel
> var offset = channel;
> for (var i = 0; i < samples; i++) {
> audioData[i] = data[offset] / maxSampleValue;
> offset += format.channels;
> }
> }
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 ?
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
On Fri, Nov 10, 2017 at 12:08 AM, Frode Langelo <[email protected]> wrote:
> Hello Amarjeet,
>
> Take a look at AudioPlayer.toAudioBuffer ; it should be doing what you
> are trying to accomplish.
>
> Regards,
> Frode
>
> On Thu, Nov 9, 2017 at 4:52 AM, Amarjeet Singh <[email protected]>
> wrote:
> > Hi Team,
> >
> >
> > I am trying to add support for Audio in IE as a Flashback. I am getting
> > data as a Arraybuffer (6048 ) from the audio stream.
> > I have written below action script which is as follows:-
> >
> >
> >> package
> >> {
> >> import flash.display.*;
> >> import flash.events.*;
> >> import flash.external.*;
> >> import flash.media.*;
> >> public class guacamole extends Sprite
> >> {
> >> public var sound:Sound = null;
> >> public var buffer:Array;
> >> public function guacamole()
> >> {
> >> this.buffer = [];
> >> super();
> >> ExternalInterface.addCallback("write", this.write);
> >> }
> >> public function write(param1:String) : void
> >> {
> >> if(!this.sound)
> >> {
> >> this.sound = new Sound();
> >> this.sound.addEventListener(SampleDataEvent.SAMPLE_DATA,
> >> this.soundGenerator);
> >> this.sound.play();
> >> }
> >> this.buffer = this.buffer.concat(param1.split(" "));
> >> }
> >> public function soundGenerator(param1:SampleDataEvent) : void
> >> {
> >> var _loc_1:int = 0;
> >> var _loc_2:Function = param1.data.writeFloat;
> >> if(this.buffer.length < 4096)
> >> {
> >> _loc_1 = 0;
> >> while(_loc_1 < 4096)
> >> {
> >> _loc_2(0.00);
> >> _loc_1++;
> >> }
> >> return;
> >> }
> >> var _loc_3:Number = Math.min(this.buffer.length, 16384);
> >> _loc_1 = 0;
> >> while(_loc_1 < _loc_3)
> >> {
> >> _loc_2(this.buffer[_loc_1]);
> >> _loc_1++;
> >> }
> >> this.buffer = this.buffer.slice(_loc_3, this.buffer.length);
> >> }
> >> }
> >> }
> >
> >
> >
> > Now I need to convert the stream of ArrayBuffer into a string of Integer
> > samples or Floating samples.
> > I need help to do that as I tried a lot but it's not working.
> > Please help me out to resolve the above issue or guide me to convert the
> > Raw PCM 16 bit Audio data to Floating samples between -1 to 1 .
> >
> >
> >
> > Thanks and Regards,
> > Amarjeet Singh
>