Пример #1
0
        // this is to stop the recording
        // desc:  this will first check the condition and stops the recording and then capture any left  overs recorded data which is not saved
        public void StopRecording()
        {
            events.AudioRecorderEvents.StateChanged e = new events.AudioRecorderEvents.StateChanged(mState);
            mState = AudioRecorderState.Idle;
            StateChanged(this, e);
            if (null != NotificationEvent)
            {
                Capturing = false;
                NotificationEvent.Set();
            }
            if (null != applicationBuffer)
            {
                if (applicationBuffer.Capturing)
                {
                    InitRecording(false);
                }
            }
            applicationNotify = null;
            applicationBuffer = null;
            FileInfo fi = new FileInfo(m_sFileName);

            if (fi.Length == 44)
            {
                File.Delete(m_sFileName);
            }
        }
Пример #2
0
        //it will start actual recording, append if there is data
        //in the wave file through the RecordCaptureData()
        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 (dsc.Format.ToString() != InputFormat.ToString())
            {
                throw new Exception("formats do not match");
            }

            if (SRecording)
            {
                StateChanged mStateChanged = new StateChanged(mState);
                mState = AudioRecorderState.Recording;
                FireEvent(mStateChanged);
                CreateCaptureBuffer(Index);
                applicationBuffer.Start(true);                //it will set the looping till the stop is used
            }
            else
            {
                applicationBuffer.Stop();
                RecordCapturedData();
                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.
                Writer = null;                  // Set the writer to null.
                //m_AudioMediaAsset = new AudioMediaAsset(ProjectDirectory+"\\"+m_sFileName);
                m_AudioMediaAsset = new AudioMediaAsset(m_sFileName);
                if (OldAsset.SizeInBytes > 44)
                {
                    OldAsset.MergeWith(m_AudioMediaAsset);
                    //m_AudioMediaAsset = OldAsset;
                }
            }
        }
Пример #3
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);
        }
Пример #4
0
 public AudioRecorder()
 {
     Index = 0;
     if (0 == m_ConstructorCounter)
     {
         m_ConstructorCounter++;
         mState    = AudioRecorderState.Idle;
         Capturing = true;
     }
     else
     {
         throw new Exception("This class is Singleton");
     }
 }
Пример #5
0
        //it stops the recording
        public void StopRecording()
        {
            // name:  this is to stop the recording
            // desc:  this will first check the condition and stops the recording and then capture any left  overs recorded data which is not saved
            StateChanged mStateChanged = new StateChanged(mState);

            mState = AudioRecorderState.Idle;
            FireEvent(mStateChanged);

            Capturing = false;
            NotificationEvent.Set();

            if (null != applicationBuffer)
            {
                if (applicationBuffer.Capturing)
                {
                    InitRecording(false);
                }
            }
        }
Пример #6
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);
        }
Пример #7
0
        // this is to stop the recording
        // desc:  this will first check the condition and stops the recording and then capture any left  overs recorded data which is not saved
        public void StopRecording()
        {
            StateChanged mStateChanged = new StateChanged(mState);

            mState = AudioRecorderState.Idle;
            FireEvent(mStateChanged);
            if (null != NotificationEvent)
            {
                Capturing = false;
                NotificationEvent.Set();
            }
            if (null != applicationBuffer)
            {
                if (applicationBuffer.Capturing)
                {
                    InitRecording(false);
                }
            }
            applicationNotify = null;
            applicationBuffer = null;
        }
Пример #8
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);
        }
Пример #9
0
 /// <summary>
 /// Create a new StateChanged event.
 /// </summary>
 /// <param name="oldState">The state of the recorder before the change.</param>
 public StateChanged(AudioRecorderState oldState)
 {
     mOldState = oldState;
 }
Пример #10
0
 public StateChanged(AudioRecorderState newState)
 {
     mState = newState;
 }