English 中文(简体)
在MacOS X 进行录音
原标题:Audio capture in Mac OS X

我正在开发一个音频捕获申请。 • 如何使用8千赫取样率,利用音像股APIC,以单一芯片捕捉MacOS X的录音?

这是我所尝试的法典。

    Component                   component;
ComponentDescription        description;
OSStatus    err = noErr;
UInt32  param;
AURenderCallbackStruct  callback;

description.componentType = kAudioUnitType_Output;
description.componentSubType = kAudioUnitSubType_HALOutput;
description.componentManufacturer = kAudioUnitManufacturer_Apple;
description.componentFlags = 0;
description.componentFlagsMask = 0;
if(component = FindNextComponent(NULL, &description))
{
    err = OpenAComponent(component, &fAudioUnit);
    if(err != noErr)
    {
        fAudioUnit = NULL;
        return err;
    }
}
param = 1;
err = AudioUnitSetProperty(fAudioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &param, sizeof(UInt32));
if(err == noErr)
{
    param = 0;
    err = AudioUnitSetProperty(fAudioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &param, sizeof(UInt32));
}
param = sizeof(AudioDeviceID);
err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &param, &fInputDeviceID);
if(err != noErr)
{
    fprintf(stderr, "failed to get default input device
");
    return err;
}
err = AudioUnitSetProperty(fAudioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &fInputDeviceID, sizeof(AudioDeviceID));
if(err != noErr)
{
    fprintf(stderr, "failed to set AU input device
");
    return err;
}
callback.inputProc = AudioInputProc; 
callback.inputProcRefCon = NULL;
err = AudioUnitSetProperty(fAudioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &callback, sizeof(AURenderCallbackStruct));
param = sizeof(AudioStreamBasicDescription);
err = AudioUnitGetProperty(fAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &fDeviceFormat, &param);
if(err != noErr)
{
    printf("failed to get input device ASBD
");
    return err;
}
fDeviceFormat.mSampleRate = 8000.0;
fDeviceFormat.mChannelsPerFrame = 1;
fDeviceFormat.mBitsPerChannel = 16;
fDeviceFormat.mFormatID = kAudioFormatLinearPCM;
fDeviceFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
err = AudioUnitSetProperty(fAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &fDeviceFormat, sizeof(AudioStreamBasicDescription));
if(err != noErr)
{
    printf( "failed to set input device ASBD= %4.4s
",(char *)&err);
    if(err == kAudioUnitErr_FormatNotSupported)
    {
        printf("kAudioUnitErr_FormatNotSupported
");
    }
    return err;
}
err = AudioUnitGetProperty(fAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &fDeviceFormat, &param);
if(err != noErr)
{
    printf( "failed to get input device ASBD
");
    return err;
}   
param = sizeof(UInt32);
err = AudioUnitGetProperty(fAudioUnit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Global, 0, &fAudioSamples, &param);
if(err != noErr)
{
    fprintf(stderr, "failed to get audio sample size
");
    return err;
}
err = AudioUnitInitialize(fAudioUnit);
if(err != noErr)
{
    fprintf(stderr, "failed to initialize AU
");
    return err;
}

在此,我无法将取样率和每样样本的比照率从32个改为16个。 请帮助我这样做。

增资 在这方面。

问题回答

采用辅助格式,将其改为8000千赫兹,

www.un.org/Depts/DGACM/index_spanish.htm 在上述代码上,s将失效。

您需要使用<条码>AudioConvert New创建录音转换器,并使用<条码>将你的缓冲转换成理想的格式。

I had a similar problem, I had to modify sand box permissions. Check if your application is sand boxed, you have access to the microphone.





相关问题
Playing a Sound With Monotouch

No matter what I try (build -> content, NSUrl, filename) I get a null exception : file not found when I try to play a .caf sound file in monotouch. //var path = NSBundle.MainBundle.PathForResource("...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

Play sound in iPhone web app with Javascript?

I m currently creating an iPhone web application for piano chords, and I wanted to add an option that would let the user press a Play button and play the selected chord. However, I m not sure how to ...