Hi Frode, I tried what you said in the above mail thread.
console.log(this.flashElement); *T**he response I get in the console ( Please refer the attachment ):-* Couldn't create AudioContext:ReferenceError: 'AudioContext' is undefined, > falling back to flash player <object width="8" height="8" id="guacamole-flashelement-1" > data="guacamole.swf" type="application/x-shockwave-flash" > style="visibility: visible;"><param name="allowScriptAccess" > value="always"></object> Error : *SCRIPT438: Object doesn't support property or method 'write'* Regards, Amarjeet On Sat, Nov 11, 2017 at 4:30 AM, Frode Langelo <[email protected]> wrote: > Hi Amarjeet, > > I am assuming the line this.flashElement.write(...) causes this: > Error : *SCRIPT438: Object doesn't support property or method 'write'* > > Unfortunately I am not a Flash expert.. I'd check some of the Flash > related forums for JavaScript/Flash integration. > How are you loading your Flash element? I would start looking there.. > the culprit appears to be JavaScript not able to access the 'write' > method exposed via ExternalInterface.addCallback in the ActionScript. > Perhaps Flash was not yet ready when you call the write method? What > does console.log(this.flashElement); say, just before calling > this.flashElement.write(...) ? > > Kind regards. > Frode > > On Fri, Nov 10, 2017 at 12:03 PM, Amarjeet Singh <[email protected]> > wrote: > >> > >> varfloatBuffer = toAudioBuffer(new SampleArray(arrayBuffer)); > >> sendToFlash(floatBuffer.buffer); > > > > > > It doesn't worked. I am getting the error in the console log while > calling > > flash.write method > > > > Error : *SCRIPT438: Object doesn't support property or method 'write'* > > > > While I am trying the below code it is playing the sound with no errors:- > > > > var sampledata = []; > >> var freq = 440; > >> var interval = null; > >> var guacamole= new Guacamole({'swf': 'guacamole.swf'}); > >> > >> function start() { > >> interval = setInterval(function() { > >> var n = Math.ceil(freq / 100) * 2; > >> for (var i=0; i < n; i++) { > >> guacamole.write(sampledata); // calls > Guacamole.write > >> } > >> }, 10); > >> } > > > > function createSound() { > >> var samples = 44100 / freq; > >> sampledata = Array(Math.round(samples)); > >> for (var i=0; i < sampledata.length; i++) { > >> sampledata[i] = Math.sin(2*Math.PI * (i / > >> sampledata.length)); > >> } > >> } > > > > createSound();start(); > > > > > > > > > >> Guacamole.write: function(samples) { > >> var out = new Array(samples.length); > >> for (var i = 0;i < samples.length; i++) { > >> out[i] = this.floatToIntSample(samples[i]); > >> } > >> as = out.join(' '); > >> this.flashElement.write(as); // this write calls the > >> flash.write > >> }, > > > > floatToIntSample: function(value) { > >> return Math.floor(value * 32768); // from -1..1 to -32767..32768 > >> range > >> } > > > > > > swf is embedded in HTML document .. > > > > > > > > Please give any suggestions ... What I am missing here ? > > I have data coming in audio stream and I have swf to play the sound but > > something with the flow of PCM data to swf is missing. > > > > > > On Fri, Nov 10, 2017 at 10:50 PM, Frode Langelo <[email protected]> > wrote: > > > >> 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 > >> > > >> >
