We help IT Professionals succeed at work.
Get Started

Adjusting Microphone bitrate changes playback speed

LGDE
LGDE asked
on
756 Views
Last Modified: 2013-11-11
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.

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());
}

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE