tarsosdsp基音偏移工件

5hcedyr0  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(321)

我正在读一本书 .wav 文件,改变音高,并将其写入android上的新文件。我正在使用tarsosdsp来完成这项工作,但在新文件中不断出现奇怪的工件。我尝试使用一个正弦波,这是文件的前几个示例的比较方式:

橙色为原始文件,蓝色由tarsos生成。据我所知,与github上的音高偏移示例相比,我没有处理差异。这是我的代码:

File directory = getDir("audio", Context.MODE_PRIVATE);

    String source = directory.toString() + "/" + "in.wav";
    String target = directory.toString() + "/" + "out.wav";
    RandomAccessFile outputFile = null;
    try {
        outputFile = new RandomAccessFile(target, "rw");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    int bitsPerSample = 16;
    int channels = 1;
    TarsosDSPAudioFormat format = new TarsosDSPAudioFormat(SAMPLE_RATE, bitsPerSample, channels, true, false);

    double cents = 0;
    double factor = centToFactor(cents);
    RateTransposer rateTransposer = new RateTransposer(factor);
    WaveformSimilarityBasedOverlapAdd wsola = new WaveformSimilarityBasedOverlapAdd(WaveformSimilarityBasedOverlapAdd.Parameters.musicDefaults(factor, SAMPLE_RATE));

    WriterProcessor writer = new WriterProcessor(format, outputFile);

    try {
        InputStream inputStream = new FileInputStream(source);
        UniversalAudioInputStream uStream = new UniversalAudioInputStream(inputStream, format);
        print(wsola.getInputBufferSize());
        print(wsola.getOverlap());

        AudioDispatcher audioDispatcher = new AudioDispatcher(uStream, wsola.getInputBufferSize(), wsola.getOverlap());
        wsola.setDispatcher(audioDispatcher);
        audioDispatcher.addAudioProcessor(wsola);
        audioDispatcher.addAudioProcessor(rateTransposer);
        audioDispatcher.addAudioProcessor(writer);
        audioDispatcher.run();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

以及:

public static double centToFactor(double cents) {
    return 1 / Math.pow(Math.E, cents * Math.log(2) / 1200 / Math.log(Math.E));
}

我试着对声音进行实际的改变( cents != 0 )但结果并没有好转。我是否必须希望这些人工制品在真实的录音中总是不被注意到,还是有办法解决这个问题?我对音频处理非常陌生。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题