LGDE
asked on
Adjusting Microphone bitrate changes playback speed
I was wondering if anyone could help me with the issue I have.
I am recording audio from microphone and later playing it back.
Now if microphone.rate (bitrate) is 44 (Khz) then playback is fine but as soon as I am lowering bitrate it speeds up.
I am assuming it is because of playback still using 44. But there is no property in Sound object to change it like in Microphone object. I think I need to change the way I am accessing ByteArray that stores sound.
Low bitrate is needed for space efficiency thus 44.1 Khz cannot be really accepted.
Would love someone to help me figure it out.
Key parts of the code below.
I am recording audio from microphone and later playing it back.
Now if microphone.rate (bitrate) is 44 (Khz) then playback is fine but as soon as I am lowering bitrate it speeds up.
I am assuming it is because of playback still using 44. But there is no property in Sound object to change it like in Microphone object. I think I need to change the way I am accessing ByteArray that stores sound.
Low bitrate is needed for space efficiency thus 44.1 Khz cannot be really accepted.
Would love someone to help me figure it out.
Key parts of the code below.
protected var soundRecording:ByteArray = new ByteArray();
protected var soundOutput:Sound;
microphone = Microphone.getMicrophone(comboMicList.selectedIndex);
microphone.rate = 11;
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
private function gotMicData(event:SampleDataEvent):void {
soundRecording.writeBytes(event.data);
}
protected function playbackData():void {
soundRecording.position = 0;
soundOutput = new Sound();
soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, playSound);
soundOutput.play();
}
private function playSound(soundOutput:SampleDataEvent):void {
if (soundRecording.bytesAvailable <= 0)
return;
for (var i:int = 0; i < 8192; i++) { // no. of samples
if (soundRecording.bytesAvailable > 0)
soundOutput.data.writeFloat(soundRecording.readFloat());
}
ASKER
Sorry AreDubya but I tried and it does not work (tried replacing "i" in second "for" with "j" as well)
I cannot do work with more than 2*8192 samples in this function
(first for 8192, second can be maximum 2, setting it to more than 2: 2,4,8, .... makes the playback silent[error])
I cannot do work with more than 2*8192 samples in this function
(first for 8192, second can be maximum 2, setting it to more than 2: 2,4,8, .... makes the playback silent[error])
LGDE,
I thought that might be too good to be true.... I will think more on this. I had a similar problem, but needed to go the other way (speed up), so that was easy. Very interested to see how this works out.
AreDubya
I thought that might be too good to be true.... I will think more on this. I had a similar problem, but needed to go the other way (speed up), so that was easy. Very interested to see how this works out.
AreDubya
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nice one. I need to make time to get more into this...
AreDubya
AreDubya
Would it be possible to run a loop and play each sample four times?
AreDubya
Open in new window