/******************************************************** * Takes in a Wav object and string depicting the file path. * A binary writer is used to write the wav file to the disk. * THe header file is written first, and then sample data * portion of the wav object. **********************************************************/ public static void writeFile(Wav file, string filePath) { FileStream fileStream = new FileStream(filePath, FileMode.Create); BinaryWriter writer = new BinaryWriter(fileStream); //Write the header writer.Write(file.head.chunkID); writer.Write(file.head.fileSize); writer.Write(file.head.riffType); //Write the format chunk writer.Write(file.head.fmtID); writer.Write(file.head.fmtSize); writer.Write(file.head.fmtCode); writer.Write(file.head.channels); writer.Write(file.head.sampleRate); writer.Write(file.head.fmtAvgBPS); writer.Write(file.head.fmtBlockAlign); writer.Write(file.head.bitDepth); //Write the data chunk writer.Write(System.Text.Encoding.ASCII.GetBytes("data")); writer.Write(file.head.dataSize); //Write the samples writer.Write(file.getData()); //Close the writer and filestream writer.Close(); fileStream.Close(); }
/***************************************************************** * Default constructor. Initilizates a blank wav file, and creates * the handler object. As well as initalize any UI components. ******************************************************************/ public GUI() { wav = new Wav(); handle = new Handler(); InitializeComponent(); setup_charts(); //Default to rectangle window window_selection = 0; this.UseWaitCursor = true; toggle_wait_cursor(); }
/***************************************************************** * Gets called when the user clicks the stop button. It sends the * message to the win32 handle to stop recording and acquires the * recorded samples. The buttons are then re-enabled and if data was * recorded a new wav file is created and drawn to the chart. If no * data was recorded an error message is displayed. ******************************************************************/ private void stopButton_Click(object sender, EventArgs e) { handle.recordData = handle.data_stop(); recordButton.Enabled = true; stopButton.Enabled = false; if (handle.recordData != null) { wav = new Wav(handle.recordData); toggle_wait_cursor(); drawChart(wav.dataToDouble()); toggle_wait_cursor(); playButton.Enabled = true; } else { MessageBox.Show("No data was recorded", "Recording error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }