Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 使用CSCore库获取MP3文件样本数据和信息_.net_Vb.net_Audio_Naudio_Cscore - Fatal编程技术网

.net 使用CSCore库获取MP3文件样本数据和信息

.net 使用CSCore库获取MP3文件样本数据和信息,.net,vb.net,audio,naudio,cscore,.net,Vb.net,Audio,Naudio,Cscore,我想使用库NReplayGain计算MP3文件的replaygayn,然后使用TagLibSharp库(带有非官方开源replaygain支持修改)将ID3v2replaygain标记写入该文件 这应该是使用NReplayGain库计算样本集replaygain的伪代码,正如他们网站所示: (…但是如果我需要说实话,我不知道什么是样本集(所有的框架都连接了?) 在尝试计算样本集的ReplayGain之前,我需要获得传递到上述代码所需的必要数据,因此我需要获得MP3文件的采样器,样本集,左样本和右

我想使用库
NReplayGain
计算MP3文件的replaygayn,然后使用
TagLibSharp
库(带有非官方开源replaygain支持修改)将
ID3v2
replaygain标记写入该文件

这应该是使用NReplayGain库计算样本集replaygain的伪代码,正如他们网站所示:

(…但是如果我需要说实话,我不知道什么是样本集(所有的框架都连接了?)

在尝试计算样本集的ReplayGain之前,我需要获得传递到上述代码所需的必要数据,因此我需要获得MP3文件的
采样器
样本集
左样本
右样本

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

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

从来没有听说过“样本集”。但正如我目前所看到的,样本集只包含左通道和右通道的样本。 您可以使用以非常简单的方式访问轨迹的所有样本:

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
从未听说过“样本集”。但正如我目前所看到的,样本集只包含左通道和右通道的样本。 您可以使用以非常简单的方式访问轨迹的所有样本:

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
这项工作:

  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
这项工作:

  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