有关录制,修改和iphone播放音频的另一个问题 [英] another question about recording, modifying and playing audio on iphone

查看:231
本文介绍了有关录制,修改和iphone播放音频的另一个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:在我以前正是因为我记录的言论和OpenAL的的移调和回放解释如下,AVRecorder结束。它的结果很不错:)不过,他详细的解答,我只是没有时间/绞尽脑汁来实现我获得@my脂肪骆驼的答案要点:D

In the end I used exactly as I explained below, AVRecorder for recording the speech and openAL for the pitch shift and playback. It worked out quite well :) But for his detailed answer that I just didn't have the time/brains to implement I awarded @my fat llama the answer points :D

我得到关于录音的问题,修改和播放音频。我问过一个类似的问题(<一个href=\"http://stackoverflow.com/questions/4393415/iphone-record-modify-pitch-and-play-back-audio-in-real-time\">iphone记录,修改间距和播放实时音频),但我现在有更多的信息,并可以做一些进一步的建议那样。

I got a question regarding recording, modifying and playing back audio. I asked a similar question before ( iphone record, modify pitch and play back audio in real time ) but I now have more information and could do with some further advice please.

所以,首先,这是什么,我试图做(在一个单独的线程主线程):

So firstly this is what I am trying to do (on a separate thread to the main thread):


  1. 监控iphone麦克风

  2. 检查声音比一定体积更大

  3. 如果高于阈值开始记录例如
  4. 人开始说话

  5. 继续录制,直到音量低于阈值例如人停止交谈

  6. 修改录制的声音的音高。

  7. 播放的声音

我想用AVRecorder监视和记录的声音,很好的教程在这里:的 http://mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/

I was thinking of using the AVRecorder to monitor and record the sound, good tutorial here: http://mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/

和我想用的OpenAL修改记录音频的音调。

and I was thinking of using openAL to modify the pitch of the recorded audio.

所以我的问题是,我是正确的思维在点列表上面,我失去的东西,或有更好的/更简单的方法来做到这一点。我能避免混合音频库,只需使用AVFoundation来改变音调呢?

So my question is, is my thinking correct in the list of points above, am I missing something or is there a better/easier way to do it. Can I avoid mixing audio libraries and just use AVFoundation to change the pitch too?

任何意见非常感谢。

推荐答案

您可以使用AVRecorder或类似的实时IO音频单元低的东西。

You can either use AVRecorder or something lower like the realtime IO audio unit.

量的概念是pretty模糊。你可能想看看计算的峰值和有效值,并了解如何将RMS值在给定的时间整合(比如300毫秒这是何等的VU表使用)之间的差异。

The concept of 'volume' is pretty vague. You might want to look at the difference between calculating peak and RMS values, and understanding how to integrate an RMS value over a given time (say 300ms which is what a VU meter uses).

基本上你总结的值的所有方块。你会采取平方根并转换为dBFS的10 * log10f(SQRT(SUM / num_samples)),但你可以做,如果没有的sqrt在一个步骤20 * log10f(SUM / num_samples)。

Basically you sum all the squares of the values. You would take the square root and convert to dBFS with 10 * log10f(sqrt(sum/num_samples)), but you can do that without the sqrt in one step with 20 * log10f(sum/num_samples).

您需要做大量的积分时间和阈值调整,以获得它的行为您想要的方式。

You'll need to do a lot of adjusting of integration times and thresholds to get it to behave the way you want.

有关变调,我想用的OpenAL做的伎俩,其背后的技术被称为带限插值 - 的https://ccrma.stanford.edu/~jos/resample/Theory_Ideal_Bandlimited_Interpolation.html

For pitch shifting, I think OpenAL with do the trick, the technique behind it is called band limited interpolation - https://ccrma.stanford.edu/~jos/resample/Theory_Ideal_Bandlimited_Interpolation.html

此示例显示了有效值计算作为一个正在运行的平均值。循环缓冲器保持正方形的历史,并且消除了需要总结每个操作的平方。我没有运行它,把它当作伪code;)

This example shows a rms calculation as a running average. The circular buffer maintains a history of squares, and eliminates the need to sum the squares every operation. I haven't run it so treat it as pseudo code ;)

例如:

class VUMeter
{

protected:

    // samples per second
    float _sampleRate;

    // the integration time in seconds (vu meter is 300ms)
    float _integrationTime;

    // these maintain a circular buffer which contains
    // the 'squares' of the audio samples

    int _integrationBufferLength;
    float *_integrationBuffer;
    float *_integrationBufferEnd;
    float *_cursor;

    // this is a sort of accumulator to make a running
    // average more efficient

    float _sum;

public:

    VUMeter()
    : _sampleRate(48000.0f)
    , _integrationTime(0.3f)
    , _sum(0.)
    {
        // create a buffer of values to be integrated
        // e.g 300ms @ 48khz is 14400 samples

        _integrationBufferLength = (int) (_integrationTime * _sampleRate);

        _integrationBuffer = new float[_integrationBufferLength + 1];
        bzero(_integrationBuffer, _integrationBufferLength);

        // set the pointers for our ciruclar buffer

        _integrationBufferEnd = _integrationBuffer + _integrationBufferLength;
        _cursor = _integrationBuffer;

    }

    ~VUMeter()
    {
        delete _integrationBuffer;
    }

    float getRms(float *audio, int samples)
    {
        // process the samples
        // this part accumulates the 'squares'

        for (int i = 0; i < samples; ++i)
        {
            // get the input sample

            float s = audio[i];

            // remove the oldest value from the sum

            _sum -= *_cursor;

            // calculate the square and write it into the buffer

            double square = s * s;
            *_cursor = square;

            // add it to the sum

            _sum += square;

            // increment the buffer cursor and wrap

            ++_cursor;

            if (_cursor == _integrationBufferEnd)
                _cursor = _integrationBuffer;
        }

        // now calculate the 'root mean' value in db

        return 20 * log10f(_sum / _integrationBufferLength);
    }
};

这篇关于有关录制,修改和iphone播放音频的另一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆