开发者

How can I modify the SpeakHere sample app to record in mono format on iPhone?

I am new to iPhone. Could you please help me to modify the SpeakHere app from Apple to record in mono format. What should I have to set for mChannelsPerFrame and what else should I set?

I already change some part for record on linearPCM WAVE format.

Here is link to speakHere.

Here is what I think they allow me to change but I don't quite understand on sound:

void ChangeNumberChannels(UInt32 nChannels, bool interleaved)
                // alter an existing format
    {
        Assert(IsPCM(), "ChangeNumberChannels only works for PCM formats");
        UInt32 wordSize = SampleWordSize(); // get this before changing ANYTHING
        if (wordSize == 0)
            wordSize = (mBitsPerChannel + 7) / 8;
 开发者_开发知识库       mChannelsPerFrame = nChannels;
        mFramesPerPacket = 1;
        if (interleaved) {
            mBytesPerPacket = mBytesPerFrame = nChannels * wordSize;
            mFormatFlags &= ~kAudioFormatFlagIsNonInterleaved;
        } else {
            mBytesPerPacket = mBytesPerFrame = wordSize;
            mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
        }
    }


On iPhone you will only be able to record in mono.

You shouldn't need to do anything to set this up in the SpeakHere example. It's done automatically. For example in AQRecorder::SetupAudioFormat:

size = sizeof(mRecordFormat.mChannelsPerFrame);
XThrowIfError(AudioSessionGetProperty(  kAudioSessionProperty_CurrentHardwareInputNumberChannels, 
                &size, 
                &mRecordFormat.mChannelsPerFrame), "couldn't get input channel count");

That gets the supported hardware input channels and sets it as an ivar. Elsewhere, the buffer size calculations will factor that in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜