Пример #1
0
        const uint DefaultSampleRate = 44100; // XXX varies

        public override SoundInput TryOpen(IBinaryStream file)
        {
            bool is_adp4 = file.Name.HasExtension(".adp4");
            bool is_adps = !is_adp4 && file.Name.HasExtension(".adps");

            if (!(is_adp4 || is_adps) || file.Length <= 4)
            {
                return(null);
            }
            var decoder = new AdpDecoder(file);
            var pcm     = decoder.Decode(is_adps);
            var format  = new WaveFormat {
                FormatTag        = 1,
                Channels         = 2,
                SamplesPerSecond = DefaultSampleRate,
                BlockAlign       = 4,
                BitsPerSample    = 16,
            };

            format.SetBPS();
            var input = new MemoryStream(pcm);
            var sound = new RawPcmInput(input, format);

            file.Dispose();
            return(sound);
        }
Пример #2
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            var  header      = file.ReadHeader(0x10);
            int  samples     = header.ToInt32(4);
            uint sample_rate = header.ToUInt32(8);

            if (sample_rate < 8000 || sample_rate > 96000)
            {
                return(null);
            }
            ushort channels = header.ToUInt16(12);

            if (channels != 1 && channels != 2)
            {
                return(null);
            }
            samples *= channels;

            var output = new byte[2 * samples];
            var first  = new AdpDecoder();
            var second = first;

            if (channels > 1)
            {
                second = new AdpDecoder();
            }
            int dst = 0;

            while (samples > 0)
            {
                int v = file.ReadByte();
                if (-1 == v)
                {
                    break;
                }
                LittleEndian.Pack(first.DecodeSample(v), output, dst);
                if (0 == --samples)
                {
                    break;
                }
                dst += 2;
                LittleEndian.Pack(second.DecodeSample(v >> 4), output, dst);
                dst += 2;
                --samples;
            }

            var format = new WaveFormat {
                FormatTag             = 1,
                Channels              = channels,
                SamplesPerSecond      = sample_rate,
                AverageBytesPerSecond = 2u * channels * sample_rate,
                BlockAlign            = (ushort)(2 * channels),
                BitsPerSample         = 16,
            };
            var pcm   = new MemoryStream(output);
            var sound = new RawPcmInput(pcm, format);

            file.Dispose();
            return(sound);
        }
Пример #3
0
 public override SoundInput TryOpen (IBinaryStream file)
 {
     var decoder = new WbcDecoder (file);
     var data = decoder.Decode();
     var pcm = new MemoryStream (data);
     var sound = new RawPcmInput (pcm, decoder.Format);
     file.Dispose();
     return sound;
 }
Пример #4
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            var decoder  = new Wv5Decoder(file);
            var pcm_data = decoder.Unpack();
            var pcm      = new MemoryStream(pcm_data);
            var sound    = new RawPcmInput(pcm, decoder.Format);

            file.Dispose();
            return(sound);
        }
Пример #5
0
 public override SoundInput TryOpen(IBinaryStream file)
 {
     using (var decoder = new Mv2Decoder(file))
     {
         decoder.Unpack();
         var pcm   = new MemoryStream(decoder.Data);
         var sound = new RawPcmInput(pcm, decoder.Format);
         file.Dispose();
         return(sound);
     }
 }
Пример #6
0
        }                                                                 // 'MKVS'

        public override SoundInput TryOpen(IBinaryStream file)
        {
            using (var reader = new MvDecoder(file))
            {
                reader.Unpack();
                var input = new MemoryStream(reader.Data);
                var sound = new RawPcmInput(input, reader.Format);
                file.Dispose();
                return(sound);
            }
        }
Пример #7
0
        }                                                                 // 'Entis'

        public override SoundInput TryOpen(IBinaryStream file)
        {
            var header = file.ReadHeader(0x40);

            if (0x02000200 != header.ToUInt32(8))
            {
                return(null);
            }
            if (!header.AsciiEqual(0x10, "EMSAC-Sound-2"))
            {
                return(null);
            }
            var decoder = new EmsacDecoder(file);
            var pcm     = decoder.Decode();
            var sound   = new RawPcmInput(pcm, decoder.Format);

            file.Dispose();
            return(sound);
        }
Пример #8
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            var  header      = file.ReadHeader(0xC4);
            uint sample_rate = header.ToUInt32(0);

            if (sample_rate < 8000 || sample_rate > 96000)
            {
                return(null);
            }
            ushort channels = header.ToUInt16(4);

            if (channels != 1 && channels != 2)
            {
                return(null);
            }
            int samples   = header.ToInt32(0xBC) * channels;
            int start_pos = header.ToInt32(0xC0);

            if (samples <= 0 || start_pos >= file.Length)
            {
                return(null);
            }

            var output = new byte[2 * samples];
            var first  = new AdpDecoder();
            var second = first;

            if (channels > 1)
            {
                second = new AdpDecoder();
            }
            file.Position = start_pos;
            int dst = 0;

            while (samples > 0)
            {
                byte v = file.ReadUInt8();
                LittleEndian.Pack(first.DecodeSample(v >> 4), output, dst);
                if (0 == --samples)
                {
                    break;
                }
                dst += 2;
                LittleEndian.Pack(second.DecodeSample(v), output, dst);
                dst += 2;
                --samples;
            }
            var format = new WaveFormat();

            format.FormatTag             = 1;
            format.Channels              = channels;
            format.SamplesPerSecond      = sample_rate;
            format.AverageBytesPerSecond = 2u * channels * sample_rate;
            format.BlockAlign            = (ushort)(2 * channels);
            format.BitsPerSample         = 0x10;
            var pcm   = new MemoryStream(output);
            var sound = new RawPcmInput(pcm, format);

            file.Dispose();
            return(sound);
        }
Пример #9
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            if (file.Signature != Wav.Signature || !file.Name.HasExtension(".adp"))
            {
                return(null);
            }

            var header = file.ReadHeader(0x24);

            if (!header.AsciiEqual(8, "WAVEfmt "))
            {
                return(null);
            }
            uint fmt_size = header.ToUInt32(0x10);
            int  codec    = header.ToUInt16(0x14);

            if (0xFFFF != codec)
            {
                return(null);
            }

            uint   sample_rate = header.ToUInt32(0x18);
            ushort channels    = header.ToUInt16(0x16);

            if (channels != 1 && channels != 2)
            {
                return(null);
            }

            int  shift          = 2;
            uint section_offset = 0x14 + fmt_size;
            uint section_size;

            for (;;)
            {
                file.Position = section_offset;
                uint section_id = file.ReadUInt32();
                section_size = file.ReadUInt32();
                if (section_id == 0x61746164) // 'data'
                {
                    break;
                }
                if (section_id == 0x74666873) // 'shft'
                {
                    shift = file.ReadInt32();
                }
                section_offset += 8 + ((section_size + 1u) & ~1u);
            }
            int samples = (int)(2 * section_size / channels);

            if (shift < 0)
            {
                shift = 2;
            }
            var output = new byte[samples * 2 * channels];
            var first  = new AdpDecoder(shift);
            int dst    = 0;

            if (1 == channels)
            {
                while (samples > 0)
                {
                    byte v = file.ReadUInt8();
                    LittleEndian.Pack(first.DecodeSample(v), output, dst);
                    LittleEndian.Pack(first.DecodeSample(v >> 4), output, dst + 2);
                    dst     += 4;
                    samples -= 2;
                }
            }
            else
            {
                var second = new AdpDecoder(shift);
                while (samples > 0)
                {
                    byte v = file.ReadUInt8();
                    LittleEndian.Pack(first.DecodeSample(v), output, dst);
                    LittleEndian.Pack(first.DecodeSample(v >> 4), output, dst + 4);
                    v = file.ReadUInt8();
                    LittleEndian.Pack(second.DecodeSample(v), output, dst + 2);
                    LittleEndian.Pack(second.DecodeSample(v >> 4), output, dst + 6);
                    dst     += 8;
                    samples -= 2;
                }
            }
            var format = new WaveFormat();

            format.FormatTag             = 1;
            format.Channels              = channels;
            format.SamplesPerSecond      = sample_rate;
            format.AverageBytesPerSecond = 2u * channels * sample_rate;
            format.BlockAlign            = (ushort)(2 * channels);
            format.BitsPerSample         = 0x10;
            var pcm   = new MemoryStream(output);
            var sound = new RawPcmInput(pcm, format);

            file.Dispose();
            return(sound);
        }
Пример #10
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            var    header   = file.ReadHeader(0x28);
            ushort channels = header.ToUInt16(0);

            if (0 == channels || channels > 2)
            {
                return(null);
            }
            ushort bps = header.ToUInt16(2);

            if (bps != 8 && bps != 16)
            {
                return(null);
            }
            var info = new NwaMetaData
            {
                Compression      = header.ToInt32(8),
                RunLengthEncoded = 0 != header.ToInt32(0xC),
                BlockCount       = header.ToInt32(0x10),
                PcmSize          = header.ToInt32(0x14),
                PackedSize       = header.ToInt32(0x18),
                SampleCount      = header.ToInt32(0x1C),
                BlockSize        = header.ToInt32(0x20),
                FinalBlockSize   = header.ToInt32(0x24),
            };

            if (info.PcmSize <= 0)
            {
                return(null);
            }
            info.Format.FormatTag             = 1;
            info.Format.Channels              = channels;
            info.Format.BitsPerSample         = bps;
            info.Format.SamplesPerSecond      = header.ToUInt32(4);
            info.Format.BlockAlign            = (ushort)(channels * bps / 8);
            info.Format.AverageBytesPerSecond = info.Format.BlockAlign * info.Format.SamplesPerSecond;
            if (-1 == info.Compression)
            {
                if (info.PcmSize > file.Length - 0x2C)
                {
                    return(null);
                }
                return(new RawPcmInput(new StreamRegion(file.AsStream, 0x2C, info.PcmSize), info.Format));
            }
            if (info.Compression > 5)
            {
                return(null);
            }
            if (info.PcmSize != info.SampleCount * bps / 8)
            {
                return(null);
            }
            using (var decoder = new NwaDecoder(file, info))
            {
                decoder.Decode();
                var pcm   = new MemoryStream(decoder.Output);
                var sound = new RawPcmInput(pcm, info.Format);
                file.Dispose();
                return(sound);
            }
        }
Пример #11
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            if (file.Signature != 0x5367674F) // 'OggS'
            {
                return(null);
            }
            var header     = file.ReadHeader(0x1C);
            int table_size = header[0x1A];

            if (table_size < 1)
            {
                return(null);
            }
            int header_size = header[0x1B];

            if (header_size < 0x10)
            {
                return(null);
            }
            int header_pos = 0x1B + table_size;

            header = file.ReadHeader(header_pos + header_size);
            if (!header.AsciiEqual(header_pos, "OpusHead"))
            {
                return(null);
            }
            int channels = header[header_pos + 9];
//            int rate = header.ToInt32 (header_pos+0xC);
            int rate = 48000;

            file.Position = 0;
            var decoder = OpusDecoder.Create(rate, channels);
            var ogg_in  = new OpusOggReadStream(decoder, file.AsStream);
            var pcm     = new MemoryStream();

            try
            {
                using (var output = new BinaryWriter(pcm, System.Text.Encoding.UTF8, true))
                {
                    while (ogg_in.HasNextPacket)
                    {
                        var packet = ogg_in.DecodeNextPacket();
                        if (packet != null)
                        {
                            for (int i = 0; i < packet.Length; ++i)
                            {
                                output.Write(packet[i]);
                            }
                        }
                    }
                }
                var format = new WaveFormat
                {
                    FormatTag        = 1,
                    Channels         = (ushort)channels,
                    SamplesPerSecond = (uint)rate,
                    BitsPerSample    = 16,
                };
                format.BlockAlign            = (ushort)(format.Channels * format.BitsPerSample / 8);
                format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlign;
                pcm.Position = 0;
                var sound = new RawPcmInput(pcm, format);
                file.Dispose();
                return(sound);
            }
            catch
            {
                pcm.Dispose();
                throw;
            }
        }