Note that there are some explanatory texts on larger screens.

plurals
  1. POLow-latency audio streaming in Flash
    primarykey
    data
    text
    <p>Suppose there is a live WAV stream that can be reached at a certain URL, and we need to stream it with as little latency as possible. Using HTML5 <code>&lt;audio&gt;</code> for this task is a no-go, because browsers attempt to pre-buffer several seconds of the stream, and the latency goes up accordingly. That's the reason behind using Flash for this task. However, due to my inexperience with this technology, I only managed to get occasional clicks and white noise. What's wrong in the code below? Thanks.</p> <pre><code>var soundBuffer: ByteArray = new ByteArray(); var soundStream: URLStream = new URLStream(); soundStream.addEventListener(ProgressEvent.PROGRESS, readSound); soundStream.load(new URLRequest(WAV_FILE_URL)); var sound = new Sound(); sound.addEventListener(SampleDataEvent.SAMPLE_DATA,playSound); sound.play(); function readSound(event:ProgressEvent):void { soundStream.readBytes(soundBuffer, 0, soundStream.bytesAvailable); } function playSound(event:SampleDataEvent):void { /* The docs say that if we send too few samples, Sound will consider it an EOF */ var samples:int = (soundBuffer.length - soundBuffer.position) / 4 var toadd:int = 4096 - samples; try { for (var c: int=0; c &lt; samples; c++) { var n:Number = soundBuffer.readFloat(); event.data.writeFloat(n); event.data.writeFloat(n); } } catch(e:Error) { ExternalInterface.call("errorReport", e.message); } for (var d: int = 0; d &lt; toadd; d++) { event.data.writeFloat(0); event.data.writeFloat(0); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload