Example #1
0
        void InitOutput(string outputPath)
        {
            outData    = File.Create(outputPath + ".bin");
            outText    = new StreamWriter(outputPath + ".txt");
            outDecoder = new RawOut(outData, true);

            outText.WriteLine("# This file indicates where the various raw decompressed sound data " +
                              "are found in the corresponding raw .bin file.");
            outText.WriteLine("# Each line is in the following format:");
            outText.WriteLine("# Identifier, Frequency/Sample rate, BitsPerSample, " +
                              "Channels, Offset from start, Length in bytes");
        }
Example #2
0
        void WriteWaveHeader(BinaryWriter w, Stream stream, RawOut data)
        {
            WriteFourCC(w, "RIFF");
            w.Write((int)(stream.Length - 8));
            WriteFourCC(w, "WAVE");

            WriteFourCC(w, "fmt ");
            w.Write(16);
            w.Write((ushort)1);             // audio format, PCM
            w.Write((ushort)data.Last.Channels);
            w.Write(data.Last.SampleRate);
            w.Write((data.Last.SampleRate * data.Last.Channels * data.Last.BitsPerSample) / 8); // byte rate
            w.Write((ushort)((data.Last.Channels * data.Last.BitsPerSample) / 8));              // block align
            w.Write((ushort)data.Last.BitsPerSample);

            WriteFourCC(w, "data");
            w.Write((int)(stream.Length - 44));
        }
Example #3
0
        void DecodeSound(string name, byte[] rawData)
        {
            string path = Path.Combine(Program.AppDirectory, "audio");

            path = Path.Combine(path, prefix + name + ".wav");

            using (FileStream dst = File.Create(path))
                using (MemoryStream src = new MemoryStream(rawData))
                {
                    dst.SetLength(44);
                    RawOut       output    = new RawOut(dst, true);
                    OggContainer container = new OggContainer(src);
                    output.PlayStreaming(container);

                    dst.Position = 0;
                    BinaryWriter w = new BinaryWriter(dst);
                    WriteWaveHeader(w, dst, output);
                }
        }
        void DecodeSound( string name, byte[] rawData )
        {
            string path = Path.Combine( Program.AppDirectory, "audio" );
            path = Path.Combine( path, prefix + name + ".wav" );

            using( FileStream dst = File.Create( path ) )
                using ( MemoryStream src = new MemoryStream( rawData ) )
            {
                dst.SetLength( 44 );
                RawOut output = new RawOut( dst, true );
                OggContainer container = new OggContainer( src );
                output.PlayStreaming( container );

                dst.Position = 0;
                BinaryWriter w = new BinaryWriter( dst );
                WriteWaveHeader( w, dst, output );
            }
        }
        void WriteWaveHeader( BinaryWriter w, Stream stream, RawOut data )
        {
            WriteFourCC( w, "RIFF" );
            w.Write( (int)(stream.Length - 8) );
            WriteFourCC( w, "WAVE" );

            WriteFourCC( w, "fmt " );
            w.Write( 16 );
            w.Write( (ushort)1 ); // audio format, PCM
            w.Write( (ushort)data.Channels );
            w.Write( data.Frequency );
            w.Write((data.Frequency * data.Channels * data.BitsPerSample) / 8 ); // byte rate
            w.Write( (ushort)((data.Channels * data.BitsPerSample) / 8) ); // block align
            w.Write( (ushort)data.BitsPerSample );

            WriteFourCC( w, "data" );
            w.Write( (int)(stream.Length - 44) );
        }