Пример #1
0
        /// <summary>
        /// Creates a Wave File Reader based on an input stream
        /// </summary>
        /// <param name="inputStream">The input stream containing a WAV file including header</param>
        public GrainWaveProvider(Stream inputStream)
        {
            this.waveStream = inputStream;
            var chunkReader = new WaveFileChunkReader();

            chunkReader.ReadWaveHeader(inputStream);
            this.waveFormat      = chunkReader.WaveFormat;
            this.dataPosition    = chunkReader.DataChunkPosition;
            this.dataChunkLength = chunkReader.DataChunkLength;
            this.chunks          = chunkReader.RiffChunks;

            waveStream.Position = dataPosition;

            var samples = (dataChunkLength / BlockAlign) * waveFormat.Channels;

            FSample = new float[samples];

            for (int i = 0; i < samples; i++)
            {
                TryReadFloat(out FSample[i]);
            }

            waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(waveFormat.SampleRate, waveFormat.Channels);

            //grain
            FGrain = new Grain();

            FGrain.SampleRate = waveFormat.SampleRate;
            FGrain.Start      = 20000;

            FGrain.Length = 1024;
            FGrain.Freq   = 440;
            FGrain.Index  = 0;
        }
Пример #2
0
        private WaveFileReader(Stream inputStream, bool ownInput)
        {
            this.waveStream = inputStream;
            var chunkReader = new WaveFileChunkReader();

            try
            {
                chunkReader.ReadWaveHeader(inputStream);
                waveFormat      = chunkReader.WaveFormat;
                dataPosition    = chunkReader.DataChunkPosition;
                dataChunkLength = chunkReader.DataChunkLength;
                ExtraChunks     = chunkReader.RiffChunks;
            }
            catch
            {
                if (ownInput)
                {
                    inputStream.Dispose();
                }

                throw;
            }

            Position      = 0;
            this.ownInput = ownInput;
        }
Пример #3
0
        public long AnalyzePP(ppParser pp)
        {
            long total = 0;

            for (int i = 0; i < pp.Subfiles.Count; i++)
            {
                IWriteFile iw = pp.Subfiles[i];

                if (!iw.Name.EndsWith(".wav"))
                {
                    continue;
                }

                Stream str = Tools.GetReadStream(iw);

                if (!str.CanSeek || str.Length == 0)
                {
                    str.Close();
                    continue;
                }

                using (str)
                {
                    WaveFileChunkReader wv = new WaveFileChunkReader();

                    WaveFormat f;
                    try
                    {
                        f = wv.ReadWaveHeader(str);
                    }
                    catch (FormatException)
                    {
                        str.Close();
                        continue;
                    }

                    long length    = str.Length;
                    long remaining = length;
                    if (f.Channels > 1) // || wv.WaveFormat.Encoding != WaveFormatEncoding.Adpcm
                    {
                        total     += (length / 2);
                        remaining /= 2;
                    }
                    if (f.SampleRate > SampleRate)
                    {
                        total += remaining - (long)(((float)SampleRate / f.SampleRate) * remaining);
                    }
                }

                if (ProgressUpdated != null)
                {
                    ProgressUpdated((int)Math.Floor((double)(100 * i) / pp.Subfiles.Count));
                }
            }

            return(total);
        }
        /// <summary>
        /// Creates a Wave File Reader based on an input stream
        /// </summary>
        /// <param name="inputStream">The input stream containing a WAV file including header</param>
        public WaveFileReader(Stream inputStream)
        {
            this.waveStream = inputStream;
            var chunkReader = new WaveFileChunkReader();

            chunkReader.ReadWaveHeader(inputStream);
            this.waveFormat      = chunkReader.WaveFormat;
            this.dataPosition    = chunkReader.DataChunkPosition;
            this.dataChunkLength = chunkReader.DataChunkLength;
            this.chunks          = chunkReader.RiffChunks;
            Position             = 0;
        }
Пример #5
0
        /// <summary>
        /// Creates a Wave File Reader based on an input stream
        /// </summary>
        /// <param name="inputStream">The input stream containing a WAV file including header</param>
        // Token: 0x06000AED RID: 2797 RVA: 0x00020568 File Offset: 0x0001E768
        public WaveFileReader(Stream inputStream)
        {
            this.waveStream = inputStream;
            WaveFileChunkReader waveFileChunkReader = new WaveFileChunkReader();

            waveFileChunkReader.ReadWaveHeader(inputStream);
            this.waveFormat      = waveFileChunkReader.WaveFormat;
            this.dataPosition    = waveFileChunkReader.DataChunkPosition;
            this.dataChunkLength = waveFileChunkReader.DataChunkLength;
            this.chunks          = waveFileChunkReader.RiffChunks;
            this.Position        = 0L;
        }
Пример #6
0
    RiffChunk ReadWaveFile(string path)
    {
        RiffChunk riffChunk;

        using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            using (var reader = new BinaryReader(fs))
            {
                riffChunk = (RiffChunk)WaveFileChunkReader.Read(reader);
            }

        return(riffChunk);
    }
Пример #7
0
        public void CanWriteDataChunkGreaterThan2GB()
        {
            WaveFormat format           = WaveFormat.CreateIeeeFloatWaveFormat(8000, 2);
            uint       blockSizeInBytes = (uint)format.AverageBytesPerSecond * 8U;

            using (var writer = new LargeWaveWriter(blockSizeInBytes, UInt32.MaxValue / blockSizeInBytes, format))
            {
                Assert.IsTrue(writer.ActualDataSizeInBytes > Int32.MaxValue && writer.ActualDataSizeInBytes <= UInt32.MaxValue,
                              "Something is wrong with the test set-up parameters.");
                using (var stream = new FileStream(writer.Filename, FileMode.Open))
                {
                    var reader = new WaveFileChunkReader();
                    reader.ReadWaveHeader(stream);
                    Assert.AreEqual(writer.ActualDataSizeInBytes, reader.DataChunkLength);
                }
            }
        }
        public void TestEmptyFile()
        {
            // arrange
            var fileContents = new byte[]
            {
                0x52, 0x49, 0x46, 0x46, // "RIFF"
                0x26, 0x00, 0x00, 0x00, // ChunkSize = 38
                0x57, 0x41, 0x56, 0x45, // "WAVE"
                0x66, 0x6d, 0x74, 0x20, // "fmt "
                0x12, 0x00, 0x00, 0x00, // Subchunk1Size = 18
                0x07, 0x00, 0x02, 0x00, // AudioFormat = 7, NumChannels = 2
                0x40, 0x1f, 0x00, 0x00, // SampleRate = 8000
                0x80, 0x3e, 0x00, 0x00, // ByteRate = 16000
                0x02, 0x00, 0x08, 0x00, // BlockAlign = 2, BitsPerSample = 8
                0x00, 0x00,             // ExtraParamSize = 0
                0x64, 0x61, 0x74, 0x61, // "data"
                0x00, 0x00, 0x00, 0x00, // Subchunk2Size = 0
            };

            using (var inputStream = new MemoryStream(fileContents))
            {
                // act
                var chunks      = new List <RiffChunk>();
                var chunkReader = new WaveFileChunkReader();
                chunkReader.ReadWaveHeader(inputStream);

                // assert
                Assert.AreEqual(16000, chunkReader.WaveFormat.AverageBytesPerSecond);
                Assert.AreEqual(8, chunkReader.WaveFormat.BitsPerSample);
                Assert.AreEqual(2, chunkReader.WaveFormat.Channels);
                Assert.AreEqual(8000, chunkReader.WaveFormat.SampleRate);

                Assert.AreEqual(46, chunkReader.DataChunkPosition);
                Assert.AreEqual(0, chunkReader.DataChunkLength);
                Assert.AreEqual(0, chunks.Count);
            }
        }
Пример #9
0
        private WaveFileReader(Stream inputStream, bool ownInput)
        {
            this.waveStream = inputStream;
            WaveFileChunkReader waveFileChunkReader = new WaveFileChunkReader();

            try
            {
                waveFileChunkReader.ReadWaveHeader(inputStream);
                this.waveFormat      = waveFileChunkReader.WaveFormat;
                this.dataPosition    = waveFileChunkReader.DataChunkPosition;
                this.dataChunkLength = waveFileChunkReader.DataChunkLength;
                this.ExtraChunks     = waveFileChunkReader.RiffChunks;
            }
            catch
            {
                if (ownInput)
                {
                    inputStream.Dispose();
                }
                throw;
            }
            this.Position = 0L;
            this.ownInput = ownInput;
        }
Пример #10
0
 /// <summary>
 /// Creates a Wave File Reader based on an input stream
 /// </summary>
 /// <param name="inputStream">The input stream containing a WAV file including header</param>
 public GrainWaveProvider(Stream inputStream)
 {
     this.waveStream = inputStream;
     var chunkReader = new WaveFileChunkReader();
     chunkReader.ReadWaveHeader(inputStream);
     this.waveFormat = chunkReader.WaveFormat;
     this.dataPosition = chunkReader.DataChunkPosition;
     this.dataChunkLength = chunkReader.DataChunkLength;
     this.chunks = chunkReader.RiffChunks;            
 	
     waveStream.Position = dataPosition;
     
     var samples = (dataChunkLength / BlockAlign) * waveFormat.Channels;
 	FSample = new float[samples];
 	
 	for(int i=0; i<samples; i++)
 	{
 		TryReadFloat(out FSample[i]);
 	}
 	
 	waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(waveFormat.SampleRate, waveFormat.Channels);
 	
 	//grain
 	FGrain = new Grain();
 	
 	FGrain.SampleRate = waveFormat.SampleRate;
 	FGrain.Start = 20000;
 	
 	FGrain.Length = 1024;
 	FGrain.Freq = 440;
 	FGrain.Index = 0;
 	
 }