Ejemplo n.º 1
0
        // === Public Member Functions === //

        public AudioFile(string Path)
        {
            this.Path_ = Path;
            try
            {
                BinaryReader BR =
                    new BinaryReader(new FileStream(this.Path_, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 0x30),
                                     Encoding.ASCII);
                this.DetermineType(BR);
                if (this.Type_ != AudioFileType.Unknown)
                {
                    this.Header_ = new AudioFileHeader();
                    switch (this.Type_)
                    {
                    case AudioFileType.BGMStream:
                        this.Header_.SampleFormat = (SampleFormat)BR.ReadInt32();
                        this.Header_.Size         = BR.ReadInt32();
                        break;

                    case AudioFileType.SoundEffect:
                        this.Header_.Size         = BR.ReadInt32();
                        this.Header_.SampleFormat = (SampleFormat)BR.ReadInt32();
                        break;
                    }
                    this.Header_.ID             = BR.ReadInt32();
                    this.Header_.SampleBlocks   = BR.ReadInt32();
                    this.Header_.LoopStart      = BR.ReadInt32();
                    this.Header_.SampleRateHigh = BR.ReadInt32();
                    this.Header_.SampleRateLow  = BR.ReadInt32();
                    this.Header_.Unknown1       = BR.ReadInt32();
                    this.Header_.Unknown2       = BR.ReadByte();
                    this.Header_.Unknown3       = BR.ReadByte();
                    this.Header_.Channels       = BR.ReadByte();
                    this.Header_.BlockSize      = BR.ReadByte();
                    switch (this.Type_)
                    {
                    case AudioFileType.BGMStream:
                        this.Header_.Unknown4 = 0;
                        break;

                    case AudioFileType.SoundEffect:
                        this.Header_.Unknown4 = BR.ReadInt32();
                        break;
                    }
                }
                BR.Close();
            }
            catch
            {
                this.Type_   = AudioFileType.Unknown;
                this.Header_ = new AudioFileHeader();
            }
        }
Ejemplo n.º 2
0
 internal AudioFileStream(string Path, AudioFileHeader Header, bool AddWAVHeader)
 {
     this.Path_         = Path;
     this.Header_       = Header;
     this.AddWAVHeader_ = AddWAVHeader;
     this.Codec_        = null;
     this.Position_     = 0;
     if (this.Header_.SampleFormat == SampleFormat.ADPCM)
     {
         this.Codec_ = new ADPCMCodec(this.Header_.Channels, this.Header_.BlockSize);
     }
     this.File_ = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     this.File_.Seek(0x30, SeekOrigin.Begin);
     if (AddWAVHeader)
     {
         // Prepare WAV file header
         this.WAVHeader_ = new byte[0x2C];
         BinaryWriter BW = new BinaryWriter(new MemoryStream(this.WAVHeader_, true), Encoding.ASCII);
         // File Header
         BW.Write("RIFF".ToCharArray());
         BW.Write((int)this.Length);
         // Wave Format Header
         BW.Write("WAVEfmt ".ToCharArray());
         BW.Write((int)0x10);
         // Wave Format Data
         BW.Write((short)1); // PCM
         BW.Write((short)this.Header_.Channels);
         BW.Write((int)this.Header_.SampleRate);
         BW.Write((int)(2 * this.Header_.Channels * this.Header_.SampleRate)); // bytes per second
         BW.Write((short)(2 * this.Header_.Channels));                         // bytes per sample
         BW.Write((short)16);                                                  // bits
         // Wave Data Header
         BW.Write("data".ToCharArray());
         BW.Write((int)(this.Length - 0x2C));
         BW.Close();
     }
     this.Buffer_     = null;
     this.BufferPos_  = 0;
     this.BufferSize_ = 0;
 }
Ejemplo n.º 3
0
 // === Public Member Functions === //
 public AudioFile(string Path)
 {
     this.Path_ = Path;
       try {
       BinaryReader BR = new BinaryReader(new FileStream(this.Path_, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 0x30), Encoding.ASCII);
     this.DetermineType(BR);
     if (this.Type_ != AudioFileType.Unknown) {
       this.Header_ = new AudioFileHeader();
       switch (this.Type_) {
     case AudioFileType.BGMStream:
       this.Header_.SampleFormat = (SampleFormat) BR.ReadInt32();
       this.Header_.Size         = BR.ReadInt32();
       break;
     case AudioFileType.SoundEffect:
       this.Header_.Size         = BR.ReadInt32();
       this.Header_.SampleFormat = (SampleFormat) BR.ReadInt32();
       break;
       }
       this.Header_.ID             = BR.ReadInt32();
       this.Header_.SampleBlocks   = BR.ReadInt32();
       this.Header_.LoopStart      = BR.ReadInt32();
       this.Header_.SampleRateHigh = BR.ReadInt32();
       this.Header_.SampleRateLow  = BR.ReadInt32();
       this.Header_.Unknown1       = BR.ReadInt32();
       this.Header_.Unknown2       = BR.ReadByte ();
       this.Header_.Unknown3       = BR.ReadByte ();
       this.Header_.Channels       = BR.ReadByte ();
       this.Header_.BlockSize      = BR.ReadByte ();
       switch (this.Type_) {
     case AudioFileType.BGMStream:   this.Header_.Unknown4 = 0;              break;
     case AudioFileType.SoundEffect: this.Header_.Unknown4 = BR.ReadInt32(); break;
       }
     }
     BR.Close();
       }
       catch {
     this.Type_   = AudioFileType.Unknown;
     this.Header_ = new AudioFileHeader();
       }
 }
Ejemplo n.º 4
0
 internal AudioFileStream(string Path, AudioFileHeader Header, bool AddWAVHeader)
 {
     this.Path_ = Path;
     this.Header_ = Header;
     this.AddWAVHeader_ = AddWAVHeader;
     this.Codec_ = null;
     this.Position_ = 0;
     if (this.Header_.SampleFormat == SampleFormat.ADPCM)
     {
         this.Codec_ = new ADPCMCodec(this.Header_.Channels, this.Header_.BlockSize);
     }
     this.File_ = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     this.File_.Seek(0x30, SeekOrigin.Begin);
     if (AddWAVHeader)
     {
         // Prepare WAV file header
         this.WAVHeader_ = new byte[0x2C];
         BinaryWriter BW = new BinaryWriter(new MemoryStream(this.WAVHeader_, true), Encoding.ASCII);
         // File Header
         BW.Write("RIFF".ToCharArray());
         BW.Write((int)this.Length);
         // Wave Format Header
         BW.Write("WAVEfmt ".ToCharArray());
         BW.Write((int)0x10);
         // Wave Format Data
         BW.Write((short)1); // PCM
         BW.Write((short)this.Header_.Channels);
         BW.Write((int)this.Header_.SampleRate);
         BW.Write((int)(2 * this.Header_.Channels * this.Header_.SampleRate)); // bytes per second
         BW.Write((short)(2 * this.Header_.Channels)); // bytes per sample
         BW.Write((short)16); // bits
         // Wave Data Header
         BW.Write("data".ToCharArray());
         BW.Write((int)(this.Length - 0x2C));
         BW.Close();
     }
     this.Buffer_ = null;
     this.BufferPos_ = 0;
     this.BufferSize_ = 0;
 }
Ejemplo n.º 5
0
 internal AudioFileStream(string Path, AudioFileHeader Header)
     : this(Path, Header, false)
 {
 }
Ejemplo n.º 6
0
 internal AudioFileStream(string Path, AudioFileHeader Header)
     : this(Path, Header, false)
 {
 }