我想使用图书馆 NReplayGain 要计算一个MP3文件的replaygayn,然后使用 TagLibSharp 库(带有非官方的开源重放支持修改)来编写 ID3v2 replaygain标记到文件中。

那么,这应该是使用NReplayGain lib计算sampleset的replaygain的伪代码,正如他们网站所示: 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(所有的帧加入?))

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

我需要一个完整的代码示例,说明如何使用 NAudio lib或任何其他类型的lib可以做到这一点。

我之所以要求一个完整的代码,是因为我知道我不能自己做,我已经在鹦鹉螺图书馆之前接触了一些其他的东西,对我来说是非常困难的,似乎图书馆只是为音频大师程序员和音频大师编写的,没有任何容易的事情。

有帮助吗?

解决方案

从来没有听说过一个"sampleset"。但正如我到目前为止所看到的,一个sampleset只是包含左右通道的样本。你可以用 CSCore,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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top