How can I modify the SpeakHere sample app to recor

2019-07-29 22:04发布

问题:

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.