public ReadWaveHeader ( Stream stream ) : |
||
stream | Stream | |
Résultat |
/// <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; }
private WaveFileReader(Stream inputStream, bool ownInput) { this.waveStream = inputStream; var chunkReader = new WaveFileChunkReader(); try { chunkReader.ReadWaveHeader(inputStream); this.waveFormat = chunkReader.WaveFormat; this.dataPosition = chunkReader.DataChunkPosition; this.dataChunkLength = chunkReader.DataChunkLength; this.chunks = chunkReader.RiffChunks; } catch { if (ownInput) { inputStream.Dispose(); } throw; } Position = 0; this.ownInput = ownInput; }
/// <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; }
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); } }
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; }