public static wavData Read(BinaryReader reader) { wavData rv = new wavData(); rv.read(reader); return(rv); }
//reads the wav placed at the sourcePath private void ReadWav() { try { wavdata = new wavData(); wavdata.data = new List <short>(); //read Wav using (FileStream fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { try { wavdata.riffID = br.ReadBytes(4); wavdata.size = br.ReadUInt32(); wavdata.wavID = br.ReadBytes(4); wavdata.fmtID = br.ReadBytes(4); wavdata.fmtSize = br.ReadUInt32(); wavdata.format = br.ReadUInt16(); wavdata.channels = br.ReadUInt16(); wavdata.sampleRate = br.ReadUInt32(); wavdata.bytePerSec = br.ReadUInt32(); wavdata.blockSize = br.ReadUInt16(); wavdata.bit = br.ReadUInt16(); wavdata.dataID = br.ReadBytes(4); wavdata.dataSize = br.ReadUInt32(); for (int i = 0; (i < wavdata.dataSize / wavdata.blockSize); i += wavdata.channels) { wavdata.data.Add((short)br.ReadUInt16()); if (wavdata.channels == 2) { br.ReadUInt16(); //Skip any second channel } if (fs.Position == fs.Length) { break; //stop when end of file } } wavdata.channels = 1; //set channels on 1 incase it was 2 } finally { if (br != null) { br.Close(); } if (fs != null) { fs.Close(); } } } } catch (Exception) { throw new Exception("trouble reading WAV file! Perhaps your wav file is corrupt."); } }
private void clear() { header = null; format = null; data = null; FileName = null; Name = null; }
public wavData(wavData copy) { samples = new byte[copy.samples.Length]; for (int k = 0; k < copy.samples.Length; k++) { samples[k] = copy.samples[k]; } }
public Wav(Wav copy) { header = new wavHeader(copy.header); format = new wavFormat(copy.format); data = new wavData(copy.data); OrigDuration = copy.OrigDuration; FileName = copy.FileName; Name = copy.Name; }
// internally used methodes /// <summary> /// update all WAV data /// </summary> private void ReadWav() { try { wavdata = new wavData(); wavdata.data = new List <short>(); //just to be sure idk maybe the pointer ain't forgotten... //read Wav using (FileStream fs = new FileStream(wavPath, FileMode.Open, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { try { wavdata.riffID = br.ReadBytes(4); wavdata.size = br.ReadUInt32(); wavdata.wavID = br.ReadBytes(4); wavdata.fmtID = br.ReadBytes(4); wavdata.fmtSize = br.ReadUInt32(); wavdata.format = br.ReadUInt16(); wavdata.channels = br.ReadUInt16(); //important! wavdata.sampleRate = br.ReadUInt32(); wavdata.bytePerSec = br.ReadUInt32(); wavdata.blockSize = br.ReadUInt16();//important! wavdata.bit = br.ReadUInt16(); wavdata.dataID = br.ReadBytes(4); wavdata.dataSize = br.ReadUInt32();//important! for (int i = 0; (i < wavdata.dataSize / wavdata.blockSize); i += wavdata.channels) { wavdata.data.Add((short)br.ReadUInt16()); if (wavdata.channels == 2) { br.ReadUInt16(); //throw away 2nd channel } } } finally { if (br != null) { br.Close(); } if (fs != null) { fs.Close(); } } } } catch (Exception) { throw new Exception("trouble reading WAV file! Perhaps your wav file is corrupt."); } }
public void Cat(Wav inputFile) { if (header == null) { header = new wavHeader(inputFile.header); format = new wavFormat(inputFile.format); data = new wavData(inputFile.data); } else { data.Cat(inputFile); } }
public void Write(BinaryWriter writer, wavFormat format, wavData data) { calcLen(format, data); writer.Write(sGroupID.ToCharArray()); writer.Write(dwFileLength); writer.Write(sRiffType.ToCharArray()); // Write the format chunk format.Write(writer); // Write the data chunk data.Write(writer); }
public void Load(string filePath) { clear(); FileName = filePath; Name = Path.GetFileName(FileName); using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { using (BinaryReader reader = new BinaryReader(fileStream)) { // Read the header header = wavHeader.Read(reader); // Read the format chunk format = wavFormat.Read(reader); // Read the data chunk data = wavData.Read(reader); OrigDuration = Duration; reader.Close(); } fileStream.Close(); } }
private void calcLen(wavFormat format, wavData data) { dwFileLength = (uint)sRiffType.Length + format.getLength() + data.getLength(); }