public BufferedWaveProvider(WaveFormat waveFormat) { this.waveFormat = waveFormat; this.BufferLength = waveFormat.AverageBytesPerSecond * 5; this.ReadFully = true; }
/// <summary> /// Creates a new WaveFileWriter /// </summary> /// <param name="filename">The filename to write to</param> /// <param name="format">The Wave Format of the output data</param> public WaveFileWriter(string filename, WaveFormat format) : this(new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read), format) { this.filename = filename; }
public IntPtr MarshalManagedToNative(object ManagedObj) { return(WaveFormat.MarshalToPtr((WaveFormat)ManagedObj)); }
public object MarshalNativeToManaged(IntPtr pNativeData) { return(WaveFormat.MarshalFromPtr(pNativeData)); }
public void Init(IWaveProvider waveProvider) { long num = (long)(this.latencyMilliseconds * 10000); this.outputFormat = waveProvider.WaveFormat; WaveFormatExtensible waveFormatExtensible; if (!this.audioClient.IsFormatSupported(this.shareMode, this.outputFormat, out waveFormatExtensible)) { if (waveFormatExtensible == null) { WaveFormat waveFormat = this.audioClient.MixFormat; if (!this.audioClient.IsFormatSupported(this.shareMode, waveFormat)) { WaveFormatExtensible[] array = new WaveFormatExtensible[] { new WaveFormatExtensible(this.outputFormat.SampleRate, 32, this.outputFormat.Channels), new WaveFormatExtensible(this.outputFormat.SampleRate, 24, this.outputFormat.Channels), new WaveFormatExtensible(this.outputFormat.SampleRate, 16, this.outputFormat.Channels) }; for (int i = 0; i < array.Length; i++) { waveFormat = array[i]; if (this.audioClient.IsFormatSupported(this.shareMode, waveFormat)) { break; } waveFormat = null; } if (waveFormat == null) { waveFormat = new WaveFormatExtensible(this.outputFormat.SampleRate, 16, 2); if (!this.audioClient.IsFormatSupported(this.shareMode, waveFormat)) { throw new NotSupportedException("Can't find a supported format to use"); } } } this.outputFormat = waveFormat; } else { this.outputFormat = waveFormatExtensible; } using (new ResamplerDmoStream(waveProvider, this.outputFormat)) { } this.dmoResamplerNeeded = true; } else { this.dmoResamplerNeeded = false; } this.sourceProvider = waveProvider; if (this.isUsingEventSync) { if (this.shareMode == AudioClientShareMode.Shared) { this.audioClient.Initialize(this.shareMode, AudioClientStreamFlags.EventCallback, num, 0L, this.outputFormat, Guid.Empty); long streamLatency = this.audioClient.StreamLatency; if (streamLatency != 0L) { this.latencyMilliseconds = (int)(streamLatency / 10000L); } } else { this.audioClient.Initialize(this.shareMode, AudioClientStreamFlags.EventCallback, num, num, this.outputFormat, Guid.Empty); } this.frameEventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); this.audioClient.SetEventHandle(this.frameEventWaitHandle.SafeWaitHandle.DangerousGetHandle()); } else { this.audioClient.Initialize(this.shareMode, AudioClientStreamFlags.None, num, 0L, this.outputFormat, Guid.Empty); } this.renderClient = this.audioClient.AudioRenderClient; }
public CueWaveFileWriter(string fileName, WaveFormat waveFormat) : base(fileName, waveFormat) { }
public static IMp3FrameDecompressor CreateAcmFrameDecompressor(WaveFormat mp3Format) { return(new AcmMp3FrameDecompressor(mp3Format)); }
private Mp3FileReader(Stream inputStream, Mp3FileReader.FrameDecompressorBuilder frameDecompressorBuilder, bool ownInputStream) { if (inputStream == null) { throw new ArgumentNullException("inputStream"); } if (frameDecompressorBuilder == null) { throw new ArgumentNullException("frameDecompressorBuilder"); } this.ownInputStream = ownInputStream; try { this.mp3Stream = inputStream; this.Id3v2Tag = Id3v2Tag.ReadTag(this.mp3Stream); this.dataStartPosition = this.mp3Stream.Position; Mp3Frame mp3Frame = Mp3Frame.LoadFromStream(this.mp3Stream); if (mp3Frame == null) { throw new InvalidDataException("Invalid MP3 file - no MP3 Frames Detected"); } double num = (double)mp3Frame.BitRate; this.xingHeader = XingHeader.LoadXingHeader(mp3Frame); if (this.xingHeader != null) { this.dataStartPosition = this.mp3Stream.Position; } Mp3Frame mp3Frame2 = Mp3Frame.LoadFromStream(this.mp3Stream); if (mp3Frame2 != null && (mp3Frame2.SampleRate != mp3Frame.SampleRate || mp3Frame2.ChannelMode != mp3Frame.ChannelMode)) { this.dataStartPosition = mp3Frame2.FileOffset; mp3Frame = mp3Frame2; } this.mp3DataLength = this.mp3Stream.Length - this.dataStartPosition; this.mp3Stream.Position = this.mp3Stream.Length - 128L; byte[] array = new byte[128]; this.mp3Stream.Read(array, 0, 128); if (array[0] == 84 && array[1] == 65 && array[2] == 71) { this.Id3v1Tag = array; this.mp3DataLength -= 128L; } this.mp3Stream.Position = this.dataStartPosition; this.Mp3WaveFormat = new Mp3WaveFormat(mp3Frame.SampleRate, (mp3Frame.ChannelMode == ChannelMode.Mono) ? 1 : 2, mp3Frame.FrameLength, (int)num); this.CreateTableOfContents(); this.tocIndex = 0; num = (double)this.mp3DataLength * 8.0 / this.TotalSeconds(); this.mp3Stream.Position = this.dataStartPosition; this.Mp3WaveFormat = new Mp3WaveFormat(mp3Frame.SampleRate, (mp3Frame.ChannelMode == ChannelMode.Mono) ? 1 : 2, mp3Frame.FrameLength, (int)num); this.decompressor = frameDecompressorBuilder(this.Mp3WaveFormat); this.waveFormat = this.decompressor.OutputFormat; this.bytesPerSample = this.decompressor.OutputFormat.BitsPerSample / 8 * this.decompressor.OutputFormat.Channels; this.bytesPerDecodedFrame = 1152 * this.bytesPerSample; this.decompressBuffer = new byte[this.bytesPerDecodedFrame * 2]; } catch (Exception) { if (ownInputStream) { inputStream.Dispose(); } throw; } }
public static void ReadAiffHeader(Stream stream, out WaveFormat format, out long dataChunkPosition, out int dataChunkLength, List <AiffFileReader.AiffChunk> chunks) { dataChunkPosition = -1L; format = null; BinaryReader binaryReader = new BinaryReader(stream); if (AiffFileReader.ReadChunkName(binaryReader) != "FORM") { throw new FormatException("Not an AIFF file - no FORM header."); } AiffFileReader.ConvertInt(binaryReader.ReadBytes(4)); string a = AiffFileReader.ReadChunkName(binaryReader); if (a != "AIFC" && a != "AIFF") { throw new FormatException("Not an AIFF file - no AIFF/AIFC header."); } dataChunkLength = 0; while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { AiffFileReader.AiffChunk aiffChunk = AiffFileReader.ReadChunkHeader(binaryReader); if (aiffChunk.ChunkName == "\0\0\0\0" || binaryReader.BaseStream.Position + (long)((ulong)aiffChunk.ChunkLength) > binaryReader.BaseStream.Length) { break; } if (aiffChunk.ChunkName == "COMM") { short channels = AiffFileReader.ConvertShort(binaryReader.ReadBytes(2)); AiffFileReader.ConvertInt(binaryReader.ReadBytes(4)); short bits = AiffFileReader.ConvertShort(binaryReader.ReadBytes(2)); double num = IEEE.ConvertFromIeeeExtended(binaryReader.ReadBytes(10)); format = new WaveFormat((int)num, (int)bits, (int)channels); if (aiffChunk.ChunkLength > 18u && a == "AIFC") { if (new string(binaryReader.ReadChars(4)).ToLower() != "none") { throw new FormatException("Compressed AIFC is not supported."); } binaryReader.ReadBytes((int)(aiffChunk.ChunkLength - 22u)); } else { binaryReader.ReadBytes((int)(aiffChunk.ChunkLength - 18u)); } } else if (aiffChunk.ChunkName == "SSND") { uint num2 = AiffFileReader.ConvertInt(binaryReader.ReadBytes(4)); AiffFileReader.ConvertInt(binaryReader.ReadBytes(4)); dataChunkPosition = (long)((ulong)(aiffChunk.ChunkStart + 16u + num2)); dataChunkLength = (int)(aiffChunk.ChunkLength - 8u); binaryReader.BaseStream.Position += (long)((ulong)(aiffChunk.ChunkLength - 8u)); } else { if (chunks != null) { chunks.Add(aiffChunk); } binaryReader.BaseStream.Position += (long)((ulong)aiffChunk.ChunkLength); } } if (format == null) { throw new FormatException("Invalid AIFF file - No COMM chunk found."); } if (dataChunkPosition == -1L) { throw new FormatException("Invalid AIFF file - No SSND chunk found."); } }
public void SetWaveFormat(int sampleRate, int channels) { this.waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channels); }
private static long BytesToNsPosition(int bytes, WaveFormat waveFormat) { long nsPosition = (10000000L * bytes) / waveFormat.AverageBytesPerSecond; return(nsPosition); }