Ejemplo n.º 1
0
            public void play()
            {
                if (mCurrentTreeNode == null)
                {
                    mPlaybacAudiokDevice.FireTreeNodePlayEnded(mElapsedTime);
                    return;
                }
                ManagedAudioMedia mam    = null;
                ChannelsProperty  chProp = mCurrentTreeNode.GetProperty(typeof(ChannelsProperty)) as ChannelsProperty;

                if (chProp != null)
                {
                    mam = chProp.GetMedia(mAudioChannel) as ManagedAudioMedia;
                }
                if (mam == null)
                {
                    if (mContinueAfterTreeNode)
                    {
                        mCurrentTreeNode = mTreeNodeNavigator.GetNext(mCurrentTreeNode);
                        play();
                    }
                }
                else
                {
                    mPlaybacAudiokDevice.play(mam.AudioMediaData);
                }
            }
Ejemplo n.º 2
0
        protected ExternalAudioMedia GetExternalAudioMedia(TreeNode node)
        {
            List <Channel> channelsList = m_Presentation.ChannelsManager.GetChannelsByName(PUBLISH_AUDIO_CHANNEL_NAME);

            if (channelsList == null || channelsList.Count == 0)
            {
                return(null);
            }

            if (channelsList == null || channelsList.Count > 1)
            {
                throw new Exception("more than one publish channel cannot exist");
            }

            Channel publishChannel = channelsList[0];

            ChannelsProperty channelsProperty = node.GetChannelsProperty();

            if (channelsProperty == null)
            {
                return(null);
            }

            return(channelsProperty.GetMedia(publishChannel) as ExternalAudioMedia);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Pre-visit action:
        /// If <see cref="Media"/> is present in <see cref="Channel"/> <see cref="CollectorChannel"/>,
        /// this is added to <see cref="CollectedMedia"/> and the child <see cref="TreeNode"/>s are not visited
        /// </summary>
        /// <param name="node">The <see cref="TreeNode"/> to visit</param>
        /// <returns>
        /// <c>true</c> is no <see cref="Media"/> is present in <see cref="Channel"/> <see cref="CollectorChannel"/>,
        /// <c>false</c> else
        /// </returns>
        public bool PreVisit(TreeNode node)
        {
            bool             foundMedia = false;
            ChannelsProperty chProp     = (ChannelsProperty)node.GetProperty(typeof(ChannelsProperty));

            if (chProp != null)
            {
                if (chProp.GetMedia(CollectorChannel) != null)
                {
                    foundMedia = true;
                    mCollectedMedia.Add(chProp.GetMedia(CollectorChannel));
                }
            }
            VisitCount++;
            return(!foundMedia);
        }
        /// <summary>
        /// Any <see cref="IManaged"/> used by the
        /// </summary>
        /// <param name="node">The node being visited</param>
        /// <returns><c>true</c></returns>
        public bool PreVisit(TreeNode node)
        {
            foreach (property.Property prop in node.Properties.ContentsAs_Enumerable)
            {
                if (prop is ChannelsProperty)
                {
                    ChannelsProperty chProp = (ChannelsProperty)prop;
                    foreach (Channel ch in chProp.UsedChannels)
                    {
                        if (chProp.GetMedia(ch) is IManaged)
                        {
                            IManaged mm = (IManaged)chProp.GetMedia(ch);
                            if (!mCollectedMedia.Contains(mm))
                            {
                                mCollectedMedia.Add(mm);
                            }
                        }
                    }
                }
                else if (prop is AlternateContentProperty)
                {
                    AlternateContentProperty altProp = (AlternateContentProperty)prop;

                    foreach (AlternateContent ac in altProp.AlternateContents.ContentsAs_Enumerable)
                    {
                        if (ac.Audio != null && !mCollectedMedia.Contains(ac.Audio))
                        {
                            mCollectedMedia.Add(ac.Audio);
                        }
                        if (ac.Image != null && !mCollectedMedia.Contains(ac.Image))
                        {
                            mCollectedMedia.Add(ac.Image);
                        }
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
        public void Init(TreeNodeAndStreamSelection selection, TreeNode currentTreeNode)
        {
            if (selection == null)
            {
                throw new ArgumentNullException("selection");
            }
            if (selection.m_TreeNode == null)
            {
                throw new ArgumentNullException("selection.m_TreeNode");
            }
            if (currentTreeNode == null)
            {
                throw new ArgumentNullException("currentTreeNode");
            }

            //TreeNode = selection.m_TreeNode;

            CurrentTreeNode = currentTreeNode;
            SelectionData   = selection;

            //DebugFix.Assert(m_SelectionData.m_TreeNode == TreeNode);

            ShortDescription = "Delete audio portion";
            LongDescription  = "Delete a portion of audio for a given treenode";

            ManagedAudioMedia manMedia = m_SelectionData.m_TreeNode.GetManagedAudioMedia();

            if (manMedia == null)
            {
                throw new NullReferenceException("m_SelectionData.m_TreeNode.GetManagedAudioMedia()");
            }
            OriginalManagedAudioMedia = manMedia.Copy();
            m_UsedMediaData.Add(OriginalManagedAudioMedia.AudioMediaData);

#if DEBUG
            DebugFix.Assert(manMedia.Duration.IsEqualTo(OriginalManagedAudioMedia.Duration));
#endif //DEBUG

            ChannelsProperty chProp = m_SelectionData.m_TreeNode.GetChannelsProperty();
            foreach (Channel ch in chProp.UsedChannels)
            {
                if (manMedia == chProp.GetMedia(ch))
                {
                    ChannelOfOriginalMedia = ch;
                    break;
                }
            }
            DebugFix.Assert(ChannelOfOriginalMedia != null);
            DebugFix.Assert(ChannelOfOriginalMedia is AudioChannel);
        }
Ejemplo n.º 6
0
        //copied from Obi.Project
        //in this case, it will work because the file used for this test was created by Obi
        public urakawa.media.TextMedia GetTextMedia(TreeNode node)
        {
            ChannelsProperty channelsProp = (ChannelsProperty)node.GetProperty(typeof(ChannelsProperty));

            //IList<Channel> channelsList = channelsProp.UsedChannels;
            //for (int i = 0; i < channelsList.Count; i++)
            foreach (Channel ch in channelsProp.UsedChannels)
            {
                string channelName = ch.Name;
                if (channelName == "obi.text") //Project.TextChannel)
                {
                    return((media.TextMedia)channelsProp.GetMedia(ch));
                }
            }
            return(null);
        }
        public override void UnExecute()
        {
            ManagedAudioMedia manMedia = TreeNode.GetManagedAudioMedia();
            ChannelsProperty  chProp   = TreeNode.GetChannelsProperty();
            Channel           channel  = null;

            foreach (Channel ch in chProp.UsedChannels)
            {
                if (manMedia == chProp.GetMedia(ch))
                {
                    channel = ch;
                    break;
                }
            }
            chProp.SetMedia(channel, null);
            chProp.SetMedia(channel, OriginalManagedAudioMedia.Copy());

            //Time duration = ManagedAudioMediaSource.Duration;
            //ManagedAudioMediaTarget.AudioMediaData.RemovePcmData(TimeInsert, TimeInsert.Add(duration));
        }
Ejemplo n.º 8
0
        public Inline GetTextInline(TreeNode node)
        {
            if (TextChannel != null)
            {
                ChannelsProperty chProp = node.GetProperty <ChannelsProperty>();
                if (chProp != null)
                {
                    TextMedia text = chProp.GetMedia(TextChannel) as TextMedia;

                    if (text != null)
                    {
                        if (USE_TEXT_BOX_UIELEMENT)
                        {
                            TextBox tb = new TextBox();

                            TextMediaBinding binding = new TextMediaBinding();
                            binding.BoundTextMedia = text;
                            binding.Mode           = System.Windows.Data.BindingMode.TwoWay;
                            tb.SetBinding(TextBox.TextProperty, binding);

                            //tb.Text = text.getText();

                            tb.BorderThickness = new Thickness(1);
                            tb.Focusable       = true;
                            InlineUIContainer res = new InlineUIContainer(tb);
                            return(res);
                        }
                        else
                        {
                            TextMediaBindableRun run = new TextMediaBindableRun(text);

                            //run.Text = text.getText();
                            return(run);
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Called before visiting children in in depth first traversal.
        /// If there is a <see cref="Media"/> associated with <paramref localName="node"/>
        /// via a <see cref="ChannelsProperty"/>, the <see cref="DetectMediaTreeNodeVisitor"/>
        /// is flagged as having found a <see cref="Media"/> in the given channel
        /// and the traversal is ended
        /// </summary>
        /// <param name="node">The <see cref="TreeNode"/> to visit</param>
        /// <returns>A <see cref="bool"/> indicating if the traversal should
        /// continue after the current visit</returns>
        public bool PreVisit(TreeNode node)
        {
            // If media has already been detected, do nothing more
            if (mHasFoundMedia)
            {
                return(false);
            }
            Property prop = node.GetProperty(typeof(ChannelsProperty));

            if (prop != null)
            {
                ChannelsProperty chProp = (ChannelsProperty)prop;
                Media            m      = chProp.GetMedia(mChannel);
                // If media is present in mChannel, flag that media is detected in mChannel
                // and retrun false to avoid searching the subtree of node
                if (m != null)
                {
                    mHasFoundMedia = true;
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 10
0
        public Media GetMediaInChannel <T>() where T : Channel
        {
            ChannelsProperty chProp = GetChannelsProperty();

            if (chProp != null)
            {
                T channel = null;

                foreach (Channel ch in Presentation.ChannelsManager.ManagedObjects.ContentsAs_Enumerable)
                {
                    if (ch is T)
                    {
                        channel = ch as T;
                        break;
                    }
                }
                if (channel != null)
                {
                    Media med = chProp.GetMedia(channel);
                    return(med);
                }
            }
            return(null);
        }
Ejemplo n.º 11
0
        public void setPropertyAndCheckForNewValue()
        {
            TreeNode root = mProject.Presentations.Get(0).RootNode;

            if (mProject.Presentations.Get(0).ChannelsManager.ManagedObjects.Count == 0)
            {
                mProject.Presentations.Get(0).ChannelFactory.Create();
            }
            Channel textCh = mProject.Presentations.Get(0).ChannelsManager.ManagedObjects.Get(0);

            if (textCh != null)
            {
                ChannelsProperty text_cp;
                if (!root.HasProperties(typeof(ChannelsProperty)))
                {
                    text_cp = mProject.Presentations.Get(0).PropertyFactory.CreateChannelsProperty();
                }
                else
                {
                    text_cp = (ChannelsProperty)root.GetProperty(typeof(ChannelsProperty));
                }
                urakawa.media.AbstractTextMedia txt = mProject.Presentations.Get(0).MediaFactory.CreateTextMedia();
                txt.Text = "hello I am the new text for the root node";
                text_cp.SetMedia(textCh, txt);

                root.AddProperty(text_cp);

                ChannelsProperty root_cp =
                    (ChannelsProperty)mProject.Presentations.Get(0).RootNode.GetProperty(typeof(ChannelsProperty));
                urakawa.media.AbstractTextMedia txt2 =
                    (urakawa.media.AbstractTextMedia)root_cp.GetMedia(textCh);

                Assert.AreEqual(txt.Text, txt2.Text);
                Assert.AreEqual(txt, txt2);
            }
        }
Ejemplo n.º 12
0
        private void verifyTree(TreeNode node, bool ancestorHasAudio, string ancestorExtAudioFile)
        {
            if (TreeNodeMustBeSkipped(node))
            {
                return;
            }

            if (TreeNodeTriggersNewAudioFile(node) && ancestorExtAudioFile == null)
            {
                ancestorExtAudioFile = "";
            }

            Media manSeqMedia = node.GetManagedAudioMediaOrSequenceMedia();

            if (ancestorHasAudio)
            {
                DebugFix.Assert(manSeqMedia == null);
            }

            if (node.HasChannelsProperty)
            {
                ChannelsProperty chProp = node.GetChannelsProperty();
                Media            media  = chProp.GetMedia(DestinationChannel);

                if (ancestorHasAudio)
                {
                    DebugFix.Assert(media == null);
                }

                if (media != null)
                {
                    DebugFix.Assert(media is ExternalAudioMedia);
                    DebugFix.Assert(manSeqMedia != null);

                    if (!ancestorHasAudio)
                    {
                        ExternalAudioMedia extMedia = (ExternalAudioMedia)media;

                        ancestorHasAudio = true;

                        if (ancestorExtAudioFile != null)
                        {
                            if (ancestorExtAudioFile == "")
                            {
                                ancestorExtAudioFile = extMedia.Uri.LocalPath;
                            }
                            else
                            {
                                DebugFix.Assert(ancestorExtAudioFile == extMedia.Uri.LocalPath);
                            }
                        }
                        else
                        {
                            ancestorExtAudioFile = extMedia.Uri.LocalPath;
                        }

                        string ext = Path.GetExtension(ancestorExtAudioFile);
                        if (!DataProviderFactory.AUDIO_WAV_EXTENSION.Equals(ext, StringComparison.OrdinalIgnoreCase))
                        {
                            Debug.Fail("Verification can only be done if external media points to wav file!");
                        }

                        //reportProgress(-1, @"DEBUG: " + ancestorExtAudioFile);

                        Stream extMediaStream = new FileStream(ancestorExtAudioFile, FileMode.Open, FileAccess.Read,
                                                               FileShare.None);

                        Stream manMediaStream = null;

                        ManagedAudioMedia manMedia = node.GetManagedAudioMedia();

#if ENABLE_SEQ_MEDIA
                        SequenceMedia seqMedia = node.GetManagedAudioSequenceMedia();
#endif //ENABLE_SEQ_MEDIA

                        if (manMedia != null)
                        {
#if ENABLE_SEQ_MEDIA
                            DebugFix.Assert(seqMedia == null);
#endif //ENABLE_SEQ_MEDIA

                            DebugFix.Assert(manMedia.HasActualAudioMediaData);

                            manMediaStream = manMedia.AudioMediaData.OpenPcmInputStream();
                        }
                        else
                        {
                            Debug.Fail("SequenceMedia is normally removed at import time...have you tried re-importing the DAISY book ?");

#if ENABLE_SEQ_MEDIA
                            DebugFix.Assert(seqMedia != null);
                            DebugFix.Assert(!seqMedia.AllowMultipleTypes);
                            DebugFix.Assert(seqMedia.ChildMedias.Count > 0);
                            DebugFix.Assert(seqMedia.ChildMedias.Get(0) is ManagedAudioMedia);

                            manMediaStream = seqMedia.OpenPcmInputStreamOfManagedAudioMedia();
#endif //ENABLE_SEQ_MEDIA
                        }

                        try
                        {
                            uint extMediaPcmLength;
                            AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(extMediaStream,
                                                                                          out extMediaPcmLength);

                            DebugFix.Assert(extMediaPcmLength == extMediaStream.Length - extMediaStream.Position);

                            if (manMedia != null)
                            {
                                DebugFix.Assert(pcmInfo.IsCompatibleWith(manMedia.AudioMediaData.PCMFormat.Data));
                            }

#if ENABLE_SEQ_MEDIA
                            if (seqMedia != null)
                            {
                                DebugFix.Assert(
                                    pcmInfo.IsCompatibleWith(
                                        ((ManagedAudioMedia)seqMedia.ChildMedias.Get(0)).AudioMediaData.PCMFormat.Data));
                            }
#endif //ENABLE_SEQ_MEDIA

                            extMediaStream.Position +=
                                pcmInfo.ConvertTimeToBytes(extMedia.ClipBegin.AsLocalUnits);

                            long manMediaStreamPosBefore = manMediaStream.Position;
                            long extMediaStreamPosBefore = extMediaStream.Position;

                            //DebugFix.Assert(AudioLibPCMFormat.CompareStreamData(manMediaStream, extMediaStream, (int)manMediaStream.Length));

                            //DebugFix.Assert(manMediaStream.Position == manMediaStreamPosBefore + manMediaStream.Length);
                            //DebugFix.Assert(extMediaStream.Position == extMediaStreamPosBefore + manMediaStream.Length);
                        }
                        finally
                        {
                            extMediaStream.Close();
                            manMediaStream.Close();
                        }
                    }
                }
                else
                {
                    DebugFix.Assert(manSeqMedia == null);
                }
            }
            else
            {
                DebugFix.Assert(manSeqMedia == null);
            }

            foreach (TreeNode child in node.Children.ContentsAs_Enumerable)
            {
                verifyTree(child, ancestorHasAudio, ancestorExtAudioFile);
            }
        }
Ejemplo n.º 13
0
        private static void CheckPublishedFiles(TreeNode node, Channel sourceCh, Channel destCh,
                                                Uri curWavUri_, MemoryStream curAudioData, PCMFormatInfo curPCMFormat)
        {
            Uri curWavUri = (curWavUri_ == null ? null : new Uri(curWavUri_.ToString()));

            if (node.HasProperties(typeof(ChannelsProperty)))
            {
                ChannelsProperty   chProp = node.GetProperty <ChannelsProperty>();
                ManagedAudioMedia  mam    = chProp.GetMedia(sourceCh) as ManagedAudioMedia;
                ExternalAudioMedia eam    = chProp.GetMedia(destCh) as ExternalAudioMedia;

                Assert.AreEqual(mam == null, eam == null,
                                "There may be external audio media if and only if there is managed audio media");

                if (mam != null && eam != null)
                {
                    Assert.IsTrue(mam.Duration.IsEqualTo(eam.Duration),
                                  "Duration of managed and external audio media differs");

                    if (eam.Uri != null)
                    {
                        FileStream wavFS_         = new FileStream(eam.Uri.LocalPath, FileMode.Open, FileAccess.Read, FileShare.None);
                        Stream     manAudioStream = mam.AudioMediaData.OpenPcmInputStream();
                        try
                        {
                            uint dataLength;
                            AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavFS_, out dataLength);

                            Assert.IsTrue(pcmInfo.IsCompatibleWith(mam.AudioMediaData.PCMFormat.Data),
                                          "External audio has incompatible pcm format");

                            wavFS_.Position += pcmInfo.ConvertTimeToBytes(eam.ClipBegin.TimeAsMillisecondFloat);

                            Assert.IsTrue(
                                AudioLibPCMFormat.CompareStreamData(manAudioStream, wavFS_, (int)manAudioStream.Length),
                                "External audio contains wrong data");
                        }
                        finally
                        {
                            wavFS_.Close();
                            manAudioStream.Close();
                        }
                    }

                    if (curWavUri != null)
                    {
                        FileStream wavFS = new FileStream(curWavUri.LocalPath, FileMode.Open, FileAccess.Read,
                                                          FileShare.None);
                        try
                        {
                            uint dataLength;
                            AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavFS, out dataLength);

                            Assert.IsTrue(pcmInfo.IsCompatibleWith(curPCMFormat.Data),
                                          "External audio has incompatible pcm format");

                            curAudioData.Position = 0;

                            Assert.AreEqual(curAudioData.Length, (long)dataLength,
                                            "External audio has unexpected length");
                            Assert.IsTrue(
                                AudioLibPCMFormat.CompareStreamData(curAudioData, wavFS, (int)curAudioData.Length),
                                "External audio contains wrong data");
                        }
                        finally
                        {
                            wavFS.Close();
                        }
                    }

                    if (curWavUri == null)
                    {
                        curWavUri    = new Uri(eam.Uri.ToString());
                        curAudioData = new MemoryStream();
                        curPCMFormat = mam.AudioMediaData.PCMFormat;
                    }
                    else if (curWavUri.ToString() != eam.Uri.ToString())
                    {
                        curWavUri    = new Uri(eam.Uri.ToString());
                        curAudioData = new MemoryStream();
                        curPCMFormat = mam.AudioMediaData.PCMFormat;
                    }

                    Assert.IsTrue(curPCMFormat.ValueEquals(mam.AudioMediaData.PCMFormat),
                                  "Managed audio has incompatible pcm format");

                    Stream manAudio = mam.AudioMediaData.OpenPcmInputStream();
                    try
                    {
                        media.data.StreamUtils.CopyData(manAudio, curAudioData);
                    }
                    finally
                    {
                        manAudio.Close();
                    }
                }
            }
            foreach (TreeNode child in node.Children.ContentsAs_YieldEnumerable)
            {
                CheckPublishedFiles(child, sourceCh, destCh, curWavUri, curAudioData, curPCMFormat);
            }
        }
Ejemplo n.º 14
0
        protected void addAudio(TreeNode treeNode, XmlNode xmlNode, bool isSequence, string fullSmilPath)
        {
            if (RequestCancellation)
            {
                return;
            }

            string dirPath = Path.GetDirectoryName(fullSmilPath);

            XmlAttributeCollection audioAttrs = xmlNode.Attributes;

            if (audioAttrs == null || audioAttrs.Count == 0)
            {
                return;
            }
            XmlNode audioAttrSrc = audioAttrs.GetNamedItem("src");

            if (audioAttrSrc == null || String.IsNullOrEmpty(audioAttrSrc.Value))
            {
                return;
            }

            string src = FileDataProvider.UriDecode(audioAttrSrc.Value);

            XmlNode audioAttrClipBegin = audioAttrs.GetNamedItem("clipBegin");
            XmlNode audioAttrClipEnd   = audioAttrs.GetNamedItem("clipEnd");

            Presentation      presentation = treeNode.Presentation; // m_Project.Presentations.Get(0);
            ManagedAudioMedia media        = null;



            string fullPath = Path.Combine(dirPath, src);

            fullPath = FileDataProvider.NormaliseFullFilePath(fullPath).Replace('/', '\\');
            addOPF_GlobalAssetPath(fullPath);

            string ext = Path.GetExtension(src);


            if (ext.Equals(DataProviderFactory.AUDIO_WAV_EXTENSION, StringComparison.OrdinalIgnoreCase))
            {
                FileDataProvider dataProv = null;

                if (!File.Exists(fullPath))
                {
                    Debug.Fail("File not found: " + fullPath);
                    media = null;
                }
                else
                {
                    //bool deleteSrcAfterCompletion = false;

                    string fullWavPath = fullPath;

                    FileDataProvider obj;
                    m_OriginalAudioFile_FileDataProviderMap.TryGetValue(fullWavPath, out obj);

                    if (obj != null)  //m_OriginalAudioFile_FileDataProviderMap.ContainsKey(fullWavPath))
                    {
                        if (m_AudioConversionSession.FirstDiscoveredPCMFormat == null)
                        {
                            DebugFix.Assert(obj.Presentation != presentation);

                            Object appData = obj.AppData;

                            DebugFix.Assert(appData != null);

                            if (appData != null && appData is WavClip.PcmFormatAndTime)
                            {
                                m_AudioConversionSession.FirstDiscoveredPCMFormat = new AudioLibPCMFormat();
                                m_AudioConversionSession.FirstDiscoveredPCMFormat.CopyFrom(((WavClip.PcmFormatAndTime)appData).mFormat);
                            }
                        }

                        if (obj.Presentation != presentation)
                        {
                            dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);


                            reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.CopyingAudio, Path.GetFileName(obj.DataFileFullPath)));


                            dataProv.InitByCopyingExistingFile(obj.DataFileFullPath);

                            //m_AudioConversionSession.RelocateDestinationFilePath(newfullWavPath, dataProv.DataFileFullPath);

                            m_OriginalAudioFile_FileDataProviderMap.Remove(fullWavPath);
                            m_OriginalAudioFile_FileDataProviderMap.Add(fullWavPath, dataProv);

                            Object appData = obj.AppData;

                            DebugFix.Assert(appData != null);

                            if (appData != null && appData is WavClip.PcmFormatAndTime)
                            {
                                dataProv.AppData = new WavClip.PcmFormatAndTime(((WavClip.PcmFormatAndTime)appData).mFormat, ((WavClip.PcmFormatAndTime)appData).mTime);
                            }
                        }
                        else
                        {
                            dataProv = obj; // m_OriginalAudioFile_FileDataProviderMap[fullWavPath];
                        }
                    }
                    else // create FileDataProvider
                    {
                        Stream wavStream = null;
                        try
                        {
                            wavStream = File.Open(fullWavPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                            uint dataLength;
                            AudioLibPCMFormat pcmInfo = null;

                            pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength);

                            if (m_AudioConversionSession.FirstDiscoveredPCMFormat == null)
                            {
                                //m_AudioConversionSession.FirstDiscoveredPCMFormat = new PCMFormatInfo(pcmInfo);
                                m_AudioConversionSession.FirstDiscoveredPCMFormat = new AudioLibPCMFormat();
                                m_AudioConversionSession.FirstDiscoveredPCMFormat.CopyFrom(pcmInfo);
                            }


                            if (RequestCancellation)
                            {
                                return;
                            }

                            //if (m_firstTimePCMFormat)
                            //{
                            //    presentation.MediaDataManager.DefaultPCMFormat = new PCMFormatInfo(pcmInfo);
                            //    m_firstTimePCMFormat = false;
                            //}

                            if (!presentation.MediaDataManager.DefaultPCMFormat.Data.IsCompatibleWith(pcmInfo))
                            {
                                wavStream.Close();
                                wavStream = null;

                                reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.ConvertingAudio, Path.GetFileName(fullWavPath)));
                                string newfullWavPath = m_AudioConversionSession.ConvertAudioFileFormat(fullWavPath);

                                if (RequestCancellation)
                                {
                                    return;
                                }



                                dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                                //Console.WriteLine("Source audio file to SDK audio file map (before creating SDK audio file): " + Path.GetFileName(fullWavPath) + " = " + dataProv.DataFileRelativePath);
                                dataProv.InitByMovingExistingFile(newfullWavPath);

                                m_AudioConversionSession.RelocateDestinationFilePath(newfullWavPath, dataProv.DataFileFullPath);

                                m_OriginalAudioFile_FileDataProviderMap.Add(fullWavPath, dataProv);

                                if (RequestCancellation)
                                {
                                    return;
                                }
                            }
                            else // use original wav file by copying it to data directory
                            {
                                dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                                //Console.WriteLine("Source audio file to SDK audio file map (before creating SDK audio file): " + Path.GetFileName(fullWavPath) + " = " + dataProv.DataFileRelativePath);
                                reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.CopyingAudio, Path.GetFileName(fullWavPath)));
                                dataProv.InitByCopyingExistingFile(fullWavPath);
                                m_OriginalAudioFile_FileDataProviderMap.Add(fullWavPath, dataProv);

                                if (RequestCancellation)
                                {
                                    return;
                                }
                            }
                        }
                        finally
                        {
                            if (wavStream != null)
                            {
                                wavStream.Close();
                            }
                        }
                    }
                } // FileDataProvider  key check ends

                if (RequestCancellation)
                {
                    return;
                }

                media = addAudioWav(dataProv, audioAttrClipBegin, audioAttrClipEnd, treeNode);
                //media = addAudioWav ( fullWavPath, deleteSrcAfterCompletion, audioAttrClipBegin, audioAttrClipEnd );
            }
            else if (ext.Equals(DataProviderFactory.AUDIO_MP3_EXTENSION, StringComparison.OrdinalIgnoreCase) ||
                     ext.Equals(DataProviderFactory.AUDIO_MP4_EXTENSION, StringComparison.OrdinalIgnoreCase) ||
                     ext.Equals(DataProviderFactory.AUDIO_MP4_EXTENSION_, StringComparison.OrdinalIgnoreCase))
            {
                if (!File.Exists(fullPath))
                {
                    Debug.Fail("File not found: {0}", fullPath);
                    return;
                }

                if (RequestCancellation)
                {
                    return;
                }

                reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.DecodingAudio, Path.GetFileName(fullPath)));


                if (RequestCancellation)
                {
                    return;
                }

                string fullMp34PathOriginal = fullPath;

                FileDataProvider obj;
                m_OriginalAudioFile_FileDataProviderMap.TryGetValue(fullMp34PathOriginal, out obj);

                FileDataProvider dataProv = null;
                if (obj != null) //m_OriginalAudioFile_FileDataProviderMap.ContainsKey(fullMp3PathOriginal))
                {
                    if (m_AudioConversionSession.FirstDiscoveredPCMFormat == null)
                    {
                        DebugFix.Assert(obj.Presentation != presentation);

                        Object appData = obj.AppData;

                        DebugFix.Assert(appData != null);

                        if (appData != null && appData is WavClip.PcmFormatAndTime)
                        {
                            m_AudioConversionSession.FirstDiscoveredPCMFormat = new AudioLibPCMFormat();
                            m_AudioConversionSession.FirstDiscoveredPCMFormat.CopyFrom(((WavClip.PcmFormatAndTime)appData).mFormat);
                        }
                    }

                    if (obj.Presentation != presentation)
                    {
                        dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);

                        reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.CopyingAudio, Path.GetFileName(obj.DataFileFullPath)));

                        dataProv.InitByCopyingExistingFile(obj.DataFileFullPath);

                        //m_AudioConversionSession.RelocateDestinationFilePath(newfullWavPath, dataProv.DataFileFullPath);

                        m_OriginalAudioFile_FileDataProviderMap.Remove(fullMp34PathOriginal);
                        m_OriginalAudioFile_FileDataProviderMap.Add(fullMp34PathOriginal, dataProv);

                        Object appData = obj.AppData;

                        DebugFix.Assert(appData != null);

                        if (appData != null && appData is WavClip.PcmFormatAndTime)
                        {
                            dataProv.AppData = new WavClip.PcmFormatAndTime(((WavClip.PcmFormatAndTime)appData).mFormat, ((WavClip.PcmFormatAndTime)appData).mTime);
                        }
                    }
                    else
                    {
                        dataProv = obj; // m_OriginalAudioFile_FileDataProviderMap[fullMp3PathOriginal];
                    }
                }
                else
                {
                    string newfullWavPath = m_AudioConversionSession.ConvertAudioFileFormat(fullMp34PathOriginal);

                    dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                    //Console.WriteLine("Source audio file to SDK audio file map (before creating SDK audio file): " + Path.GetFileName(fullMp34PathOriginal) + " = " + dataProv.DataFileRelativePath);
                    dataProv.InitByMovingExistingFile(newfullWavPath);

                    m_AudioConversionSession.RelocateDestinationFilePath(newfullWavPath, dataProv.DataFileFullPath);

                    m_OriginalAudioFile_FileDataProviderMap.Add(fullMp34PathOriginal, dataProv);

                    if (RequestCancellation)
                    {
                        return;
                    }
                }

                if (dataProv != null)
                {
                    //if (m_firstTimePCMFormat)
                    //{
                    //    Stream wavStream = null;
                    //    try
                    //    {
                    //        wavStream = File.Open(newfullWavPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                    //        uint dataLength;
                    //        AudioLibPCMFormat pcmInfo = null;

                    //        pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength);

                    //        presentation.MediaDataManager.DefaultPCMFormat = new PCMFormatInfo(pcmInfo);
                    //    }
                    //    finally
                    //    {
                    //        if (wavStream != null) wavStream.Close();
                    //        m_firstTimePCMFormat = false;
                    //    }
                    //}

                    if (RequestCancellation)
                    {
                        return;
                    }

                    //media = addAudioWav(newfullWavPath, true, audioAttrClipBegin, audioAttrClipEnd);
                    media = addAudioWav(dataProv, audioAttrClipBegin, audioAttrClipEnd, treeNode);

                    if (RequestCancellation)
                    {
                        return;
                    }

                    if (media == null)
                    {
#if DEBUG
                        Debugger.Break();
#endif
                    }
                }
                //}
            }

            if (RequestCancellation)
            {
                return;
            }

            if (media == null)
            {
                if (!TreenodesWithoutManagedAudioMediaData.Contains(treeNode))
                {
                    TreenodesWithoutManagedAudioMediaData.Add(treeNode);
                }

                Debug.Fail("Creating ExternalAudioMedia ??");

                Time timeClipBegin = null;

                ExternalAudioMedia exmedia = presentation.MediaFactory.CreateExternalAudioMedia();
                exmedia.Src = src;
                if (audioAttrClipBegin != null &&
                    !string.IsNullOrEmpty(audioAttrClipBegin.Value))
                {
                    timeClipBegin = new Time();
                    try
                    {
                        timeClipBegin = new Time(audioAttrClipBegin.Value);
                    }
                    catch (Exception ex)
                    {
                        string str = "CLIP BEGIN TIME PARSE FAIL: " + audioAttrClipBegin.Value;
                        Console.WriteLine(str);
                        Debug.Fail(str);
                    }
                    exmedia.ClipBegin = timeClipBegin;
                }
                if (audioAttrClipEnd != null &&
                    !string.IsNullOrEmpty(audioAttrClipEnd.Value))
                {
                    Time timeClipEnd = null;
                    try
                    {
                        timeClipEnd = new Time(audioAttrClipEnd.Value);
                    }
                    catch (Exception ex)
                    {
                        string str = "CLIP END TIME PARSE FAIL: " + audioAttrClipEnd.Value;
                        Console.WriteLine(str);
                        Debug.Fail(str);
                    }

                    if (timeClipEnd != null)
                    {
                        try
                        {
                            exmedia.ClipEnd = timeClipEnd;
                        }
                        catch (Exception ex)
                        {
                            string str = "CLIP TIME ERROR (end < begin): " + timeClipBegin + " (" + (audioAttrClipBegin != null ? audioAttrClipBegin.Value : "N/A") + ") / " + timeClipEnd + " (" + audioAttrClipEnd.Value + ")";
                            Console.WriteLine(str);
                            //Debug.Fail(str);
                        }
                    }
                }
            }

            if (RequestCancellation)
            {
                return;
            }

            if (media != null)
            {
                ChannelsProperty chProp =
                    treeNode.GetChannelsProperty();
                if (chProp == null)
                {
                    chProp =
                        presentation.PropertyFactory.CreateChannelsProperty();
                    treeNode.AddProperty(chProp);
                }
                if (isSequence)
                {
#if ENABLE_SEQ_MEDIA
                    SequenceMedia mediaSeq = chProp.GetMedia(m_audioChannel) as SequenceMedia;
                    if (mediaSeq == null)
                    {
                        mediaSeq = presentation.MediaFactory.CreateSequenceMedia();
                        mediaSeq.AllowMultipleTypes = false;
                        chProp.SetMedia(m_audioChannel, mediaSeq);
                    }
                    mediaSeq.ChildMedias.Insert(mediaSeq.ChildMedias.Count, media);
#else
                    ManagedAudioMedia existingMedia = chProp.GetMedia(presentation.ChannelsManager.GetOrCreateAudioChannel()) as ManagedAudioMedia;
                    if (existingMedia == null)
                    {
                        chProp.SetMedia(presentation.ChannelsManager.GetOrCreateAudioChannel(), media);
                    }
                    else
                    {
                        // WARNING: WavAudioMediaData implementation differs from AudioMediaData:
                        // the latter is naive and performs a stream binary copy, the latter is optimized and re-uses existing WavClips.
                        //  WARNING 2: The audio data from the given parameter gets emptied !
                        existingMedia.AudioMediaData.MergeWith(media.AudioMediaData);

                        //Stream stream = seqManMedia.AudioMediaData.OpenPcmInputStream();
                        //try
                        //{
                        //    mediaData.AppendPcmData(stream, null);
                        //}
                        //finally
                        //{
                        //    stream.Close();
                        //}
                    }
#endif //ENABLE_SEQ_MEDIA
                }
                else
                {
                    //#if DEBUG
                    //                    ((WavAudioMediaData) media.AudioMediaData).checkWavClips();
                    //#endif //DEBUG
                    chProp.SetMedia(presentation.ChannelsManager.GetOrCreateAudioChannel(), media);
                }
            }
            else
            {
                Debug.Fail("Media could not be created !");
            }
        }
Ejemplo n.º 15
0
        public override bool PreVisit(TreeNode node)
        {
            if (m_RootNode == null)
            {
                m_RootNode = node;
            }

            if (TreeNodeMustBeSkipped(node))
            {
                return(false);
            }
            if (TreeNodeTriggersNewAudioFile(node))
            {
                createNextAudioFile(node);
            }

            if (node.HasProperties(typeof(ChannelsProperty)))
            {
                ChannelsProperty chProp = node.GetChannelsProperty();

                ManagedAudioMedia mam = chProp.GetMedia(SourceChannel) as ManagedAudioMedia;
                if (mam != null)
                {
                    AudioMediaData amd = mam.AudioMediaData;

                    if (mCurrentAudioFileStream == null)
                    {
                        createNextAudioFile(node);
                    }
                    else if (mCurrentAudioFilePCMFormat != null &&
                             !mCurrentAudioFilePCMFormat.Data.IsCompatibleWith(amd.PCMFormat.Data))
                    {
#if DEBUG
                        Debugger.Break();
#endif
                        createNextAudioFile(node);
                    }

                    if (mCurrentAudioFileStream != null && mCurrentAudioFilePCMFormat == null)
                    {
                        writeInitialHeader(amd.PCMFormat);
                    }

                    Time durationFromRiffHeader = amd.AudioDuration;

                    Time clipBegin = new Time(mCurrentAudioFilePCMFormat.Data.ConvertBytesToTime(mCurrentAudioFileStream.Position - mCurrentAudioFileStreamRiffWaveHeaderLength));
                    Time clipEnd   = new Time(clipBegin.AsTimeSpanTicks + durationFromRiffHeader.AsTimeSpanTicks, true);

                    //BinaryReader rd = new BinaryReader(stream);

                    Stream stream = amd.OpenPcmInputStream();
                    try
                    {
                        const uint BUFFER_SIZE = 1024 * 1024 * 3; // 3 MB MAX BUFFER
                        StreamUtils.Copy(stream, 0, mCurrentAudioFileStream, BUFFER_SIZE);
                    }
                    finally
                    {
                        stream.Close();
                    }

                    ExternalAudioMedia eam = node.Presentation.MediaFactory.Create <ExternalAudioMedia>();
                    if (eam == null)
                    {
                        throw new exception.FactoryCannotCreateTypeException(String.Format(
                                                                                 "The media facotry cannot create a ExternalAudioMedia matching QName {1}:{0}",

                                                                                 XukAble.GetXukName(typeof(ExternalAudioMedia), true) ?? typeof(ExternalAudioMedia).Name,
                                                                                 node.Presentation.Project.GetXukNamespace()));
                    }

                    eam.Language  = mam.Language;
                    eam.Src       = node.Presentation.RootUri.MakeRelativeUri(GetCurrentAudioFileUri()).ToString();
                    eam.ClipBegin = clipBegin;
                    eam.ClipEnd   = clipEnd;

                    if (chProp.GetMedia(DestinationChannel) != null)
                    {
#if DEBUG
                        Debugger.Break();
#endif
                        chProp.SetMedia(DestinationChannel, null);
                    }
                    chProp.SetMedia(DestinationChannel, eam);
                }
            }
            return(true);
        }
Ejemplo n.º 16
0
        public override bool PreVisit(TreeNode node)
        {
            if (m_RootNode == null)
            {
                m_RootNode = node;
            }

            if (m_currentAudioLevelNode == null)
            {
                m_currentAudioLevelNode = m_RootNode;
            }

            if (TreeNodeMustBeSkipped(node))
            {
                return(false);
            }

            if (RequestCancellation)
            {
                checkTransientWavFileAndClose(node);
                return(false);
            }


            if (TreeNodeTriggersNewAudioFile(node))
            {
                m_currentAudioLevelNode = node;

                checkTransientWavFileAndClose(node);
                // REMOVED, because doesn't support nested TreeNode matches ! return false; // skips children, see postVisit
            }

            if (node.GetAlternateContentProperty() != null)
            {
                m_AlternateContentPropertiesList.Add(node.GetAlternateContentProperty());
            }

            if (!node.HasChannelsProperty)
            {
                return(true);
            }

            if (!node.Presentation.MediaDataManager.EnforceSinglePCMFormat)
            {
                Debug.Fail("! EnforceSinglePCMFormat ???");
                throw new Exception("! EnforceSinglePCMFormat ???");
            }

#if ENABLE_SEQ_MEDIA
            Media media = node.GetManagedAudioMediaOrSequenceMedia();

            if (media == null)
            {
                return(true);
            }
#endif


            ManagedAudioMedia manAudioMedia = node.GetManagedAudioMedia();
            if (manAudioMedia == null)
            {
                return(true);
            }

            //if (!manAudioMedia.HasActualAudioMediaData)
            //{
            //    return true;
            //}

            if (m_TransientWavFileStream == null)
            {
                mCurrentAudioFileNumber++;
                Uri waveFileUri = GetCurrentAudioFileUri();
                m_TransientWavFileStream = new FileStream(waveFileUri.LocalPath, FileMode.Create, FileAccess.Write, FileShare.None);

                m_TransientWavFileStreamRiffOffset = node.Presentation.MediaDataManager.DefaultPCMFormat.Data.RiffHeaderWrite(m_TransientWavFileStream, 0);
            }

            long bytesBegin = m_TransientWavFileStream.Position - (long)m_TransientWavFileStreamRiffOffset;

#if ENABLE_SEQ_MEDIA
            SequenceMedia seqAudioMedia = node.GetManagedAudioSequenceMedia();
#endif //ENABLE_SEQ_MEDIA

            Stream audioPcmStream = null;
            if (manAudioMedia != null)
            {
                audioPcmStream = manAudioMedia.AudioMediaData.OpenPcmInputStream();
            }
#if ENABLE_SEQ_MEDIA
            else if (seqAudioMedia != null)
            {
                Debug.Fail("SequenceMedia is normally removed at import time...have you tried re-importing the DAISY book ?");

                audioPcmStream = seqAudioMedia.OpenPcmInputStreamOfManagedAudioMedia();
            }
#endif //ENABLE_SEQ_MEDIA
            else
            {
                Debug.Fail("This should never happen !!");
                return(false);
            }

            if (RequestCancellation)
            {
                checkTransientWavFileAndClose(node);
                return(false);
            }

            try
            {
                const uint BUFFER_SIZE = 1024 * 1024 * 3; // 3 MB MAX BUFFER
                uint       streamCount = StreamUtils.Copy(audioPcmStream, 0, m_TransientWavFileStream, BUFFER_SIZE);

                //System.Windows.Forms.MessageBox.Show ( audioPcmStream.Length.ToString () + " : " +  m_TransientWavFileStream.Length.ToString () + " : " + streamCount.ToString () );
            }
            catch
            {
                m_TransientWavFileStream.Close();
                m_TransientWavFileStream           = null;
                m_TransientWavFileStreamRiffOffset = 0;

#if DEBUG
                Debugger.Break();
#endif
            }
            finally
            {
                audioPcmStream.Close();
            }

            if (m_TransientWavFileStream == null)
            {
                Debug.Fail("Stream copy error !!");
                return(false);
            }

            long bytesEnd = m_TransientWavFileStream.Position - (long)m_TransientWavFileStreamRiffOffset;

            string src = node.Presentation.RootUri.MakeRelativeUri(GetCurrentAudioFileUri()).ToString();

            if (manAudioMedia != null
#if ENABLE_SEQ_MEDIA
                || seqAudioMedia != null
#endif //ENABLE_SEQ_MEDIA
                )
            {
                if (m_TotalTimeInLocalUnits == 0)
                {
                    Time dur = node.Root.GetDurationOfManagedAudioMediaFlattened();
                    if (dur != null)
                    {
                        m_TotalTimeInLocalUnits = dur.AsLocalUnits;
                    }
                }

                m_TimeElapsedInLocalUnits += manAudioMedia != null ? manAudioMedia.Duration.AsLocalUnits :
#if ENABLE_SEQ_MEDIA
                                             seqAudioMedia.GetDurationOfManagedAudioMedia().AsLocalUnits
#else
                                             -1
#endif //ENABLE_SEQ_MEDIA
                ;

                int percent = Convert.ToInt32((m_TimeElapsedInLocalUnits * 100) / m_TotalTimeInLocalUnits);

                if (EncodePublishedAudioFiles)
                {
                    reportProgress_Throttle(percent, String.Format(UrakawaSDK_daisy_Lang.CreateMP3File, Path.GetFileName(src).Replace(DataProviderFactory.AUDIO_WAV_EXTENSION, DataProviderFactory.AUDIO_MP3_EXTENSION), GetSizeInfo(node)));
                }
                else
                {
                    reportProgress_Throttle(percent, String.Format(UrakawaSDK_daisy_Lang.CreatingAudioFile, Path.GetFileName(src), GetSizeInfo(node)));
                }
                //Console.WriteLine("progress percent " + m_ProgressPercentage);
            }

            ExternalAudioMedia extAudioMedia = node.Presentation.MediaFactory.Create <ExternalAudioMedia>();
            extAudioMedia.Tag = m_currentAudioLevelNode;

            ushort nChannels = (ushort)(EncodePublishedAudioFilesStereo ? 2 : 1);
            if ((EncodePublishedAudioFiles
                 ||
                 (ushort)EncodePublishedAudioFilesSampleRate != node.Presentation.MediaDataManager.DefaultPCMFormat.Data.SampleRate ||
                 nChannels != node.Presentation.MediaDataManager.DefaultPCMFormat.Data.NumberOfChannels
                 ) &&
                !m_ExternalAudioMediaList.Contains(extAudioMedia))
            {
                m_ExternalAudioMediaList.Add(extAudioMedia);
            }

            extAudioMedia.Language = node.Presentation.Language;
            extAudioMedia.Src      = src;

            long timeBegin =
                node.Presentation.MediaDataManager.DefaultPCMFormat.Data.ConvertBytesToTime(bytesBegin);
            long timeEnd =
                node.Presentation.MediaDataManager.DefaultPCMFormat.Data.ConvertBytesToTime(bytesEnd);
            extAudioMedia.ClipBegin = new Time(timeBegin);
            extAudioMedia.ClipEnd   = new Time(timeEnd);

            ChannelsProperty chProp = node.GetChannelsProperty();
            if (chProp.GetMedia(DestinationChannel) != null)
            {
                chProp.SetMedia(DestinationChannel, null);
                Debug.Fail("This should never happen !!");
            }
            chProp.SetMedia(DestinationChannel, extAudioMedia);

            return(false);
        }
Ejemplo n.º 17
0
        private void addAudio(TreeNode treeNode, XmlNode xmlNode, bool isSequence, string fullSmilPath)
        {
            string dirPath = Path.GetDirectoryName(fullSmilPath);

            XmlAttributeCollection audioAttrs = xmlNode.Attributes;

            if (audioAttrs == null || audioAttrs.Count == 0)
            {
                return;
            }
            XmlNode audioAttrSrc = audioAttrs.GetNamedItem("src");

            if (audioAttrSrc == null || String.IsNullOrEmpty(audioAttrSrc.Value))
            {
                return;
            }
            XmlNode audioAttrClipBegin = audioAttrs.GetNamedItem("clipBegin");
            XmlNode audioAttrClipEnd   = audioAttrs.GetNamedItem("clipEnd");

            Presentation presentation = m_Project.Presentations.Get(0);
            Media        media        = null;

            if (audioAttrSrc.Value.EndsWith("wav"))
            {
                string           dirPathBook         = Path.GetDirectoryName(m_Book_FilePath);
                FileDataProvider dataProv            = null;
                string           fullWavPathOriginal = Path.Combine(dirPathBook, audioAttrSrc.Value);
                if (!File.Exists(fullWavPathOriginal))
                {
                    System.Diagnostics.Debug.Fail("File not found: {0}", fullWavPathOriginal);
                    media = null;
                }
                else
                {
                    //bool deleteSrcAfterCompletion = false;

                    string fullWavPath = fullWavPathOriginal;

                    uint dataLength;
                    AudioLibPCMFormat pcmInfo = null;

                    if (m_OriginalAudioFile_FileDataProviderMap.ContainsKey(fullWavPath))
                    {
                        dataProv = m_OriginalAudioFile_FileDataProviderMap[fullWavPath];
                    }
                    else // create FileDataProvider
                    {
                        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;
                            //}

                            if (!presentation.MediaDataManager.DefaultPCMFormat.Data.IsCompatibleWith(pcmInfo))
                            {
                                wavStream.Close();
                                wavStream = null;

                                string newfullWavPath = m_AudioConversionSession.ConvertAudioFileFormat(fullWavPath);

                                dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                                Console.WriteLine("Source audio file to SDK audio file map (before creating SDK audio file): " + Path.GetFileName(fullWavPath) + " = " + dataProv.DataFileRelativePath);
                                dataProv.InitByMovingExistingFile(newfullWavPath);
                                m_OriginalAudioFile_FileDataProviderMap.Add(fullWavPath, dataProv);
                            }
                            else // use original wav file by copying it to data directory
                            {
                                dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                                Console.WriteLine("Source audio file to SDK audio file map (before creating SDK audio file): " + Path.GetFileName(fullWavPath) + " = " + dataProv.DataFileRelativePath);
                                dataProv.InitByCopyingExistingFile(fullWavPath);
                                m_OriginalAudioFile_FileDataProviderMap.Add(fullWavPath, dataProv);
                            }
                        }
                        finally
                        {
                            if (wavStream != null)
                            {
                                wavStream.Close();
                            }
                        }
                    }
                } // FileDataProvider  key check ends

                media = addAudioWav(dataProv, audioAttrClipBegin, audioAttrClipEnd);
                //media = addAudioWav ( fullWavPath, deleteSrcAfterCompletion, audioAttrClipBegin, audioAttrClipEnd );
            }
            else if (audioAttrSrc.Value.EndsWith("mp3"))
            {
                string fullMp3PathOriginal = Path.Combine(dirPath, audioAttrSrc.Value);
                if (!File.Exists(fullMp3PathOriginal))
                {
                    System.Diagnostics.Debug.Fail("File not found: {0}", fullMp3PathOriginal);
                    return;
                }

                string newfullWavPath = m_AudioConversionSession.ConvertAudioFileFormat(fullMp3PathOriginal);

                FileDataProvider dataProv = null;
                if (m_OriginalAudioFile_FileDataProviderMap.ContainsKey(fullMp3PathOriginal))
                {
                    dataProv = m_OriginalAudioFile_FileDataProviderMap[fullMp3PathOriginal];
                }
                else
                {
                    dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                    Console.WriteLine("Source audio file to SDK audio file map (before creating SDK audio file): " + Path.GetFileName(fullMp3PathOriginal) + " = " + dataProv.DataFileRelativePath);
                    dataProv.InitByMovingExistingFile(newfullWavPath);
                    m_OriginalAudioFile_FileDataProviderMap.Add(fullMp3PathOriginal, dataProv);
                }

                if (newfullWavPath != null)
                {
                    //if (m_firstTimePCMFormat)
                    //{
                    //    Stream wavStream = null;
                    //    try
                    //    {
                    //        wavStream = File.Open(newfullWavPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                    //        uint dataLength;
                    //        AudioLibPCMFormat pcmInfo = null;

                    //        pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength);

                    //        presentation.MediaDataManager.DefaultPCMFormat = new PCMFormatInfo(pcmInfo);
                    //    }
                    //    finally
                    //    {
                    //        if (wavStream != null) wavStream.Close();
                    //        m_firstTimePCMFormat = false;
                    //    }
                    //}


                    //media = addAudioWav(newfullWavPath, true, audioAttrClipBegin, audioAttrClipEnd);
                    media = addAudioWav(dataProv, audioAttrClipBegin, audioAttrClipEnd);
                }
                //}
            }

            if (media == null)
            {
                media = presentation.MediaFactory.CreateExternalAudioMedia();
                ((ExternalAudioMedia)media).Src = audioAttrSrc.Value;
                if (audioAttrClipBegin != null &&
                    !string.IsNullOrEmpty(audioAttrClipBegin.Value))
                {
                    try
                    {
                        ((ExternalAudioMedia)media).ClipBegin =
                            Time.ParseTimeString(audioAttrClipBegin.Value);
                    }
                    catch (FormatException e)
                    {
                        ((ExternalAudioMedia)media).ClipBegin =
                            new Time(0);
                        string str = "bad time string: " + audioAttrClipBegin.Value;
                        Console.Write(str);
                        Debug.Fail(str);
                    }
                }
                if (audioAttrClipEnd != null &&
                    !string.IsNullOrEmpty(audioAttrClipEnd.Value))
                {
                    try
                    {
                        ((ExternalAudioMedia)media).ClipEnd =
                            Time.ParseTimeString(audioAttrClipEnd.Value);
                    }
                    catch (FormatException e)
                    {
                        ((ExternalAudioMedia)media).ClipEnd =
                            new Time(0);
                        string str = "bad time string: " + audioAttrClipEnd.Value;
                        Console.Write(str);
                        Debug.Fail(str);
                    }
                }
            }

            if (media != null)
            {
                ChannelsProperty chProp =
                    treeNode.GetProperty <ChannelsProperty>();
                if (chProp == null)
                {
                    chProp =
                        presentation.PropertyFactory.CreateChannelsProperty();
                    treeNode.AddProperty(chProp);
                }
                if (isSequence)
                {
                    SequenceMedia mediaSeq = chProp.GetMedia(m_audioChannel) as SequenceMedia;
                    if (mediaSeq == null)
                    {
                        mediaSeq = presentation.MediaFactory.CreateSequenceMedia();
                        mediaSeq.AllowMultipleTypes = false;
                        chProp.SetMedia(m_audioChannel, mediaSeq);
                    }
                    mediaSeq.ChildMedias.Insert(mediaSeq.ChildMedias.Count, media);
                }
                else
                {
                    chProp.SetMedia(m_audioChannel, media);
                }
            }
            else
            {
                System.Diagnostics.Debug.Fail("Media could not be created !");
            }
        }