实现功能:录音的同时转换成mp3格式
用到的例子和插件:SpeakHere + lame
// ____________________________________________________________________________________
// AudioQueue callback function, called when an input buffers has been filled.
void AQRecorder::MyInputBufferHandler( void * inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp * inStartTime,
UInt32 inNumPackets,
const AudioStreamPacketDescription* inPacketDesc)
{
AQRecorder *aqr = (AQRecorder *)inUserData;
try {
if (inNumPackets > 0) {
// write packets to file
XThrowIfError(AudioFileWritePackets(aqr->mRecordFile, FALSE, inBuffer->mAudioDataByteSize,
inPacketDesc, aqr->mRecordPacket, &inNumPackets, inBuffer->mAudioData),
"AudioFileWritePackets failed");
if (!aqr->mp3Encoder) {
aqr->mp3Encoder = init];
}
aqr->mp3Encoder.setToStopped = NO;
;
aqr->mRecordPacket += inNumPackets;
}
// if we're not stopping, re-enqueue the buffe so that it gets filled again
if (aqr->IsRunning())
XThrowIfError(AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL), "AudioQueueEnqueueBuffer failed");
} catch (CAXException e) {
char buf;
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
}
}
```
lame代码
- (void)encodePcmData:(void *)pcmBuffer withDataSize:(UInt32)pcmDataSize {
if (!_setToStopped) {
;
int mp3DataSize = pcmDataSize * 4;
unsigned char mp3Buffer;
int encodedBytes = lame_encode_buffer( lame, pcmBuffer, pcmBuffer, pcmDataSize, mp3Buffer, mp3DataSize );
;
}
}
- (void) writeToFile
{
if (_setToStopped) {
lame_close(lame);
}
NSString *path = ;
NSString *filePath = ;
;
}
```