/// <summary> /// Get the channel data converted to PCM-16 from mono audio data /// </summary> /// <param name="data">Data to convert</param> /// <param name="nBlocks">Number of blocks</param> /// <param name="blockLen">Block length</param> /// <param name="lastBlockLen">Last block length</param> /// <param name="waveType">Wavetype of the audio data (compression)</param> /// <returns>Channel data</returns> static byte[] MonoChannel(byte[] data, uint nBlocks, uint blockLen, uint lastBlockLen, int waveType) { List <byte> resultado = new List <byte>(); List <byte> datos = new List <byte>(); datos.AddRange(data); byte[] blockData; for (int i = 0; i < nBlocks - 1; i++) { blockData = new byte[(int)blockLen]; datos.CopyTo(i * (int)blockLen, blockData, 0, (int)blockLen); if (waveType == 2) { resultado.AddRange(Compression_ADPCM.Decompress(blockData, BitConverter.ToInt16(blockData, 0), BitConverter.ToInt16(blockData, 2))); } else if (waveType == 1) { resultado.AddRange(blockData); } else if (waveType == 0) { resultado.AddRange(PCM.PCM8SignedToPCM16(blockData)); } } blockData = new byte[(int)lastBlockLen]; datos.CopyTo((int)(nBlocks - 1) * (int)blockLen, blockData, 0, (int)lastBlockLen); if (waveType == 2) { if (blockData.Length < 4) // Archivos sin sonido { resultado.AddRange(blockData); return(resultado.ToArray()); } resultado.AddRange(Compression_ADPCM.Decompress(blockData, BitConverter.ToInt16(blockData, 0), BitConverter.ToInt16(blockData, 2))); } else if (waveType == 1) { resultado.AddRange(blockData); } else if (waveType == 0) { resultado.AddRange(PCM.PCM8SignedToPCM16(blockData)); } return(resultado.ToArray()); }
/// <summary> /// Get one channels converted to PCM-16 from the audio data /// </summary> /// <param name="data">Audio data with two channels</param> /// <param name="nBlocks">Numbers of blocks in the audio data</param> /// <param name="blockLen">Block length in the audio data</param> /// <param name="lastBlockLen">Length of the last block</param> /// <param name="leftChannel">If true, return the left channel, else return the right channel</param> /// <param name="waveType">The wavetype of the audio data (compression)</param> /// <returns>Data of the channel</returns> static byte[] DivideChannels(byte[] data, uint nBlocks, uint blockLen, uint lastBlockLen, bool leftChannel, int waveType) { List <byte> resultado = new List <byte>(); List <byte> datos = new List <byte>(); datos.AddRange(data); int j = (leftChannel) ? 0 : (int)blockLen; byte[] blockData; for (int i = 0; i < nBlocks - 1; i++) { blockData = new byte[(int)blockLen]; datos.CopyTo(i * (int)blockLen * 2 + j, blockData, 0, (int)blockLen); if (waveType == 2) { resultado.AddRange(Compression_ADPCM.Decompress(blockData, BitConverter.ToInt16(blockData, 0), BitConverter.ToInt16(blockData, 2))); } else if (waveType == 1) { resultado.AddRange(blockData); } else if (waveType == 0) { resultado.AddRange(PCM.PCM8SignedToPCM16(blockData)); } } blockData = new byte[(int)lastBlockLen]; j = (leftChannel) ? 0 : (int)lastBlockLen; datos.CopyTo((int)(nBlocks - 1) * (int)blockLen * 2 + j, blockData, 0, (int)lastBlockLen); if (waveType == 2) { resultado.AddRange(Compression_ADPCM.Decompress(blockData, BitConverter.ToInt16(blockData, 0), BitConverter.ToInt16(blockData, 2))); } else if (waveType == 1) { resultado.AddRange(blockData); } else if (waveType == 0) { resultado.AddRange(PCM.PCM8SignedToPCM16(blockData)); } return(resultado.ToArray()); }
public static sWAV ConvertToWAV(sSWAV swav, bool loop) { sWAV wav = new sWAV(); if (swav.data.info.nWaveType == 0) // 8 Bits per sample, PCM-8 { swav.data.data = PCM.PCM8SignedToPCM16(swav.data.data); if (loop) { Byte[] data = new Byte[(int)swav.data.info.nNonLoopLen]; Array.Copy(swav.data.data, swav.data.info.nLoopOffset, data, 0, data.Length); swav.data.data = data; } wav = WAV.Create_WAV(1, swav.data.info.nSampleRate, 16, swav.data.data); } else if (swav.data.info.nWaveType == 1) // 16 Bits per sample, PCM-16 { if (loop) // NO TESTED { Byte[] data = new Byte[(int)swav.data.info.nNonLoopLen]; Array.Copy(swav.data.data, swav.data.info.nLoopOffset, data, 0, data.Length); swav.data.data = data; } wav = WAV.Create_WAV(1, swav.data.info.nSampleRate, 16, swav.data.data); } else if (swav.data.info.nWaveType >= 2) // 4 Bits per sample, IMA-ADPCM { swav.data.data = Compression_ADPCM.Decompress( swav.data.data, BitConverter.ToUInt16(swav.data.data, 0), BitConverter.ToUInt16(swav.data.data, 2)); if (loop) { Byte[] data = new Byte[swav.data.data.Length - ((int)swav.data.info.nLoopOffset * 2)]; Array.Copy(swav.data.data, swav.data.info.nLoopOffset * 2, data, 0, data.Length); swav.data.data = data; } wav = WAV.Create_WAV(1, swav.data.info.nSampleRate, 16, swav.data.data); } return(wav); }