vlider / Mic-recording-minimal-example

This is example of retrieving PCM data from microphone and converting to mp3
26 stars 8 forks source link

Sampling Rate and Frame Length #1

Open gburlet opened 7 years ago

gburlet commented 7 years ago

Hello,

I came across your git repo link in your stackoverflow post and think there's an error regarding sampling rates in the parameter set up.

When setting the input sampling rate of the LAME encoder, the sampling rate output by AVAudioEngine is divided by two. This effectively yields the Nyquist rate, but that's not what LAME is expecting. If you were intending to downsample the signal, you should really decimate the signal by applying a low-pass filter at the Nyquist rate using lame_set_lowpassfreq(lame, sampleRate/2) before downsampling. I'm not sure if that was your intent in the code, however, and if so it should be documented with a little comment above that line.

Also why is buffer.frameLength divided by two in the tap? Doesn't this send only half the audio samples for mp3 decoding?

Thanks for the code sample!

vlider commented 7 years ago

Hello @gburlet Thanks for rising this issue. I wrote this sample project just to demonstrate mic recording, with minimal functionality. Of course lame can be set up differently, but to be honest - I'm not really expert in it. I found such configuration enough for demonstration, but I would love to see how it can be improved. If you could issue pull request with changes needed for lame codec setup - that would be great!

Regards,