我正在使用音频单元对音乐录制应用进行编码,我遇到了一些问题,让我生成的M4A文件播放除了不那么棒的嗡嗡声之外的任何其他内容.我已经使用这些SO 资源 作为 参考,我已经尝试了一切来排除故障.
我有一个AUGraph2节点:一个多通道混音器和一个远程I/O. 我的调音台上有两个输入回调:一个用于从麦克风输入输入,另一个用于从音频文件中提取.混频器输出连接到I/O单元上输出范围的输入元件.这可以实现同步I/O.
为了捕获输出,我添加了一个回调和两个方法:
回调
static OSStatus recordAndSaveCallback (void * inRefCon,
AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList * ioData)
{
Mixer* THIS = (__bridge Mixer*)inRefCon;
AudioBufferList bufferList;
OSStatus status;
status = AudioUnitRender(THIS.ioUnit,
ioActionFlags,
inTimeStamp,
0,
inNumberFrames,
&bufferList);
SInt16 samples[inNumberFrames]; // A large enough size to not have to worry about buffer overrun
memset (&samples, 0, sizeof (samples));
bufferList.mNumberBuffers = 1;
bufferList.mBuffers[0].mData = samples;
bufferList.mBuffers[0].mNumberChannels = 1;
bufferList.mBuffers[0].mDataByteSize = …Run Code Online (Sandbox Code Playgroud) 我有一个程序,使用连接到远程IO音频单元的AUSampler生成声音.AUSampler由在定时循环中触发的预先记录的事件控制.我想将结果声音写入文件.
关于在IO单元的渲染回调中写入文件还有一些其他问题:
但这些都涉及实时编写数据.有没有办法离线渲染文件所需的时间比播放文件少?
我写了一个循环来使用扩展音频文件服务将我的应用程序生成的pcm音频数据编码到aac.编码同步地在后台线程中进行,而不是实时进行.
对于ios 4和i,ipad 1和iphone 3gs/4的编码完美无缺.然而,对于双核设备(iphone 4s,ipad 2),第三次调用ExtAudioFileWrite会使编码线程崩溃,没有堆栈跟踪,也没有错误代码.
这是有问题的代码:
数据格式
AudioStreamBasicDescription AUCanonicalASBD(Float64 sampleRate,
UInt32 channel){
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = sampleRate;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical;
audioFormat.mChannelsPerFrame = channel;
audioFormat.mBytesPerPacket = sizeof(AudioUnitSampleType);
audioFormat.mBytesPerFrame = sizeof(AudioUnitSampleType);
audioFormat.mFramesPerPacket = 1;
audioFormat.mBitsPerChannel = 8 * sizeof(AudioUnitSampleType);
audioFormat.mReserved = 0;
return audioFormat;
}
AudioStreamBasicDescription MixdownAAC(void){
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = 44100.0;
audioFormat.mFormatID = kAudioFormatMPEG4AAC;
audioFormat.mFormatFlags = kMPEG4Object_AAC_Main;
audioFormat.mChannelsPerFrame = 2;
audioFormat.mBytesPerPacket = 0;
audioFormat.mBytesPerFrame = 0;
audioFormat.mFramesPerPacket = 1024;
audioFormat.mBitsPerChannel = 0;
audioFormat.mReserved = 0;
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写(应该是)一个简单的应用程序,它在AUGraph中按顺序包含一堆音频单元,然后将输出写入文件.我使用AUGraphAddRenderNotify添加了回调.这是我的回调函数:
OSStatus MyAURenderCallback(void *inRefCon,
AudioUnitRenderActionFlags *actionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
if (*actionFlags & kAudioUnitRenderAction_PostRender) {
ExtAudioFileRef outputFile = (ExtAudioFileRef)inRefCon;
ExtAudioFileWriteAsync(outputFile, inNumberFrames, ioData);
}
}
Run Code Online (Sandbox Code Playgroud)
这种作品.该文件是可播放的,我可以听到我录制的内容,但是有大量静电使其几乎听不见.
有人知道这有什么问题吗?或者有没有人知道将AUGraph输出记录到文件的更好方法?
谢谢您的帮助.
I need to stream audio from the mic to a http server.
These recording settings are what I need:
NSDictionary *audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: kAudioFormatULaw],AVFormatIDKey,
[NSNumber numberWithFloat:8000.0],AVSampleRateKey,//was 44100.0
[NSData dataWithBytes: &acl length: sizeof( AudioChannelLayout ) ], AVChannelLayoutKey,
[NSNumber numberWithInt:1],AVNumberOfChannelsKey,
[NSNumber numberWithInt:64000],AVEncoderBitRateKey,
nil];
Run Code Online (Sandbox Code Playgroud)
API im coding to states:
Send a continuous stream of audio to the currently viewed camera. Audio needs to be encoded at G711 mu-law at 64 kbit/s for transfer to the Axis camera at the bedside. …