3

When synthesising sound using the SAMPLE_DATA event of the Sound class, the Flash documentation recommends writing out as many samples as possoible up to 8192. On my system the sound cuts out unless I write at least 4192 samples each event. That's a full tenth of a second, which is going to be user-noticeable.

I may have the option of buffering things up ahead of time, but this is a major annoyance for my application. Is there any way of getting lower latency audio output?

  • I've used [SampleDataEvent](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/SampleDataEvent.html) w/the microphone, but didn't realize it was so cool for generating sounds. The comment in the docs about calculating the latency is interesting, have you tried using this many samples: `((SampleDataEvent.position/44.1) - SoundChannel.position)` . Or perhaps you need to make the amount user selectable (cop out from the docs :) – Sunil D. Apr 07 '12 at 06:14
  • I think that latency may be distinct from the delay introduced by the minimum buffer size. – user1300292 Apr 07 '12 at 07:03

1 Answers1

2

Unfortunately, SAMPLE_DATA is the main means of synthesizing audio, and it has varying performance and latency between platforms. For the smallest latency, the best you can do is provide as few samples as possible (2048) in the SampleDataEvent.

There is also Sound.loadPCMFromByteArray, which was added in Flash Player 11 and allows you to load samples directly into a normal Sound object. Although this wouldn't be helpful for real-time, dynamic audio synthesis, it allows you to pre-generate the sound and play it back whenever you need it.

Mike Welsh
  • 1,549
  • 1
  • 9
  • 14