コード例 #1
0
        public void InitRecording(bool SRecording)
        {
            //if no device is set then it is informed then no device is set
            if (null == m_cApplicationDevice)
            {
                throw new Exception("no device is set for recording");
            }
            //format of the capture buffer and the input format is compared
            //if not same then it is informed that formats do not match
            if (applicationBuffer.Format.ToString() != InputFormat.ToString())
            {
                throw new Exception("formats do not match");
            }

            if (SRecording)
            {
                CreateCaptureBuffer();
                applicationBuffer.Start(true);                //it will set the looping till the stop is used
            }
            else
            {
                applicationBuffer.Stop();
                RecordCapturedData();
                BinaryWriter         Writer      = new BinaryWriter(File.OpenWrite(m_sFileName));
                long                 Audiolength = (long)(SampleCount + 44);
                CalculationFunctions cf          = new CalculationFunctions();
                for (int i = 0; i < 4; i++)
                {
                    Writer.BaseStream.Position = i + 4;
                    Writer.Write(Convert.ToByte(cf.ConvertFromDecimal(Audiolength)[i]));
                }
                for (int i = 0; i < 4; i++)
                {
                    Writer.BaseStream.Position = i + 40;
                    Writer.Write(Convert.ToByte(cf.ConvertFromDecimal(SampleCount)[i]));
                }
                Writer.Close();                 // Close the file now.
                //Set the writer to null.
                Writer      = null;
                SampleCount = 0;
                Audiolength = 0;
                AudioClip NewRecordedClip = new AudioClip(m_sFileName);
                mAsset.AddClip(NewRecordedClip);
                //NotifyThread = null;
            }
        }
コード例 #2
0
ファイル: AudioMediaAsset.cs プロジェクト: daisy/obi
        public ArrayList ApplyPhraseDetection(long threshold, double length, double before)
        {
//			 convert input parameters from time to byte
            long lLength = Calc.ConvertTimeToByte(length, m_SamplingRate, m_FrameSize);
            long lBefore = Calc.ConvertTimeToByte(before, m_SamplingRate, m_FrameSize);


            AudioClip ob_Clip;
            // AssetList is list of assets returned by phrase detector
            ArrayList alAssetList = new ArrayList();
            // clipList is clip list for each return asset
            ArrayList       alClipList;
            AudioMediaAsset ob_Asset = new AudioMediaAsset(m_Channels, m_BitDepth, m_SamplingRate);


// apply phrase detection on each clip in clip list of this asset
            for (int i = 0; i < m_alClipList.Count; i++)
            {
                ob_Clip    = m_alClipList [i] as AudioClip;
                alClipList = ob_Clip.DetectPhrases(threshold, lLength, lBefore);
//MessageBox.Show (alClipList.Count.ToString () + "Clip Count") ;
                if (Convert.ToBoolean(alClipList [0]) == false)
                {
//MessageBox.Show ("bool is False") ;
                    ob_Asset.AddClip(alClipList [1] as AudioClip);

                    if (i == m_alClipList.Count - 1 && ob_Asset.m_alClipList != null)
                    {
                        alAssetList.Add(ob_Asset);
                        //MessageBox.Show ("last Asset added") ;
                    }
                }
                else
                {
//MessageBox.Show ("bool is true") ;
                    if (ob_Clip.BeginTime + 3000 < (alClipList [1] as AudioClip).BeginTime)
                    {
                        ob_Asset.AddClip(ob_Clip.CopyClipPart(0, (alClipList [1] as AudioClip).BeginTime - ob_Clip.BeginTime));
                        if (i == 0)
                        {
                            alAssetList.Add(ob_Asset);
                        }
                    }
//ob_Asset.AddClip (alClipList [1] as AudioClip) ;
                    if (i != 0)
                    {
                        alAssetList.Add(ob_Asset);
                    }
//MessageBox.Show ("Asset Added before loop") ;

                    for (int j = 1; j < alClipList.Count - 1; j++)
                    {
                        ob_Asset = new AudioMediaAsset(m_Channels, m_BitDepth, m_SamplingRate);
                        ob_Asset.AddClip(alClipList [j] as AudioClip);
                        alAssetList.Add(ob_Asset);
//MessageBox.Show ("Asset added inside loop") ;
                    }
                    ob_Asset = new AudioMediaAsset(m_Channels, m_BitDepth, m_SamplingRate);

                    if (alClipList.Count > 2)
                    {
                        ob_Asset.AddClip(alClipList [alClipList.Count - 1] as AudioClip);
                    }

                    if (i == m_alClipList.Count - 1 && ob_Asset.m_alClipList != null)
                    {
                        alAssetList.Add(ob_Asset);
//MessageBox.Show ("last Asset added") ;
                    }
                }                 // bool if ends
            }


            return(alAssetList);
        }