TarsosDSP 音高分析傻瓜式

问题描述 投票:0回答:1

我正在开发一个分析声音文件音高的程序。我遇到了一个非常好的 API,称为“TarsosDSP”,它提供了各种音高分析。然而,我在设置它时遇到了很多麻烦。有人可以向我展示一些关于如何使用此 API(尤其是 PitchProcessor 类)的快速指南吗?一些代码片段将非常感激,因为我在声音分析方面确实很新。

谢谢

编辑:我在 http://husk.eecs.berkeley.edu/courses/cs160-sp14/index.php/Sound_Programming 找到了一些文档,其中有一些示例代码展示了如何设置 PitchProcessor,...

int bufferReadResult = mRecorder.read(mBuffer, 0, mBufferSize);
// (note: this is NOT android.media.AudioFormat)
be.hogent.tarsos.dsp.AudioFormat mTarsosFormat = new be.hogent.tarsos.dsp.AudioFormat(SAMPLE_RATE, 16, 1, true, false);
AudioEvent audioEvent = new AudioEvent(mTarsosFormat, bufferReadResult);
audioEvent.setFloatBufferWithByteBuffer(mBuffer);
pitchProcessor.process(audioEvent);

…我很迷茫,mBuffer 和 mBufferSize 到底是什么?我如何找到这些值?我在哪里输入我的音频文件?

java audio javasound tarsosdsp
1个回答
10
投票

TarsosDSP 框架中音频的基本流程如下:读取来自音频文件或麦克风的传入音频流并将其切成例如帧。 1024 个样本。每个帧都会通过一个管道进行修改或分析(例如音调分析)。

在 TarsosDSP 中,

AudioDispatcher
负责将音频切成帧。它还将音频帧包装到
AudioEvent
对象中。这个
AudioEvent
对象通过
AudioProcessors
链发送。

因此,在您引用的代码中,mBuffer 是音频帧,mBufferSize 是样本中缓冲区的大小。您可以自己选择缓冲区大小,但对于音高检测,2048 个样本是合理的。

对于音调检测,您可以使用 TarsosDSP 库执行类似的操作:

   PitchDetectionHandler handler = new PitchDetectionHandler() {
        @Override
        public void handlePitch(PitchDetectionResult pitchDetectionResult,
                AudioEvent audioEvent) {
            System.out.println(audioEvent.getTimeStamp() + " " pitchDetectionResult.getPitch());
        }
    };
    AudioDispatcher adp = AudioDispatcherFactory.fromDefaultMicrophone(2048, 0);
    adp.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.YIN, 44100, 2048, handler));
    adp.run();

在此代码中,首先创建一个处理程序,该处理程序仅打印检测到的音高。

AudioDispatcher
连接到默认麦克风,缓冲区大小为 2048。
AudioDispatcher
中添加了检测音高的音频处理器。处理程序也在那里使用。

最后一行开始该过程。

© www.soinside.com 2019 - 2024. All rights reserved.