/// <summary> /// Write the child elements of a WavAudioMediaData element. /// </summary> /// <param name="destination">The destination <see cref="XmlWriter"/></param> /// <param name="baseUri"> /// The base <see cref="Uri"/> used to make written <see cref="Uri"/>s relative, /// if <c>null</c> absolute <see cref="Uri"/>s are written /// </param> /// <param name="handler">The handler for progress</param> protected override void XukOutChildren(XmlWriter destination, Uri baseUri, IProgressHandler handler) { base.XukOutChildren(destination, baseUri, handler); if (!PCMFormat.ValueEquals(Presentation.MediaDataManager.DefaultPCMFormat)) { destination.WriteStartElement(XukStrings.PCMFormat); PCMFormat.XukOut(destination, baseUri, handler); destination.WriteEndElement(); } if (Presentation.Project.PrettyFormat) { destination.WriteStartElement(XukStrings.WavClips, XukAble.XUK_NS); } foreach (WavClip clip in mWavClips) { destination.WriteStartElement(WavClip_NAME.z(PrettyFormat), XukAble.XUK_NS); destination.WriteAttributeString(DataProvider.DataProvider_NAME.z(PrettyFormat), clip.DataProvider.Uid); if (!clip.ClipBegin.IsEqualTo(Time.Zero)) { destination.WriteAttributeString(XukStrings.ClipBegin, clip.ClipBegin.ToString()); } if (!clip.IsClipEndTiedToEOM) { destination.WriteAttributeString(XukStrings.ClipEnd, clip.ClipEnd.ToString()); } destination.WriteEndElement(); } if (Presentation.Project.PrettyFormat) { destination.WriteEndElement(); } }
/// <summary> /// Exports <c>this</c> to a given destination <see cref="Presentation"/> /// </summary> /// <param name="destPres">The given destination presentation</param> /// <returns>The exported wav audio media data</returns> protected override MediaData ExportProtected(Presentation destPres) { WavAudioMediaData expWAMD = destPres.MediaDataFactory.Create <WavAudioMediaData>(); expWAMD.PCMFormat = PCMFormat.Copy(); // it is better to export at the level of asset stream and leave the clip composition behind // exporting clips also exports the shared DataProvider multiple times, which increases the size exponentially Stream stream = this.OpenPcmInputStream(); try { expWAMD.AppendPcmData(stream, null); } finally { stream.Close(); } //foreach (WavClip clip in mWavClips) //{ //expWAMD.mWavClips.Add(clip.Export(destPres)); //} return(expWAMD); }
public PCM(Stream stream) : base(stream) { format = Reinterpret.Memory <PCMFormat>(this["fmt "].ResourceData); data = this["data"].ResourceData; hasBeenSet = true; }
/// <summary> /// Part of technical solution to make copy method return correct type. /// In implementing classes this method should return a copy of the class instances /// </summary> /// <returns>The copy</returns> protected override MediaData CopyProtected() { WavAudioMediaData copy = Presentation.MediaDataFactory.Create <WavAudioMediaData>(); copy.PCMFormat = PCMFormat.Copy(); foreach (WavClip clip in mWavClips) { copy.mWavClips.Add(clip.Copy()); } return(copy); }
public PCM(short channels, int sampleRate) : base("WAVE") { format = new PCMFormat(); format.ChannelCount = channels; format.SignificantBitsPerSample = 16; format.BlockAlign = (short)(format.SignificantBitsPerSample / 8 * format.ChannelCount); format.SampleRate = sampleRate; format.BytesPerSecond = format.SampleRate * format.BlockAlign; format.CompressionCode = 1; format.ExtraByteCount = 0; AddBlock("fmt ", Reinterpret.Object(format)); }
/// <summary> /// Splits the audio media data at a given split point in time, /// <c>this</c> retaining the audio before the split point, /// creating a new <see cref="WavAudioMediaData"/> containing the audio after the split point /// </summary> /// <param name="splitPoint">The given split point</param> /// <returns>A audio media data containing the audio after the split point</returns> /// <exception cref="exception.MethodParameterIsNullException"> /// Thrown when the given split point is <c>null</c> /// </exception> /// <exception cref="exception.MethodParameterIsOutOfBoundsException"> /// Thrown when the given split point is negative or is beyond the duration of <c>this</c> /// </exception> public override AudioMediaData Split(Time splitPoint) { if (splitPoint == null) { throw new exception.MethodParameterIsNullException( "The split point can not be null"); } if (splitPoint.IsNegative) { throw new exception.MethodParameterIsOutOfBoundsException( "The split point can not be negative"); } if (splitPoint.IsGreaterThan(AudioDuration)) { throw new exception.MethodParameterIsOutOfBoundsException( String.Format( "Split point {0} is beyond the WavAudioMediaData end - audio length is {1}", splitPoint, AudioDuration)); } WavAudioMediaData oWAMD = Presentation.MediaDataFactory.Create <WavAudioMediaData>(); if (oWAMD == null) { throw new exception.FactoryCannotCreateTypeException(String.Format( "Thrown if the MediaDataFactory can not create a WacAudioMediaData matching Xuk QName {1}:{0}", GetXukName(), GetXukNamespace())); } oWAMD.PCMFormat = PCMFormat.Copy(); Time originalDuration = AudioDuration; Time newClipDuration = AudioDuration.GetDifference(splitPoint); Time curClip_Begin = Time.Zero; List <WavClip> clips = new List <WavClip>(mWavClips); mWavClips.Clear(); oWAMD.mWavClips.Clear(); for (int i = 0; i < clips.Count; i++) { WavClip curClip = clips[i]; Time savedCurClipDuration = curClip.Duration; Time curClip_End = new Time(curClip_Begin.AsTimeSpanTicks + curClip.Duration.AsTimeSpanTicks, true); if (splitPoint.IsLessThanOrEqualTo(curClip_Begin)) { oWAMD.mWavClips.Add(curClip); } else if (splitPoint.IsLessThan(curClip_End)) { WavClip secondPartClip = new WavClip( curClip.DataProvider, curClip.ClipBegin, curClip.IsClipEndTiedToEOM ? null : curClip.ClipEnd); curClip.ClipEnd = new Time(curClip.ClipBegin.AsTimeSpanTicks + (splitPoint.AsTimeSpanTicks - curClip_Begin.AsTimeSpanTicks), true); secondPartClip.ClipBegin = curClip.ClipEnd.Copy(); mWavClips.Add(curClip); oWAMD.mWavClips.Add(secondPartClip); } else { mWavClips.Add(curClip); } curClip_Begin.Add(savedCurClipDuration); } NotifyAudioDataRemoved(this, splitPoint, newClipDuration); oWAMD.NotifyAudioDataInserted(oWAMD, Time.Zero, newClipDuration); #if DEBUG DebugFix.Assert(AudioLibPCMFormat.TimesAreEqualWithMillisecondsTolerance( newClipDuration.AsLocalUnits, oWAMD.AudioDuration.AsLocalUnits)); DebugFix.Assert(newClipDuration.IsEqualTo(oWAMD.AudioDuration)); DebugFix.Assert(AudioLibPCMFormat.TimesAreEqualWithMillisecondsTolerance( this.AudioDuration.AsLocalUnits + oWAMD.AudioDuration.AsLocalUnits, originalDuration.AsLocalUnits)); Time copy = this.AudioDuration.Copy(); copy.Add(oWAMD.AudioDuration); DebugFix.Assert(originalDuration.IsEqualTo(copy)); #endif //DEBUG return(oWAMD); }
public override bool ValueEquals(WithPresentation other) { if (!base.ValueEquals(other)) { return(false); } AudioMediaData otherz = other as AudioMediaData; if (otherz == null) { return(false); } if (OriginalRelativePath != null && DataProvider != null) { if (OriginalRelativePath != otherz.OriginalRelativePath) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } if (!DataProvider.ValueEquals(otherz.DataProvider)) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } return(true); } if (!PCMFormat.ValueEquals(otherz.PCMFormat)) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } if (PCMFormat.Data.ConvertTimeToBytes(AudioDuration.AsLocalUnits) != otherz.PCMFormat.Data.ConvertTimeToBytes(otherz.AudioDuration.AsLocalUnits)) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } if (HasActualPcmData != otherz.HasActualPcmData) { return(false); } if (HasActualPcmData) { Stream thisData = OpenPcmInputStream(); try { Stream otherdata = otherz.OpenPcmInputStream(); try { if (!AudioLibPCMFormat.CompareStreamData(thisData, otherdata, (int)thisData.Length)) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } } finally { otherdata.Close(); } } finally { thisData.Close(); } } return(true); }