如何修改 SpeakHere 示例应用程序以在 iPhone 上以单声道格式录制?

发布于 2024-10-21 07:25:16 字数 1087 浏览 2 评论 0原文

我是 iPhone 新手。您能帮我修改 Apple 的 SpeakHere 应用程序,使其以单声道格式录制吗?我应该为 mChannelsPerFrame 设置什么以及还应该设置什么?

我已经更改了一些部分以使用 LinearPCM WAVE 格式进行记录。

这里是speakHere的链接

以下是我认为他们允许我改变的内容,但我不太理解声音:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青柠芒果 2024-10-28 07:25:16

在 iPhone 上,您只能以单声道录制。

在 SpeakHere 示例中,您无需执行任何操作即可进行设置。它是自动完成的。例如在 AQRecorder::SetupAudioFormat 中:

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

获取支持的硬件输入通道并将其设置为 ivar。在其他地方,缓冲区大小的计算将考虑这一点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文