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); }
/// <summary> /// Convert a STRM structure to a WAV structure /// </summary> /// <param name="strm">STRM structure to convert</param> /// <param name="loop">If true, the new WAV data will start in the loop offset</param> /// <returns>WAV structure converted</returns> public static sWAV ConvertToWAV(sSTRM strm, bool loop) { sWAV wav = new sWAV(); // Get the audio data if (strm.head.channels == 2) { // Get both channels and convert it to PCM-16 strm.data.leftChannel = DivideChannels(strm.data.data, strm.head.nBlocks, strm.head.blockLen, strm.head.lastBlocklen, true, strm.head.waveType); strm.data.rightChannel = DivideChannels(strm.data.data, strm.head.nBlocks, strm.head.blockLen, strm.head.lastBlocklen, false, strm.head.waveType); Array.Clear(strm.data.data, 0, strm.data.data.Length); if (loop && strm.head.waveType == 0) // 8 bits per sample { strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel, (int)strm.head.loopOffset); } else if (loop && strm.head.waveType == 2) // 4 bits per sample { strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel, (int)strm.head.loopOffset * 2); } else if (loop && strm.head.waveType == 1) // 16 bits per sample (NO TESTED) { strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel, (int)strm.head.loopOffset); } else // No loop { strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel); } } else if (strm.head.channels == 1) { // Get the channel and convert it to PCM-16 strm.data.data = MonoChannel(strm.data.data, strm.head.nBlocks, strm.head.blockLen, strm.head.lastBlocklen, strm.head.waveType); if (strm.head.waveType == 0 && loop) // 8 bits per sample { Byte[] data = new Byte[strm.data.data.Length - (int)strm.head.loopOffset]; Array.Copy(strm.data.data, strm.head.loopOffset, data, 0, data.Length); strm.data.data = data; } else if (loop && strm.head.waveType == 2) // 4 bits per sample { Byte[] data = new Byte[strm.data.data.Length - ((int)strm.head.loopOffset * 2)]; Array.Copy(strm.data.data, strm.head.loopOffset * 2, data, 0, data.Length); strm.data.data = data; } else if (loop && strm.head.waveType == 1) // 16-bits per sample (NO TESTED) { Byte[] data = new Byte[strm.data.data.Length - (int)strm.head.loopOffset]; Array.Copy(strm.data.data, strm.head.loopOffset, data, 0, data.Length); strm.data.data = data; } } // Create the WAV structure from the STRM data wav = WAV.Create_WAV(strm.head.channels, strm.head.sampleRate, 16, strm.data.data); return(wav); }