I am doing the following in my code:
_sound = new Sound();
_sound.addEventListener( SampleDataEvent.SAMPLE_DATA, handlePlaybackSampleData );
_soundChannel = _sound.play();
Usually this should result in the Sound calling the handle… function when it wants to play so that I can insert my own generated ByteArray for the sound.
But it doesn’t even call that function and sometimes (!!!) crashes instead with an:
Error #2004: One of the parameters is invalid.
I have no idea why this is happening. In all examples it works exactly like that.
It also doesn’t make too much sense as all parameters in play() are optional anyway.
Before that happens, I am recording the microphone input to a buffer, and then want to playback what I have recorded, which is what all this is for.
Edit:
Here is the function:
public function handlePlaybackSampleData(p_sampleEvent:SampleDataEvent) :void
{
// Read data until either MAX_SAMPLES or all available samples are reached.
var i:int = 0;
var data :Number = 0;
while( i < 8192 )
{
if( _lastRecord.bytesAvailable )
{
data = _lastRecord.readFloat();
p_sampleEvent.data.writeFloat(data);
p_sampleEvent.data.writeFloat(data);
i++;
continue;
}
else
{
break;
}
}
}
To have this question get an “official answer”, here is what happened:
The sample rate was a problem, as you can see in a different question. Solving that also somehow solved this problem.
Unfortunately, I can’t really explain how. Maybe it was just a slightly f*cked up compilation and restarting everything fixed it. In any case, it is gone now.