private static float[][] ConvertWaveDataToFloatArrays(byte[] waveData, ref WavePCMParser.WaveInfo waveInfo) { float[][] channelsData = new float[waveInfo.channels][]; for (int i = 0; i < waveInfo.channels; ++i) { channelsData[i] = new float[waveInfo.samplesCount]; } int index = waveInfo.sectionData.indexDataStart; int sampleIndex = 0; while (index < waveInfo.sectionData.size) { foreach (var channelData in channelsData) { // конвертирование в диапазоне от 1f до -1f channelData[sampleIndex] = BitConverter.ToInt16(waveData, index) / _normalizeCoeff; index += waveInfo.bytesPerSample; } sampleIndex++; } return(channelsData); }
public static void ConvertFloatArraysToWaveData(byte[] waveData, ref WavePCMParser.WaveInfo waveInfo, float[][] channelsData) { int index = waveInfo.sectionData.indexDataStart; for (int i = 0; i < waveInfo.samplesCount; ++i) { foreach (var channelData in channelsData) { short s = (short)(channelData[i] * _normalizeCoeff); waveData[index++] = (byte)(s & 0xFF); waveData[index++] = (byte)(s >> 8); } } }