Exemplo n.º 1
0
 /// <summary>
 /// Create a new command to delete audio data from an asset.
 /// </summary>
 /// <param name="asset">The asset to delete from.</param>
 /// <param name="beginTime">Begin time of data to delete in milliseconds.</param>
 /// <param name="endTime">End time of data to delete in milliseconds.</param>
 public DeleteAudioDataCommand(IAudioMediaAsset asset, double beginTime, double endTime)
 {
     m_Asset      = asset;
     m_dBeginTime = beginTime;
     m_dEndTime   = endTime;
     m_boolTime   = true;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new command to insert audio data into an asset.
 /// </summary>
 /// <param name="asset">The asset to insert into.</param>
 /// <param name="chunk">The chunk of data (as an asset itself) to insert into the asset.</param>
 /// <param name="time">The insertion time, in milliseconds.</param>
 public InsertAudioAssetCommand(IAudioMediaAsset asset, IAudioMediaAsset chunk, double time)
 {
     m_Asset          = asset;
     m_AssetChunk     = chunk;
     m_dInsertionTime = time;
     m_boolTime       = true;
 }
Exemplo n.º 3
0
 public void Play(IAudioMediaAsset asset)
 {
     m_StartPosition = 0;
     m_State         = AudioPlayerState.NotReady;
     m_Asset         = asset as AudioMediaAsset;
     InitPlay(0, 0);
 }
Exemplo n.º 4
0
        public long GetSilenceAmplitude(IAudioMediaAsset silenceRef)
        {
            AudioMediaAsset ob_AudioMediaSilenceRef = silenceRef as AudioMediaAsset;
            AudioClip       Ref = ob_AudioMediaSilenceRef.m_alClipList[0] as AudioClip;

            return(Ref.GetClipSilenceAmplitude());
        }
Exemplo n.º 5
0
        public void play(IAudioMediaAsset wave)
        {
            string m_sPath = null;

            ob_Audio = new Audio(m_sPath);
            ob_Audio.Play();
        }
Exemplo n.º 6
0
 /// <summary>
 /// Create a new command to insert audio data into an asset.
 /// </summary>
 /// <param name="asset">The asset to insert into.</param>
 /// <param name="chunk">The chunk of data (as an asset itself) to insert into the asset.</param>
 /// <param name="position">The insertion position, in bytes.</param>
 public InsertAudioAssetCommand(IAudioMediaAsset asset, IAudioMediaAsset chunk, long position)
 {
     m_Asset              = asset;
     m_AssetChunk         = chunk;
     m_lInsertionPosition = position;
     m_boolTime           = false;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Create a new command to delete audio data from an asset.
 /// </summary>
 /// <param name="asset">The asset to delete from.</param>
 /// <param name="beginPosition">Begin position of data to delete in bytes.</param>
 /// <param name="endPosition">End position of data to delete in bytes.</param>
 public DeleteAudioDataCommand(IAudioMediaAsset asset, long beginPosition, long endPosition)
 {
     m_Asset          = asset;
     m_lBeginPosition = beginPosition;
     m_lEndPosition   = endPosition;
     m_boolTime       = false;
 }
Exemplo n.º 8
0
        // Functions


        public void Play(IAudioMediaAsset asset)
        {
            m_Asset = asset;
            VuMeter ob_VuMeter = new VuMeter();

            ob_VuMeter.DisplayGraph();
            InitPlay(0, 0);
        }
Exemplo n.º 9
0
 public void StartRecording(IAudioMediaAsset asset)
 {
     m_sFileName = GetFileName();
     OldAsset    = new AudioMediaAsset(asset.Path);
     Writer      = new BinaryWriter(File.OpenWrite(m_sFileName));
     CreateRIFF(Writer, m_sFileName);
     InitRecording(true);
 }
Exemplo n.º 10
0
        public void play(IAudioMediaAsset wave, double timePositionToStartFrom)
        {
            string m_sPath = null;

            ob_Audio = new Audio(m_sPath);
            ob_Audio.CurrentPosition = timePositionToStartFrom;
            ob_Audio.Play();
        }
Exemplo n.º 11
0
        // same as above function but take time position as parameter instead of byte position
        internal void InsertAudio(double timeTargetPos, IAudioMediaAsset Source, double timeStartPos, double timeEndPos)
        {
            long lTargetPos = ConvertTimeToByte(timeTargetPos);
            long lStartPos  = ConvertTimeToByte(timeStartPos);
            long lEndPos    = ConvertTimeToByte(timeEndPos);

            InsertAudio(lTargetPos, Source, lStartPos, lEndPos);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Create a new command to apply phrase detection.
 /// </summary>
 /// <param name="asset">The asset to split into phrases.</param>
 /// <param name="threshold">The silence threshold.</param>
 /// <param name="length">The length of silence between sentences (in milliseconds.)</param>
 /// <param name="before">The legnth of leading silence for a sentece (in milliseconds.)</param>
 public PhraseDetectionCommand(IAudioMediaAsset asset, long threshold, double length, double before)
 {
     m_Asset         = asset;
     m_Manager       = asset.Manager;
     m_lThreshold    = threshold;
     m_dPhraseLength = length;
     m_dBefore       = before;
     m_boolTime      = true;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Create a new command to apply phrase detection.
 /// </summary>
 /// <param name="asset">The asset to split into phrases.</param>
 /// <param name="threshold">The silence threshold.</param>
 /// <param name="length">The length of silence between sentences (in bytes.)</param>
 /// <param name="before">The legnth of leading silence for a sentece (in bytes.)</param>
 public PhraseDetectionCommand(IAudioMediaAsset asset, long threshold, long length, long before)
 {
     m_Asset         = asset;
     m_Manager       = asset.Manager;
     m_lThreshold    = threshold;
     m_lPhraseLength = length;
     m_lBefore       = before;
     m_boolTime      = false;
 }
Exemplo n.º 14
0
//double m_dStartPosition ;
// Functions


        public void Play(IAudioMediaAsset asset)
        {
            m_StartPosition = 0;
            m_State         = AudioPlayerState.NotReady;
            m_Asset         = asset as AudioMediaAsset;
//VuMeter ob_VuMeter  = new VuMeter () ;
//ob_VuMeter.DisplayGraph () ;
            InitPlay(0, 0);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Delete the data.
 /// </summary>
 public override void Do()
 {
     if (m_boolTime == true)
     {
         m_NewAsset = m_Asset.DeleteChunk(m_dBeginTime, m_dEndTime);
     }
     else
     {
         m_NewAsset = m_Asset.DeleteChunk(m_lBeginPosition, m_lEndPosition);
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// Split the asset.
 /// </summary>
 public override void Do()
 {
     if (m_boolTime == true)
     {
         m_RearAsset = m_Asset.Split(m_dSplitTime);
     }
     else
     {
         m_RearAsset = m_Asset.Split(m_lSplitPosition);
     }
 }
Exemplo n.º 17
0
 private bool CompareAudioAssetFormat(IAudioMediaAsset asset1, IAudioMediaAsset asset2)
 {
     if (asset1.Channels == asset2.Channels && asset2.SampleRate == asset2.SampleRate && asset1.BitDepth == asset2.BitDepth)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 18
0
// check the format as above function but for assets instead of byte array
        public bool CheckStreamsFormat(IAudioMediaAsset asset)
        {
            byte []      bBuffer  = new byte [44];
            BinaryReader brBuffer = new BinaryReader(File.OpenRead(asset.Path));

            brBuffer.BaseStream.Position = 0;
            for (int i = 0; i < 44; i++)
            {
                bBuffer [i] = brBuffer.ReadByte();
            }
            brBuffer.Close();
            return(CheckStreamsFormat(bBuffer));
        }
Exemplo n.º 19
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
        }
Exemplo n.º 20
0
        public void StartListening(IAudioMediaAsset asset)
        {
            StateChanged mStateChanged = new StateChanged(mState);

            mState = AudioRecorderState.Listening;
            FireEvent(mStateChanged);
            //m_AudioMediaAsset = new AudioMediaAsset(asset.Path);
//			m_AudioMediaAsset = asset;
            m_sFileName = GetFileName();
            OldAsset    = new AudioMediaAsset(asset.Path);
            Writer      = new BinaryWriter(File.OpenWrite(m_sFileName));
            CreateRIFF(Writer, m_sFileName);
            InitRecording(true);
        }
Exemplo n.º 21
0
        public long GetSilenceAmplitude(IAudioMediaAsset Ref)
        {
            BinaryReader brRef = new BinaryReader(File.OpenRead(Ref.Path));
            //FileInfo file = new FileInfo (Ref.Path) ;
            //long lSize = file.Length ;

            // creates counter of size equal to file size
            long lSize = Ref.SizeInBytes;

            // Block size of audio chunck which is least count of detection
            int Block;

            // determine the Block  size
            if (Ref.SampleRate > 22500)
            {
                Block = 96;
            }
            else
            {
                Block = 48;
            }

            //set reading position after the header
            brRef.BaseStream.Position = 44;
            long lLargest = 0;
            long lBlockSum;

            // adjust the  lSize to avoid reading beyond file length
            lSize = ((lSize / Block) * Block) - 4;

            // loop to end of file reading collective value of  samples in Block and determine highest value denoted by lLargest
            // Step size is the Block size
            for (int j = 44; j < (lSize / Block); j = j + Block)
            {
                //  BlockSum is function to retrieve average amplitude in  Block
                lBlockSum = BlockSum(brRef, j, Block, Ref.FrameSize, Ref.Channels);
                if (lLargest < lBlockSum)
                {
                    lLargest = lBlockSum;
                }
            }
            long SilVal = Convert.ToInt64(lLargest);

            SilVal = SilVal + 4;
            brRef.Close();



            return(SilVal);
        }
Exemplo n.º 22
0
        public void Play(IAudioMediaAsset asset, double timeFrom)
        {
            m_Asset = asset;
            CalculationFunctions calc = new CalculationFunctions();
            long lPosition            = calc.ConvertTimeToByte(timeFrom, m_Asset.SampleRate, m_Asset.FrameSize);

            lPosition = calc.AdaptToFrame(lPosition, m_Asset.FrameSize);

            if (lPosition > 0 && lPosition < m_Asset.AudioLengthBytes)
            {
                InitPlay(lPosition, 0);
            }
            else
            {
                MessageBox.Show("Parameters out of range");
            }
        }
Exemplo n.º 23
0
        public IAudioMediaAsset MergeWith(IAudioMediaAsset next)
        {
            AudioMediaAsset amNext = new AudioMediaAsset(next.Path);

            string       sTempPath = GenerateFileName(".wav", m_sDirPath);
            BinaryWriter br        = new BinaryWriter(File.Create(sTempPath));

            br.Write(GetChunk(0, this.AudioLengthBytes));
            br.Close();

            AudioMediaAsset am1 = new AudioMediaAsset(sTempPath);

            am1.InsertByteBuffer(amNext.GetChunk(0, amNext.AudioLengthBytes), this.AudioLengthBytes - 1);


            return(am1);
        }
Exemplo n.º 24
0
        public void Play(IAudioMediaAsset asset, double timeFrom)
        {
            m_Asset = asset as AudioMediaAsset;
            long lPosition = Calc.ConvertTimeToByte(timeFrom, m_Asset.SampleRate, m_Asset.FrameSize);

            lPosition = Calc.AdaptToFrame(lPosition, m_Asset.FrameSize);


            if (lPosition >= 0 && lPosition < m_Asset.AudioLengthInBytes)
            {
                m_StartPosition = lPosition;
                InitPlay(lPosition, 0);
            }
            else
            {
                throw new Exception("Start Position is out of bounds of Audio Asset");
            }
        }
Exemplo n.º 25
0
        private void Play(IAudioMediaAsset asset, double timeFrom, double timeTo)
        {
            m_Asset = asset as AudioMediaAsset;
            long lStartPosition = Calc.ConvertTimeToByte(timeFrom, m_Asset.SampleRate, m_Asset.FrameSize);

            lStartPosition = Calc.AdaptToFrame(lStartPosition, m_Asset.FrameSize);
            long lEndPosition = Calc.ConvertTimeToByte(timeTo, m_Asset.SampleRate, m_Asset.FrameSize);

            lByteTo = lEndPosition;
            // check for valid arguments
            if (lStartPosition > 0 && lStartPosition < lEndPosition && lEndPosition <= m_Asset.AudioLengthInBytes)
            {
                InitPlay(lStartPosition, lEndPosition);
            }
            else
            {
                MessageBox.Show("Arguments out of range");
            }
        }
Exemplo n.º 26
0
        //it will start actual recording, append if there is data
        //in the wave file through the RecordCaptureData()
        public void StartRecording(IAudioMediaAsset asset)
        {
            events.AudioRecorderEvents.StateChanged e = new events.AudioRecorderEvents.StateChanged(mState);
            mState = AudioRecorderState.Recording;
            StateChanged(this, e);
            m_Channels   = asset.Channels;
            m_SampleRate = asset.SampleRate;
            m_bitDepth   = asset.BitDepth;
            mAsset       = new AudioMediaAsset(m_Channels, m_bitDepth, m_SampleRate);
            mAsset       = asset.Copy() as AudioMediaAsset;
            AssetManager manager = mAsset.Manager as AssetManager;

            sProjectDirectory = manager.DirPath;
            InputFormat       = GetInputFormat();
            m_sFileName       = GetFileName();
            BinaryWriter bw = new BinaryWriter(File.Create(m_sFileName));

            CreateRIFF(bw);
            CreateCaptureBuffer();
            InitRecording(true);
        }
Exemplo n.º 27
0
//		bool BOOLListen = false;
        public void StartListening(IAudioMediaAsset asset)
        {
            StateChanged mStateChanged = new StateChanged(mState);

            mState = AudioRecorderState.Listening;
            FireEvent(mStateChanged);
            m_Channels   = asset.Channels;
            m_bitDepth   = asset.BitDepth;
            m_SampleRate = asset.SampleRate;
            mAsset       = new AudioMediaAsset(m_Channels, m_bitDepth, m_SampleRate);
            mAsset       = asset.Copy() as AudioMediaAsset;
            AssetManager manager = asset.Manager as AssetManager;

            sProjectDirectory = manager.DirPath;
            InputFormat       = GetInputFormat();
            m_sFileName       = sProjectDirectory + "\\" + "Listen.wav";
            BinaryWriter ListenWriter = new BinaryWriter(File.Create(m_sFileName));

            CreateRIFF(ListenWriter);
            CreateCaptureBuffer();
            InitRecording(true);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Create a new command to split an audio asset.
 /// </summary>
 /// <param name="asset">The asset to split.</param>
 /// <param name="time">The split time, in milliseconds.</param>
 public SplitAudioAssetCommand(IAudioMediaAsset asset, double time)
 {
     m_Asset      = asset;
     m_dSplitTime = time;
     m_boolTime   = true;
 }
Exemplo n.º 29
0
        public void InsertAsset(IAudioMediaAsset chunk, long position)
        {
            double dPosition = Calc.ConvertByteToTime(position, m_SamplingRate, m_FrameSize);

            InsertAsset(chunk, dPosition);
        }
Exemplo n.º 30
0
        // The function opens two files (target file and source file)simultaneously  and copies from one to other frame by frame
        //This is done to reduce load on system memory as wave file may be as big as it go out of scope of RAM
        // IAudioMediaAsset Target is destination file where the stream has to be inserted and  TargetBytePos is insertion position in bytes excluding header
        //IAudioMediaAsset Source is asset from which data is taken between Positions in bytes (StartPos and EndPos) , these are also excluding header length
        internal void InsertAudio(long TargetBytePos, IAudioMediaAsset ISource, long StartPos, long EndPos)
        {
            AudioMediaAsset Source = new AudioMediaAsset(ISource.Path);

            // checks the compatibility of formats of two assets and validity of parameters
            if (CheckStreamsFormat(Source) == true && TargetBytePos < (m_AudioLengthBytes) && StartPos < EndPos && EndPos < Source.AudioLengthBytes)
            // braces holds whole  function
            {
                // opens Target asset and Source asset for reading and create temp file for manipulation
                BinaryReader brTarget = new BinaryReader(File.OpenRead(m_sFilePath));

                BinaryReader brSource = new BinaryReader(File.OpenRead(Source.Path));

                BinaryWriter bw = new BinaryWriter(File.Create(m_sFilePath + "tmp"));

                // adapt positions to frame size
                TargetBytePos = AdaptToFrame(TargetBytePos) + 44;
                StartPos      = Source.AdaptToFrame(StartPos) + 44;
                EndPos        = Source.AdaptToFrame(EndPos) + 44;
                int Step = FrameSize;

                // copies audio stream before the insertion point into temp file
                bw.BaseStream.Position       = 0;
                brTarget.BaseStream.Position = 0;
                long lCount = TargetBytePos;
                long i      = 0;
                for (i = 0; i < lCount; i = i + Step)
                {
                    bw.Write(brTarget.ReadBytes(Step));
                }

                // copies the audio stream data (between marked positions) from scource file  to temp file
                brSource.BaseStream.Position = StartPos;
                lCount = lCount + (EndPos - StartPos);
                for (i = i; i < lCount; i = i + Step)
                {
                    bw.Write(brSource.ReadBytes(Step));
                }

                // copies the remaining data after insertion point in Target asset into temp file
                FileInfo file = new FileInfo(m_sFilePath);
                lCount = file.Length - 44 + (EndPos - StartPos);

                brTarget.BaseStream.Position = TargetBytePos;

                for (i = i; i < lCount; i = i + Step)
                {
                    try
                    {
                        bw.Write(brTarget.ReadBytes(Step));
                    }
                    catch
                    {
                        MessageBox.Show("Problem   " + i);
                    }
                }


                // close all the reading and writing objects
                brTarget.Close();
                brSource.Close();
                bw.Close();

                //  Delete the target file and rename the temp file to target file
                FileInfo pfile = new FileInfo(m_sFilePath);
                pfile.Delete();

                FileInfo nfile = new FileInfo(m_sFilePath + "tmp");
                nfile.MoveTo(m_sFilePath);


                // Update lenth fields in header of temp file and also members of Target asset
                FileInfo filesize = new FileInfo(m_sFilePath);
                m_lSize = filesize.Length;

                BinaryWriter bw1 = new BinaryWriter(File.OpenWrite(m_sFilePath));
                UpdateLengthHeader(m_lSize, bw1);
                bw1.Close();
            }
            else
            {
                MessageBox.Show("Can not manipulate. files are of different format or invalid input parameters passed");
            }

            // End insert  function
        }