/// <summary>
        /// Write the audio track
        /// </summary>
        /// <param name="stream">The source stream of the file</param>
        /// <param name="container">The container used by the file (default : raw)</param>
        public void Write(Stream stream, AudioFileContainer container = AudioFileContainer.RAW)
        {
            try
            {
                byte[] buffer = new byte[_sectorSize];
                int    dataRead;

                stream.Position = (container == AudioFileContainer.WAVE) ? 44 : 0;
                _size           = ((stream.Length - stream.Position) / _sectorSize) + 1;

                for (int sectorsDone = 0; sectorsDone < _size; sectorsDone++)
                {
                    dataRead = stream.Read(buffer, 0, _sectorSize);

                    if (dataRead < _sectorSize)
                    {
                        for (int i = dataRead; i < _sectorSize; i++)
                        {
                            buffer[i] = 0;
                        }
                    }

                    WriteSector(buffer);
                }
            }
            catch (Exception)
            {
                throw new FrameworkException("Error while writing audio track : unable to write audio track");
            }
        }
Beispiel #2
0
 public void Write(string f, AudioFileContainer af) {
     //Preliminary checks
     if (af.Tag.IsEmpty) {
         Delete(f);
         return;
     }
     
     CreateStreams(f, Action.Write, af.Tag);
 }
Beispiel #3
0
        public void Write(string f, AudioFileContainer af)
        {
            //Preliminary checks
            if (af.Tag.IsEmpty)
            {
                Delete(f);
                return;
            }

            CreateStreams(f, Action.Write, af.Tag);
        }
 /// <summary>
 /// Extract the audio track
 /// </summary>
 /// <param name="outFilePath">The full path of the disk's file (eg : /FOO/BAR/FILE.EXT)</param>
 /// <param name="container">The container used for the file</param>
 public void Extract(string outFilePath, AudioFileContainer container)
 {
     try
     {
         Directory.CreateDirectory(Path.GetDirectoryName(outFilePath));
         using (var fs = new FileStream(outFilePath, FileMode.Create, FileAccess.Write))
         {
             if (container == AudioFileContainer.WAVE)
             {
                 using (var stream = new CBinaryWriter(fs))
                 {
                     // WAVE Header
                     uint dataSize = (uint)(_size * _sectorSize);
                     stream.WriteAsciiString("RIFF");          // RIFF sign
                     stream.Write((uint)(dataSize + 44 - 8));  // File size - 8, wave header is 44 bytes long
                     stream.WriteAsciiString("WAVE");          // Format ID
                     stream.WriteAsciiString("fmt", 4);        // Format bloc ID
                     stream.Write((uint)16);                   // Bloc size
                     stream.Write((ushort)0x01);               // PCM
                     stream.Write((ushort)2);                  // Channels
                     stream.Write((uint)44100);                // Frequency
                     stream.Write((uint)(44100 * 2 * 16 / 8)); // Bytes per sec (frequency * bytes per bloc)
                     stream.Write((ushort)(2 * 16 / 8));       // Bytes per bloc (channels * bits per sample / 8)
                     stream.Write((ushort)16);                 // Bits per sample
                     stream.WriteAsciiString("data");          // data bloc sign
                     stream.Write((uint)dataSize);             // data size
                     Read(fs);
                 }
             }
             else
             {
                 Read(fs);
             }
         }
     }
     catch (FrameworkException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw new FrameworkException("Error while writing audio file : unable to write file \"{0}\"", outFilePath);
     }
 }
Beispiel #5
0
 public AudioFile(Stream stream, string mimetype)
 {
     this.mimetype = mimetype;
     container     = AudioFileIO.Read(stream, mimetype);
 }
Beispiel #6
0
 public AudioFile(string filename, string mimetype)
 {
     this.filename = filename;
     this.mimetype = mimetype;
     container     = AudioFileIO.Read(filename, mimetype);
 }
Beispiel #7
0
 public AudioFile(string filename)
 {
     this.filename = filename;
     container     = AudioFileIO.Read(filename);
 }