private ManagedAudioMedia addAudioWav(FileDataProvider dataProv, XmlNode audioAttrClipBegin, XmlNode audioAttrClipEnd, TreeNode treeNode) { //if (m_autoDetectPcmFormat //&& m_AudioConversionSession.FirstDiscoveredPCMFormat != null //&& !m_AudioConversionSession.FirstDiscoveredPCMFormat.IsCompatibleWith(treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data)) //{ //PCMFormatInfo pcmFormat = treeNode.Presentation.MediaDataManager.DefaultPCMFormat; //.Copy(); //pcmFormat.Data.CopyFrom(m_AudioConversionSession.FirstDiscoveredPCMFormat); // //treeNode.Presentation.MediaDataManager.DefaultPCMFormat = pcmFormat; //} //if (RequestCancellation) return null; Time clipB = Time.Zero; Time clipE = Time.MaxValue; if (audioAttrClipBegin != null && !string.IsNullOrEmpty(audioAttrClipBegin.Value)) { string strBeginValue = audioAttrClipBegin.Value.Replace("npt=", ""); try { clipB = new Time(strBeginValue); } catch (Exception ex) { clipB = new Time(0); string str = "CLIP BEGIN TIME PARSE FAIL: " + audioAttrClipBegin.Value; Console.WriteLine(str); Debug.Fail(str); } } if (audioAttrClipEnd != null && !string.IsNullOrEmpty(audioAttrClipEnd.Value)) { try { string strEndValue = audioAttrClipEnd.Value.Replace("npt=", ""); clipE = new Time(strEndValue); } catch (Exception ex) { clipE = new Time(0); string str = "CLIP END TIME PARSE FAIL: " + audioAttrClipEnd.Value; Console.WriteLine(str); Debug.Fail(str); } } ManagedAudioMedia media = null; ObiPresentation presentation = m_Presentation; WavAudioMediaData mediaData = (WavAudioMediaData) presentation.MediaDataFactory.CreateAudioMediaData(); // mediaData.AudioDuration DOES NOT WORK BECAUSE DEPENDS ON WAVCLIPS LIST!!! WavClip wavClip = new WavClip(dataProv); Time newClipE = clipE.Copy(); if (Math.Abs(newClipE.AsMilliseconds) > Math.Abs(wavClip.MediaDuration.AsMilliseconds)) { Console.WriteLine("clip adjusted. file size: " + wavClip.MediaDuration.AsMilliseconds + "; clip end: " + newClipE.AsMilliseconds); clipEndAdjustedToNull(clipB, newClipE, wavClip.MediaDuration, treeNode); //newClipE = wavClip.MediaDuration; newClipE = null; } try { mediaData.AppendPcmData(dataProv, clipB, newClipE); } catch (Exception ex) { #if DEBUG Debugger.Break(); #endif //DEBUG Console.WriteLine("CLIP TIME ERROR1 (end < begin ?): " + clipB + " (" + (audioAttrClipBegin != null ? audioAttrClipBegin.Value : "N/A") + ") / " + clipE + " (" + (audioAttrClipEnd != null ? audioAttrClipEnd.Value : "N/A") + ") === " + wavClip.MediaDuration); } //if (RequestCancellation) return null; media = presentation.MediaFactory.CreateManagedAudioMedia(); media.AudioMediaData = mediaData; return(media); }
private ManagedAudioMedia addAudioWav(FileDataProvider dataProv, XmlNode audioAttrClipBegin, XmlNode audioAttrClipEnd, TreeNode treeNode) { if (m_autoDetectPcmFormat && m_AudioConversionSession.FirstDiscoveredPCMFormat != null && !m_AudioConversionSession.FirstDiscoveredPCMFormat.IsCompatibleWith(treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data)) { PCMFormatInfo pcmFormat = treeNode.Presentation.MediaDataManager.DefaultPCMFormat; //.Copy(); pcmFormat.Data.CopyFrom(m_AudioConversionSession.FirstDiscoveredPCMFormat); //pcmFormat.Data.SampleRate = (ushort) m_audioProjectSampleRate; //pcmFormat.Data.NumberOfChannels = m_audioStereo ? (ushort) 2 : (ushort) 1; treeNode.Presentation.MediaDataManager.DefaultPCMFormat = pcmFormat; } if (RequestCancellation) { return(null); } Time clipB = Time.Zero; Time clipE = Time.MaxValue; if (audioAttrClipBegin != null && !string.IsNullOrEmpty(audioAttrClipBegin.Value)) { try { clipB = new Time(audioAttrClipBegin.Value); } catch (Exception ex) { clipB = new Time(); string str = "CLIP BEGIN TIME PARSE FAIL: " + audioAttrClipBegin.Value; Console.WriteLine(str); Debug.Fail(str); } } if (audioAttrClipEnd != null && !string.IsNullOrEmpty(audioAttrClipEnd.Value)) { try { clipE = new Time(audioAttrClipEnd.Value); } catch (Exception ex) { clipE = new Time(); string str = "CLIP END TIME PARSE FAIL: " + audioAttrClipEnd.Value; Console.WriteLine(str); Debug.Fail(str); } } ManagedAudioMedia media = null; Presentation presentation = treeNode.Presentation; // m_Project.Presentations.Get(0); //if (deleteSrcAfterCompletion) //{ WavAudioMediaData mediaData = (WavAudioMediaData) presentation.MediaDataFactory.CreateAudioMediaData(); // mediaData.AudioDuration DOES NOT WORK BECAUSE DEPENDS ON WAVCLIPS LIST!!! WavClip wavClip = new WavClip(dataProv); Time newClipE = clipE.Copy(); if (newClipE.IsGreaterThan(wavClip.MediaDuration)) { clipEndAdjustedToNull(clipB, newClipE, wavClip.MediaDuration, treeNode); //newClipE = wavClip.MediaDuration; newClipE = null; } //FileDataProvider dataProv = m_Src_FileDataProviderMap[fullWavPath]; //System.Windows.Forms.MessageBox.Show ( clipB.ToString () + " : " + clipE.ToString () ) ; //bool isClipEndError = false; try { mediaData.AppendPcmData(dataProv, clipB, newClipE); } catch (Exception ex) { #if DEBUG Debugger.Break(); #endif //DEBUG Console.WriteLine("CLIP TIME ERROR1 (end < begin ?): " + clipB + " (" + (audioAttrClipBegin != null ? audioAttrClipBegin.Value : "N/A") + ") / " + clipE + " (" + (audioAttrClipEnd != null ? audioAttrClipEnd.Value : "N/A") + ") === " + wavClip.MediaDuration); //if (ex is exception.MethodParameterIsOutOfBoundsException && clipB != null && clipE != null && clipB.IsLessThanOrEqualTo(clipE)) //{ // isClipEndError = true; //} //else //{ // Console.WriteLine("CLIP TIME ERROR1 (end < begin ?): " + clipB + " (" + (audioAttrClipBegin != null ? audioAttrClipBegin.Value : "N/A") + ") / " + clipE + " (" + (audioAttrClipEnd != null ? audioAttrClipEnd.Value : "N/A") + ")"); // return null; //} } //if (isClipEndError) //{ // // reduce clip end by 1 millisecond for rounding off tolerance // isClipEndError = addAudioWavWithEndOfFileTolerance(mediaData, dataProv, clipB, clipE, treeNode); // if (isClipEndError) // { // Console.WriteLine("CLIP TIME ERROR2 (end < begin ?): " + clipB + " (" + (audioAttrClipBegin != null ? audioAttrClipBegin.Value : "N/A") + ") / " + clipE + " (" + (audioAttrClipEnd != null ? audioAttrClipEnd.Value : "N/A") + ")"); // return null; // } //} if (RequestCancellation) { return(null); } media = presentation.MediaFactory.CreateManagedAudioMedia(); media.AudioMediaData = mediaData; //} /* else * { * * uint dataLength; * AudioLibPCMFormat pcmInfo = null; * Stream wavStream = null; * try * { * wavStream = File.Open(fullWavPath, FileMode.Open, FileAccess.Read, FileShare.Read); * * pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength); * * //if (m_firstTimePCMFormat) * //{ * // presentation.MediaDataManager.DefaultPCMFormat = new PCMFormatInfo(pcmInfo); * // m_firstTimePCMFormat = false; * //} * * Time clipDuration = new Time(pcmInfo.ConvertBytesToTime(dataLength)); * if (!clipB.IsEqualTo(Time.Zero) || !clipE.IsEqualTo(Time.MaxValue)) * { * clipDuration = clipE.GetTime(clipB); * } * else * { * System.Diagnostics.Debug.Fail("Audio clip with full duration ??"); * } * * long byteOffset = 0; * if (!clipB.IsEqualTo(Time.Zero)) * { * byteOffset = pcmInfo.ConvertTimeToBytes(clipB.TimeAsMillisecondFloat); * } * if (byteOffset > 0) * { * wavStream.Seek(byteOffset, SeekOrigin.Current); * } * * presentation.MediaDataFactory.DefaultAudioMediaDataType = * typeof (WavAudioMediaData); * * WavAudioMediaData mediaData = * (WavAudioMediaData) * presentation.MediaDataFactory.CreateAudioMediaData(); * * * mediaData.InsertPcmData(wavStream, Time.Zero, clipDuration); * * media = presentation.MediaFactory.CreateManagedAudioMedia(); * ((ManagedAudioMedia) media).AudioMediaData = mediaData; * } * finally * { * if (wavStream != null) wavStream.Close(); * } * * } */ return(media); }
private Media addAudioWav(FileDataProvider dataProv, XmlNode audioAttrClipBegin, XmlNode audioAttrClipEnd) { Time clipB = Time.Zero; Time clipE = Time.MaxValue; if (audioAttrClipBegin != null && !string.IsNullOrEmpty(audioAttrClipBegin.Value)) { try { clipB = Time.ParseTimeString(audioAttrClipBegin.Value); } catch (FormatException e) { clipB = new Time(0); string str = "bad time string: " + audioAttrClipBegin.Value; Console.Write(str); Debug.Fail(str); } } if (audioAttrClipEnd != null && !string.IsNullOrEmpty(audioAttrClipEnd.Value)) { try { clipE = Time.ParseTimeString(audioAttrClipEnd.Value); } catch (FormatException e) { clipE = new Time(0); string str = "bad time string: " + audioAttrClipEnd.Value; Console.Write(str); Debug.Fail(str); } } Media media = null; Presentation presentation = m_Project.Presentations.Get(0); //if (deleteSrcAfterCompletion) //{ presentation.MediaDataFactory.DefaultAudioMediaDataType = typeof(WavAudioMediaData); WavAudioMediaData mediaData = (WavAudioMediaData) presentation.MediaDataFactory.CreateAudioMediaData(); //FileDataProvider dataProv = m_Src_FileDataProviderMap[fullWavPath]; //System.Windows.Forms.MessageBox.Show ( clipB.ToString () + " : " + clipE.ToString () ) ; mediaData.AppendPcmData(dataProv, clipB, clipE); media = presentation.MediaFactory.CreateManagedAudioMedia(); ((ManagedAudioMedia)media).AudioMediaData = mediaData; //} /* else * { * * uint dataLength; * AudioLibPCMFormat pcmInfo = null; * Stream wavStream = null; * try * { * wavStream = File.Open(fullWavPath, FileMode.Open, FileAccess.Read, FileShare.Read); * * pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength); * * //if (m_firstTimePCMFormat) * //{ * // presentation.MediaDataManager.DefaultPCMFormat = new PCMFormatInfo(pcmInfo); * // m_firstTimePCMFormat = false; * //} * * TimeDelta clipDuration = new TimeDelta(pcmInfo.ConvertBytesToTime(dataLength)); * if (!clipB.IsEqualTo(Time.Zero) || !clipE.IsEqualTo(Time.MaxValue)) * { * clipDuration = clipE.GetTimeDelta(clipB); * } * else * { * System.Diagnostics.Debug.Fail("Audio clip with full duration ??"); * } * * long byteOffset = 0; * if (!clipB.IsEqualTo(Time.Zero)) * { * byteOffset = pcmInfo.ConvertTimeToBytes(clipB.TimeAsMillisecondFloat); * } * if (byteOffset > 0) * { * wavStream.Seek(byteOffset, SeekOrigin.Current); * } * * presentation.MediaDataFactory.DefaultAudioMediaDataType = * typeof (WavAudioMediaData); * * WavAudioMediaData mediaData = * (WavAudioMediaData) * presentation.MediaDataFactory.CreateAudioMediaData(); * * * mediaData.InsertPcmData(wavStream, Time.Zero, clipDuration); * * media = presentation.MediaFactory.CreateManagedAudioMedia(); * ((ManagedAudioMedia) media).AudioMediaData = mediaData; * } * finally * { * if (wavStream != null) wavStream.Close(); * } * * } */ return(media); }