Reputation: 12712
I am using the following to extract the byte info from a sound object - however if I go back to the same sound object and run this again, The byteArray has no bytes available.
var data:ByteArray = new ByteArray;
sound.extract(data,sound.length*44.1);
data.position = 0;
return data;
Is this the correct behavior? Is there not a way to do this multiple times on the same sound object? Or am I doing something wrong here. Any help appreciated - thanks
Upvotes: 0
Views: 1264
Reputation: 6563
If you pass in 0 for the startPosition
you can always get at the data:
sound.extract(data,sound.length*44.1, 0);
There seems to be a ByteArray internal to the Sound whose position is being set by the startPosition
parameter. -1 seems to just tell it to read from wherever that ByteArray position is currently at. When you've already read out all the data, passing -1 gets nothing from the ByteArray bc its position is at the end.
Upvotes: 0
Reputation: 11
sound.extract(data,sound.length*44.1, -1);
Maybe you need to set the startPosition with -1. Otherwise when you go back to the same sound and call extract again, the startpositon will not be -1.
Upvotes: 1
Reputation:
What you may be looking to do is listen for a SampleDataEvent on a sound object. Inside the SampleDataEvent you can extract the block of sound captured by that event, modify it, and then write it back to the sound stream live and uninterrupted.
An introduction to using this event:
http://blog.andreanaya.com/2009/04/dynamic-sound-part-1/
Note that you can access the binary sound data out of this event using the SampleDataEvent.thedata.
Upvotes: 0
Reputation: 12847
I believe the whole point of 'extract' is to actually remove the byte info from the Sound object; from the api:
This method is designed to be used when you are working with dynamically generated audio, using a function you assign to the sampleData event for a different Sound object. That is, you can use this method to extract sound data from a Sound object. Then you can write the data to the byte array that another Sound object is using to stream dynamic audio.
I'm not too sure what you're trying to accomplish, but if you want to keep your Sound object in tact, you might want to look into just writing it to the ByteArray yourself:
var ba:ByteArray = new ByteArray();
ba.writeObject(sound);
ba.position = 0;
return ba;
Upvotes: 0