示例#1
0
        public void InsertAsset(IAudioMediaAsset chunk, double time)
        {
// checks if audio formats of original asset and chunk asset are of same formats
            if (CompareAudioAssetFormat(this, chunk) == true && time <= m_dAudioLengthInTime && time >= 0)
            {
                // creates the temporary blank asset
                AudioMediaAsset ob1 = new AudioMediaAsset(this.Channels, this.BitDepth, this.SampleRate);

                // if Chunk is to be inserted somewhere in between of original asset
                if (time > -0 && time < m_dAudioLengthInTime)
                {
                    // copies part of original asset before insertion time to temporary ob1 asset
                    ob1 = GetChunk(0, time) as AudioMediaAsset;
                    // merges the chunk to temp ob1 asset
                    ob1.MergeWith(chunk);
//					copies part of original assetafter insertion time to temporary ob2 asset
                    AudioMediaAsset ob2 = GetChunk(time, this.LengthInMilliseconds) as AudioMediaAsset;
                    // merge ob2 at back of ob1 so as to finalise ob1
                    ob1.MergeWith(ob2);
                }
// if chunk asset is to be placed before original asset
                else if (time == 0)
                {
                    // points chunk to ob1 and merge original asset at back of ob1
                    ob1 = chunk as AudioMediaAsset;
                    ob1.MergeWith(this);
                }
                // clears clip list of original asset and copy clips in clip list of ob1 to it
                m_alClipList.Clear();
                for (int i = 0; i < ob1.m_alClipList.Count; i++)
                {
                    m_alClipList.Add(ob1.m_alClipList [i]);
                }
                m_dAudioLengthInTime  = ob1.LengthInMilliseconds;
                m_lAudioLengthInBytes = ob1.AudioLengthInBytes;
                m_lSizeInBytes        = ob1.SizeInBytes;

// if Chunk is to be appended to original asset
                if (time == m_dAudioLengthInTime)
                {
                    MergeWith(chunk);
                }
            }             // end of main format check
            else
            {
                throw new Exception("Incompatible format or Insertion time not in asset range");
            }


            // end of insert chunk function
        }
示例#2
0
        public IAudioMediaAsset DeleteChunk(double beginTime, double endTime)
        {
            // checks if beginTime and EndTime is within bounds of asset and are in order
            if (beginTime >= 0 && beginTime < endTime && endTime <= m_dAudioLengthInTime)
            {
                // create new asset from original asset from part which has to be deleted and keep for returning back
                AudioMediaAsset ob_NewAsset = GetChunk(beginTime, endTime) as AudioMediaAsset;

// create two temp assets for holding clips in front of BeginTime and a asset to hold  Clips after endTime
                AudioMediaAsset ob_FromtAsset = new AudioMediaAsset(m_Channels, m_BitDepth, m_SamplingRate);
                AudioMediaAsset ob_RearAsset  = new AudioMediaAsset(m_Channels, m_BitDepth, m_SamplingRate);

// if deletion part lies somewhere in between body of asset
                if (beginTime != 0 && endTime != m_dAudioLengthInTime)
                {
// Copy respective  clips  to Front and Rear Assets and merge them
                    ob_FromtAsset = GetChunk(0, beginTime)  as AudioMediaAsset;

                    ob_RearAsset = GetChunk(endTime, m_dAudioLengthInTime) as AudioMediaAsset;

                    ob_FromtAsset.MergeWith(ob_RearAsset);
                }
// if deletion is from in between to end of asset
                else if (beginTime != 0)
                {
                    // copies only front part of asset
                    ob_FromtAsset = GetChunk(0, beginTime) as AudioMediaAsset;
                }
// if Deletion is in front including start
                else if (endTime != m_dAudioLengthInTime)
                {
                    // copies end part of asset to front asset
                    ob_FromtAsset = GetChunk(endTime, m_dAudioLengthInTime) as AudioMediaAsset;
                }

// replaces clip list of original asset with clip list of front asset
                m_alClipList          = ob_FromtAsset.m_alClipList;
                m_dAudioLengthInTime  = ob_FromtAsset.LengthInMilliseconds;
                m_lAudioLengthInBytes = ob_FromtAsset.AudioLengthInBytes;
                m_lSizeInBytes        = ob_FromtAsset.SizeInBytes;

                ob_FromtAsset = null;

                return(ob_NewAsset);
            }
            else
            {
                throw new Exception("Invalid input parameters");
            }
        }