private static int test01_ReadWrite8BitsMonoWAVFile() { WAV_file my_wav_file = new WAV_file(); my_wav_file.File_name = "dog_bark.wav"; Console.WriteLine( "Nome: " + my_wav_file.File_name ); my_wav_file.Path = ".\\"; // my_wav_file.Path = ".\\Debug\\wav_files\\"; Console.WriteLine( "Path: " + my_wav_file.Path ); my_wav_file.loadFile(); Console.Write(my_wav_file.toWAVHeaderString()); System.Byte[] buffer_8_bits_Mono; uint numberOfSamples = (uint) my_wav_file.getBuffer_8_bits_mono( out buffer_8_bits_Mono); // Buffer processing. Console.WriteLine(); Console.WriteLine(); for (uint i = 0; i < numberOfSamples; i++) { // Console.Write( buffer_8_bits_Mono[i].toString() + "."); } Console.WriteLine(); Console.WriteLine(); // We are going to save the file on the hard drive with another name. my_wav_file.File_name = "test01_dog_bark_saved.wav"; my_wav_file.initializeWaveHeaderStructBeforeWriting(); my_wav_file.setBuffer_8_bits_mono(buffer_8_bits_Mono); my_wav_file.writeFile(); return 0; }
private static int test05_Read16BitsMonoWrite16bitsStereoWAVFile() { WAV_file my_wav_file = new WAV_file(); my_wav_file.File_name = "test03_A440_16_Bits_Mono.wav"; Console.WriteLine("Nome: " + my_wav_file.File_name); my_wav_file.Path = ".\\"; // my_wav_file.Path = ".\\Debug\\wav_files\\"; Console.WriteLine("Path: " + my_wav_file.Path); my_wav_file.loadFile(); Console.Write(my_wav_file.toWAVHeaderString()); System.Int16[] buffer_16_bits_Mono; uint numberOfSamples = (uint)my_wav_file.getBuffer_16_bits_mono(out buffer_16_bits_Mono); // Buffer processing. Console.WriteLine(); Console.WriteLine(); for (uint i = 0; i < numberOfSamples; i++) { // Console.Write( buffer_16_bits_Mono[i].toString() + "."); } Console.WriteLine(); Console.WriteLine(); // We are going to save the file on the hard drive with another name. my_wav_file.File_name = "test05_A440_16_Bits_Stereo.wav"; my_wav_file.NumOfChannels = WAV_file.NUM_CHANNELS.TWO; my_wav_file.initializeWaveHeaderStructBeforeWriting(); my_wav_file.setBuffer_16_bits_stereo(buffer_16_bits_Mono, buffer_16_bits_Mono); my_wav_file.writeFile(); return 0; }
private static int test11_ReadWrite16BitsStereo__double__WAVFile() { WAV_file my_wav_file = new WAV_file(); my_wav_file.File_name = "test05_A440_16_Bits_Stereo.wav"; Console.WriteLine("Nome: " + my_wav_file.File_name); my_wav_file.Path = ".\\"; // my_wav_file.Path = ".\\Debug\\wav_files\\"; Console.WriteLine("Path: " + my_wav_file.Path); my_wav_file.loadFile(); Console.Write(my_wav_file.toWAVHeaderString()); double[] buffer_double_left; double[] buffer_double_right; uint numberOfSamples = (uint)my_wav_file.getBuffer_double_stereo_normalized(out buffer_double_left, out buffer_double_right); // Buffer processing. Console.WriteLine(); Console.WriteLine(); for (uint i = 0; i < numberOfSamples; i++) { // Console.Write( buffer_double_left[i].toString() + "."); // Console.Write( buffer_double_right[i].toString() + "."); } Console.WriteLine(); Console.WriteLine(); // We are going to save the file on the hard drive with another name. my_wav_file.File_name = "test11_A440_16_Bits_Stereo.wav"; my_wav_file.initializeWaveHeaderStructBeforeWriting(); my_wav_file.setBuffer_double_stereo_normalized(buffer_double_left, buffer_double_right); my_wav_file.writeFile(); return 0; }
private static int test03_generate16BitsMono440HzWAVFile() { WAV_file my_wav_file = new WAV_file(); my_wav_file.File_name = "test03_A440_16_Bits_Mono.wav"; Console.WriteLine("Nome: " + my_wav_file.File_name); my_wav_file.Path = ".\\"; // my_wav_file.Path = ".\\Debug\\wav_files\\"; Console.WriteLine("Path: " + my_wav_file.Path); const System.UInt32 C_SAMPLES_PER_SEC = 8000; const System.UInt32 C_TIME_SEC = 5; my_wav_file.BitsPerSample = WAV_file.BITS_PER_SAMPLE.BPS_16_BITS; my_wav_file.NumOfChannels = WAV_file.NUM_CHANNELS.ONE; my_wav_file.SampleRate = C_SAMPLES_PER_SEC; my_wav_file.NumberOfSamples = C_SAMPLES_PER_SEC * C_TIME_SEC; // 5 segundos my_wav_file.initializeWaveHeaderStructBeforeWriting(); System.Int16[] buffer_16_bits_Mono; // Allocate the memory for the buffer. my_wav_file.getBuffer_16_bits_mono(out buffer_16_bits_Mono); // Fills the buffer with a sinusoidal. float alphaAngle = 0; const System.UInt32 C_SIGNAL_FREQUENCY = 440; // 440 Hz La (A) for (uint i = 0; i < my_wav_file.NumberOfSamples; i++) { buffer_16_bits_Mono[i] = (System.Int16) (Math.Round(Math.Sin(alphaAngle) * System.Int16.MaxValue)); alphaAngle += (2 * (float)(Math.PI) * C_SIGNAL_FREQUENCY) / C_SAMPLES_PER_SEC; } my_wav_file.setBuffer_16_bits_mono(buffer_16_bits_Mono); my_wav_file.writeFile(); return 0; }