0

我想使用库NReplayGain来计算 MP3 文件的 replaygayn,然后使用TagLibSharp库(具有非官方开源 replaygain 支持修改)将ID3v2replaygain 标签写入文件。

好吧,这应该是使用 NReplayGain 库计算样本集重放增益的伪代码,正如他们的网站所示:https ://github.com/karamanolev/NReplayGain

Dim trackGain As New TrackGain(samplerate, samplesize)

For Each sampleSet As SampleSet In track
    trackGain.AnalyzeSamples(sampleSet.leftSamples, sampleSet.rightSamples)
Next

Dim gain As Double = trackGain.GetGain()
Dim peak As Double = trackGain.GetPeak()

(......但如果我需要说实话,我不知道什么是 SampleSet (所有的框架都加入了?))

在尝试计算样本集的 ReplayGain 之前,我需要获取需要传递给上面代码的必要数据,因此我需要获取MP3文件的samplerateSampleSet和。leftSamplesrightSamples

我需要一个完整的代码示例,说明如何使用NAudiolib 或任何其他类型的 lib 来检索这些数据。

我要求完整代码的原因是因为我知道我自己做不到,我在 NAudio 库之前接触过一些其他的东西,对我来说非常困难,似乎该库是为音频大师程序员和音频大师编写的,没有任何简单的。

4

2 回答 2

5

从未听说过“样本集”。但到目前为止,我可以看到,一个样本集只包含左右通道的样本。您可以使用CSCore以一种非常简单的方式访问轨道的所有样本:

Option Strict On

Imports CSCore
Imports CSCore.Codecs

Module Test

    Sub Main()
        Dim source As IWaveSource = CodecFactory.Instance.GetCodec("C:\Temp\test.mp3")
        Dim sampleSource As ISampleSource = source.ToSampleSource()

        Dim sampleBuffer(source.WaveFormat.SampleRate * source.WaveFormat.Channels) As Single
        Dim sampleRate As Integer = source.WaveFormat.SampleRate
        Dim channelCount As Short = source.WaveFormat.Channels
        Dim read As Integer

        Dim leftSamples As New List(Of Single)
        Dim rightSamples As New List(Of Single)

        Do
            'now iterate through the sampleBuffer
            For i = 0 To read Step channelCount
                If channelCount = 1 Then 'mono
                    leftSamples.Add(sampleBuffer(i))
                ElseIf channelCount = 2 Then
                    leftSamples.Add(sampleBuffer(i))
                    rightSamples.Add(sampleBuffer(i + 1))
                Else
                    Throw New NotSupportedException("3 or more channels are not supported.")
                End If
            Next
        Loop While read > 0

        'now you've got all samples in a range of -1 to 1
        'do what ever you need to do with them
    End Sub

End Module
于 2013-11-19T11:50:33.340 回答
0

这有效:

  Sub Main()
    Dim originalWavFile As IWaveSource
    originalWavFile = CodecFactory.Instance.GetCodec("1.mp3")
    Dim bufferSize As Integer = 64000
    Dim bytesBuffer = New Byte(bufferSize) {}
    Dim read As Integer = bufferSize
    While read = bufferSize
        Dim nby = originalWavFile.Length - originalWavFile.Position
        If nby > bufferSize Then
            nby = bufferSize
        End If
        read = originalWavFile.Read(bytesBuffer, 0, nby)
        ' do something with the samples
    End While
    originalWavFile.Dispose()
End Sub
于 2021-03-09T11:52:41.090 回答