public static wavHeader Read(BinaryReader reader) { wavHeader rv = new wavHeader(); rv.read(reader); return(rv); }
private void clear() { header = null; format = null; data = null; FileName = null; Name = null; }
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; }
// Constructor accepting output from fourier.cs displays filtered sample. public Load(float[] filteredSample, wavHeader wh) { InitializeComponent(); zoom = false; button4.BackColor = Color.Red; comboBox1.SelectedIndex = 0; sample = filteredSample; header = wh; fillListFromWavHeader(header); repaintChart3(sample); }
// Method reads wav file from filestream. void readWav(string filename) { try { using (FileStream fs = File.Open(filename, FileMode.Open)) { BinaryReader reader = new BinaryReader(fs); // Read the header of the wav file. int chunkID = reader.ReadInt32(); int fileSize = reader.ReadInt32(); int riffType = reader.ReadInt32(); int fmtID = reader.ReadInt32(); int fmtSize = reader.ReadInt32(); int fmtCode = reader.ReadInt16(); int channels = reader.ReadInt16(); int sampleRate = reader.ReadInt32(); int byteRate = reader.ReadInt32(); int fmtBlockAlign = reader.ReadInt16(); int bitDepth = reader.ReadInt16(); int fmtExtraSize = 0; if (fmtSize == 18) { fmtExtraSize = reader.ReadInt16(); reader.ReadBytes(fmtExtraSize); } int dataID = reader.ReadInt32(); int bytes = reader.ReadInt32(); header = new wavHeader(chunkID, fileSize, riffType, fmtID, fmtSize, fmtCode, channels, sampleRate, byteRate, fmtBlockAlign, bitDepth, fmtExtraSize, dataID, bytes); fillListFromWavHeader(header); // Construct the wav header struct. byte[] byteArray = reader.ReadBytes(bytes); // Read all the data into the byte array. int bytesForSamp = bitDepth / 8; int samps = bytes / bytesForSamp; sample = null; Int16[] asInt16 = new Int16[samps]; Buffer.BlockCopy(byteArray, 0, asInt16, 0, bytes); sample = Array.ConvertAll(asInt16, e => e / (float)Int16.MaxValue); // Convert to range of -1 to 1. } } catch { Console.WriteLine("...Failed to load note: " + filename); } }
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); } }
// Method iterates header names and values into the list for user to view. private void fillListFromWavHeader(wavHeader wh) { listView1.Items.Clear(); listView2.Items.Clear(); foreach (var field in typeof(wavHeader).GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { Console.WriteLine("{0} = {1}", field.Name, field.GetValue(wh)); ListViewItem lvi = new ListViewItem(field.Name); ListViewItem lvi2 = new ListViewItem(field.GetValue(wh).ToString()); listView1.Items.Add(lvi); listView2.Items.Add(lvi2); } }
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(); } }
public wavHeader(wavHeader copy) { dwFileLength = copy.dwFileLength; }