简体   繁体   English

处理16位样本音频

[英]Processing 16bit sample audio

Right now i have an audio file (2 Channels, 44.1kHz Sample Rate, 16bit Sample size, WAV) I would like to pass it into this method but i am not sure of any way to convert the WAV file to a byte array. 现在,我有一个音频文件(2通道,44.1kHz采样率,16位采样大小,WAV),我想将其传递给此方法,但是我不确定将WAV文件转换为字节数组的任何方法。

 /// <summary>
    /// Process 16 bit sample
    /// </summary>
    /// <param name="wave"></param>
    public void Process(ref byte[] wave)
    {
        _waveLeft = new double[wave.Length / 4];
        _waveRight = new double[wave.Length / 4];

        if (_isTest == false)
        {
            // Split out channels from sample
            int h = 0;
            for (int i = 0; i < wave.Length; i += 4)
            {
                _waveLeft[h] = (double)BitConverter.ToInt16(wave, i);
                _waveRight[h] = (double)BitConverter.ToInt16(wave, i + 2);
                h++;
            }
        }
        else
        {
            // Generate artificial sample for testing
            _signalGenerator = new SignalGenerator();
            _signalGenerator.SetWaveform("Sine");
            _signalGenerator.SetSamplingRate(44100);
            _signalGenerator.SetSamples(16384);
            _signalGenerator.SetFrequency(5000);
            _signalGenerator.SetAmplitude(32768);
            _waveLeft = _signalGenerator.GenerateSignal();
            _waveRight = _signalGenerator.GenerateSignal();
        }

        // Generate frequency domain data in decibels
        _fftLeft = FourierTransform.FFTDb(ref _waveLeft);
        _fftRight = FourierTransform.FFTDb(ref _waveRight);
    }

Edit Hi sorry for the confusion. 编辑您好,抱歉造成混乱。 I'm currently new to audio signalling so my explanation of what I might like to get is wrong. 我目前是音频信号的新手,所以我对我可能想要得到的解释是错误的。 For this method to work correctly, i believe i need to pass in the byte array of the data chunk in the wav file only. 为了使此方法正常工作,我相信我只需要在wav文件中传递数据块的字节数组。 The end result would be to apply fft on it as shown in the code and transform it to a spectrogram. 最终结果将是如代码所示在其上应用fft并将其转换为频谱图。 Thanks. 谢谢。

you need: 你需要:

using System.IO;

and this code to get the byte array 和这段代码来获取字节数组

byte[] data = File.ReadAllBytes(PathToFile);

where PathToFile is the Location (as String) of the .wav file. 其中PathToFile.wav文件的位置(作为字符串)。

Edit: 编辑:

Right now i have an audio file (2 Channels, 44.1kHz Sample Rate, 16bit Sample size, WAV) I would like to pass it into this method but i am not sure of any way to convert the WAV file to a byte array. 现在,我有一个音频文件(2通道,44.1kHz采样率,16位采样大小,WAV),我想将其传递给此方法,但是我不确定将WAV文件转换为字节数组的任何方法。

He asks for a function to get the byte array from the .wav file he didn't say anything about getting the specific part of the byte array that contains the data of the music. 他要求一个从.wav文件中获取字节数组的函数,他没有说要获取包含音乐数据的字节数组的特定部分。 So Downvoting a correct answer is.. 因此,否决正确答案是..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM