Exemplo n.º 1
0
 public void Save(FilePath filePath)
 {
     using (Stream savedStream = new FileStream(
                filePath.FileFullPath, FileMode.Create, FileAccess.Write))
     {
         WriteWaveFileHeader(savedStream, SoundData.Length);
         StreamOperations.WriteBytesToStream(savedStream, SoundData);
         Console.WriteLine($"{filePath.Name} saved");
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Assumption: The header is 44 bytes.
        /// </summary>
        /// <param name="savedStream"></param>
        /// <param name="soundDataSizeInBytes"></param>
        private void WriteWaveFileHeader(Stream savedStream, int soundDataSizeInBytes)
        {
            // Writes "RIFF" chunk descriptor.
            StreamOperations.WriteStringToStream(savedStream, RIFF_STR);
            StreamOperations.WriteIntegerToStream(savedStream, soundDataSizeInBytes + 36, BitConvertorWrapper.IntType.Int32);
            StreamOperations.WriteStringToStream(savedStream, WAVE_STR);

            // Write "fmt" sub-chunk.
            StreamOperations.WriteStringToStream(savedStream, FMT_STR);
            StreamOperations.WriteIntegerToStream(savedStream, 16, BitConvertorWrapper.IntType.Int32);
            StreamOperations.WriteIntegerToStream(savedStream, mAudioFormat, BitConvertorWrapper.IntType.Int16);
            StreamOperations.WriteIntegerToStream(savedStream, NumChannels, BitConvertorWrapper.IntType.Int16);
            StreamOperations.WriteIntegerToStream(savedStream, SampleRate, BitConvertorWrapper.IntType.Int32);
            StreamOperations.WriteIntegerToStream(savedStream, ByteRate, BitConvertorWrapper.IntType.Int32);
            StreamOperations.WriteIntegerToStream(savedStream, BytesPerSample, BitConvertorWrapper.IntType.Int16);
            StreamOperations.WriteIntegerToStream(savedStream, BitsPerSample, BitConvertorWrapper.IntType.Int16);

            // Write "data" sub-chunk.
            StreamOperations.WriteStringToStream(savedStream, DATA_STR);
            StreamOperations.WriteIntegerToStream(savedStream, soundDataSizeInBytes, BitConvertorWrapper.IntType.Int32);
        }