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

故事扮演 提交于 2019-12-24 17:15:12

问题


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;
        }
    }

回答1:


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.



来源:https://stackoverflow.com/questions/5255846/how-can-i-modify-the-speakhere-sample-app-to-record-in-mono-format-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!