/// <summary> /// Implementation of the IDisposable pattern /// </summary> /// <param name="disposing">Are we being destroyed</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (this.wavParser != null) { this.wavParser.Dispose(); this.wavParser = null; } } }
public static void ConcatenateWavs(Stream[] wavs, Stream output) { var parsedWavs = new WavParser[wavs.Length]; // Get total raw data stream length uint len = 0; for (int i = 0; i < wavs.Length; i++) { var wavParser = new WavParser(wavs[i]); parsedWavs[i] = wavParser; len += wavParser.RawWaveSize; } // Write WAV header WriteWavHeader(output, parsedWavs[0].AudioFormat, len); // Write raw PCM data streams in sequence for (int i = 0; i < wavs.Length; i++) WriteRawData(wavs[i], output, WAV_HEADER_SIZE, parsedWavs[i].RawWaveSize); //trim at the end to ignore any extra data chunks (like the ones in BWF [Broadcast Wave Format]) }
/// <summary> /// Open the media. /// Create the structures. /// </summary> protected override void OpenMediaAsync() { // Create a parser this.wavParser = new WavParser(this.stream); // Parse the header this.wavParser.ParseWaveHeader(); this.wavParser.WaveFormatEx.ValidateWaveFormat(); this.startPosition = this.currentPosition = this.wavParser.DataPosition; // Init var streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>(); var sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>(); var availableStreams = new List<MediaStreamDescription>(); // Stream Description streamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = this.wavParser.WaveFormatEx.ToHexString(); var msd = new MediaStreamDescription(MediaStreamType.Audio, streamAttributes); this.audioDesc = msd; availableStreams.Add(this.audioDesc); sourceAttributes[MediaSourceAttributesKeys.Duration] = this.wavParser.Duration.ToString(); ReportOpenMediaCompleted(sourceAttributes, availableStreams); }
/// <summary> /// Close the media. Release the resources. /// </summary> protected override void CloseMedia() { // Close the stream this.startPosition = this.currentPosition = 0; this.wavParser = null; this.audioDesc = null; }