Exemple #1
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            if (!file.Name.HasExtension("PWV"))
            {
                return(null);
            }
            var header = file.ReadHeader(0x10);

            if (!header.AsciiEqual(9, "WAVE"))
            {
                return(null);
            }
            var output = new MemoryStream((int)file.Length);

            try
            {
                file.Position = 0;
                Unpack(file, output);
                output.Position = 0;
                var wave = new WaveInput(output);
                file.Dispose();
                return(wave);
            }
            catch
            {
                output.Dispose();
                throw;
            }
        }
Exemple #2
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            int first = file.ReadByte();

            if ((first ^ 0x21) != 0x78) // doesn't look like zlib stream
            {
                return(null);
            }
            file.Position = 0;
            using (var input = new XoredStream(file.AsStream, 0x21, true))
                using (var zstream = new ZLibStream(input, CompressionMode.Decompress))
                {
                    SoundInput sound = null;
                    var        wav   = new MemoryStream();
                    try
                    {
                        zstream.CopyTo(wav);
                        wav.Position = 0;
                        sound        = new WaveInput(wav);
                    }
                    finally
                    {
                        if (null == sound)
                        {
                            wav.Dispose();
                        }
                        else
                        {
                            file.Dispose();
                        }
                    }
                    return(sound);
                }
        }
        private void OnThreadProc()
        {
            var token = _tokenSource.Token;

            var device = DeviceEnumerator.GetWaveInDeviceById(Options.DeviceId);

            if (device == null)
            {
                throw new InvalidOperationException($"Device '{Options.DeviceId}' is not found");
            }

            var waveFormat = new WaveFormat(44100, 16, 2);

            using (var input = new WaveInput(device, waveFormat))
            {
                input.OnDataReady += OnDataReady;
                input.Start();

                Console.WriteLine($"Wave input is started ({waveFormat})");

                while (!token.IsCancellationRequested)
                {
                    Thread.Sleep(10);
                }

                input.Stop();
            }
        }
    private void Awake()
    {
        _MainInput = new WaveInput();
        _MainInput.Enable();
        _BeatIndex = 0;

        _WaveDrawer = new WaveDrawer(8 * 12, 8 * 6, _WaveRenderer, _WaveTarget);

        _ActiveUI = false;
        _UI.gameObject.SetActive(_ActiveUI);
    }
Exemple #5
0
        public override SoundInput TryOpen(Stream file)
        {
            int packed = ReadInt32(file);

            if (packed < 0)
            {
                return(null);
            }
            byte[] input;
            if (packed > 12)
            {
                if ((packed + 8) != file.Length)
                {
                    return(null);
                }
                int unpacked = ReadInt32(file);
                if (unpacked <= 0)
                {
                    return(null);
                }
                using (var reader = new LzssReader(file, packed, unpacked))
                {
                    reader.Unpack();
                    if (Binary.AsciiEqual(reader.Data, 0, "RIFF"))
                    {
                        var sound = new WaveInput(new MemoryStream(reader.Data));
                        file.Dispose();
                        return(sound);
                    }
                    input = reader.Data;
                }
            }
            else
            {
                if (0x46464952 != ReadInt32(file))  // 'RIFF'
                {
                    return(null);
                }
                file.Position = 0;
                input         = new byte[file.Length];
                file.Read(input, 0, input.Length);
            }
            var wa1 = new Wa1Reader(input);

            wa1.Unpack();
            var wav = new WaveInput(new MemoryStream(wa1.Data));

            file.Dispose();
            return(wav);
        }
Exemple #6
0
        }                                                                 // 'WST2'

        public override SoundInput TryOpen(IBinaryStream file)
        {
            var adpcm_data = new byte[0x20];

            file.Position = 12;
            if (0x1C != file.Read(adpcm_data, 4, 0x1C))
            {
                return(null);
            }
            adpcm_data[0] = 0xF4;
            adpcm_data[1] = 7;
            adpcm_data[2] = 7;
            int data_length = (int)(file.Length - file.Position);
            int total_size  = 0x4E - 8 + data_length;
            var wav_file    = new MemoryStream(total_size + 4);

            try
            {
                using (var wav = new BinaryWriter(wav_file, Encoding.Default, true))
                {
                    wav.Write(Wav.Signature);
                    wav.Write(total_size);
                    wav.Write(0x45564157); // 'WAVE'
                    wav.Write(0x20746d66); // 'fmt '
                    wav.Write(0x32);
                    wav.Write((ushort)2);  // ADPCM
                    wav.Write((ushort)2);  // channels
                    wav.Write((uint)0xAC44);
                    wav.Write((uint)0xAC44);
                    wav.Write((ushort)0x800);
                    wav.Write((ushort)4);
                    wav.Write((ushort)0x20);
                    wav.Write(adpcm_data, 0, adpcm_data.Length);
                    wav.Write(0x61746164);  // 'data'
                    wav.Write(data_length);
                    file.AsStream.CopyTo(wav_file);
                }
                wav_file.Position = 0;
                var sound = new WaveInput(wav_file);
                file.Dispose();
                return(sound);
            }
            catch
            {
                wav_file.Dispose();
                throw;
            }
        }
Exemple #7
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            int length = (int)file.Length;

            if (length < 4)
            {
                return(null);
            }
            uint signature = file.ReadUInt8();

            switch (signature & 0x42)
            {
            case 0x42:
                length -= 3;
                break;

            case 0x02:
            case 0x40:
                length -= 1;
                break;

            default:
                return(null);
            }
            uint key    = (signature & 0xBD) ^ 0x6A8CD4E7u;
            var  header = file.ReadBytes(4);

            file.Position = 1;
            Decrypt(header, key);

            SoundInput sound = null;

            if (header.AsciiEqual("RIFF"))
            {
                sound = new WaveInput(DecryptedStream(file, length, key));
            }
            else if (header.AsciiEqual("OggS"))
            {
                sound = new OggInput(DecryptedStream(file, length, key));
            }
            if (sound != null)
            {
                file.Dispose();
            }
            return(sound);
        }
Exemple #8
0
 private void Awake()
 {
     _MainInput = new WaveInput();
     _MainInput.Enable();
 }
Exemple #9
0
        }                                                                 // 'WPX'

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

            if (!header.AsciiEqual(4, "WAV"))
            {
                return(null);
            }
            int count    = header[0xE];
            int dir_size = header[0xF];

            if (1 != header[0xC] || 0 == count || 0 == dir_size)
            {
                return(null);
            }

            file.Position = 0x10;
            var index = file.ReadBytes(count * dir_size);

            var section = WpxSection.Find(index, 0x20, count, dir_size);

            if (null == section || section.UnpackedSize < 0x10 || section.DataFormat != 0x80)
            {
                throw new InvalidFormatException();
            }
            file.Position = section.Offset;
            var fmt = file.ReadBytes(section.UnpackedSize);

            section = WpxSection.Find(index, 0x21, count, dir_size);
            if (null == section)
            {
                throw new InvalidFormatException();
            }

            var reader = new WwaReader(file.AsStream, section);
            var data   = reader.Unpack(section.DataFormat);

            if (null == data)
            {
                throw new InvalidFormatException();
            }

            int total_size = 20 + fmt.Length + data.Length;

            using (var wav_file = new MemoryStream(20 + fmt.Length))
                using (var wav = new BinaryWriter(wav_file))
                {
                    wav.Write(Wav.Signature);
                    wav.Write(total_size);
                    wav.Write(0x45564157); // 'WAVE'
                    wav.Write(0x20746d66); // 'fmt '
                    wav.Write(fmt.Length);
                    wav.Write(fmt);
                    wav.Write(0x61746164); // 'data'
                    wav.Write(data.Length);
                    var wav_header  = wav_file.ToArray();
                    var data_stream = new MemoryStream(data);
                    var source      = new PrefixStream(wav_header, data_stream);
                    var sound       = new WaveInput(source);
                    file.Dispose();
                    return(sound);
                }
        }