Example #1
0
        public void StartRecordVedio(Camera[] captureCamera, int videoWidth, int videoHeight, bool recordMicrophone = false, AudioSource microphoneSource = null,
                                     int recordTime = 10, Action <string> recordVedioCallBack = null)
        {
            this.recordMicrophone = recordMicrophone;
            this.microphoneSource = microphoneSource;
            RecordVedioCallBack   = recordVedioCallBack;

            var sampleRate   = recordMicrophone ? AudioSettings.outputSampleRate : 0;
            var channelCount = recordMicrophone ? (int)AudioSettings.speakerMode : 0;

            recordingClock = new RealtimeClock();
            videoRecorder  = new MP4Recorder(
                videoWidth,
                videoHeight,
                30,
                sampleRate,
                channelCount,
                OnReplay
                );
            cameraInput = new CameraInput(videoRecorder, recordingClock, captureCamera);
            //录像
            StartMicrophone();
            audioInput = recordMicrophone ? new AudioInput(videoRecorder, recordingClock, microphoneSource, true) : null;
            if (audioInput != null)
            {
                microphoneSource.mute = false;
            }

            isStartRecording = true;
            Invoke("StopRecordVedio", recordTime);
        }
Example #2
0
        public void StartRecording(ExportVideoDTO exportVideo)
        {
            _record   = true;
            _settings = exportVideo;

            switch (exportVideo.VideoType)
            {
            case VideoType.MP4:
                _mediaRecorder = new MP4Recorder(exportVideo.Width, exportVideo.Height, exportVideo.Framerate, AudioSettings.outputSampleRate, (int)AudioSettings.speakerMode, OnStopRecording);
                break;

            case VideoType.GIF:
                _mediaRecorder = new GIFRecorder(exportVideo.Width, exportVideo.Height, exportVideo.Framerate, OnStopRecording);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            _clock       = new RealtimeClock();
            _cameraInput = new CameraInput(_mediaRecorder, _clock, _camera);
            _audioInput  = new AudioInput(_mediaRecorder, _clock, AudioPeerService.GetAudioListener());

            _mainCanvas.gameObject.SetActive(false);
            _recordCanvas.gameObject.SetActive(true);

            AudioPeerService.Stop();
            AudioPeerService.Play();
            _coroutine = StartCoroutine(_Play());
        }
Example #3
0
        /// <summary>
        /// Releases the resources used by the <see cref="AudioCaptureBase"/> object.
        /// </summary>
        /// <param name="disposing">
        /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
        /// </param>
        /// <since_tizen> 3 </since_tizen>
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (_handle != IntPtr.Zero)
            {
                if (_state != AudioIOState.Idle)
                {
                    try
                    {
                        Unprepare();
                    }
                    catch (Exception)
                    {
                    }
                }

                AudioInput.Destroy(_handle);
                _handle     = IntPtr.Zero;
                _isDisposed = true;
            }
        }
Example #4
0
        private void OnInputDataAvailable(IntPtr handle, uint length)
        {
            if (length == 0U)
            {
                return;
            }

            IntPtr ptr = IntPtr.Zero;

            try
            {
                AudioIOUtil.ThrowIfError(AudioInput.Peek(_handle, out ptr, ref length));

                byte[] buffer = new byte[length];
                Marshal.Copy(ptr, buffer, 0, (int)length);

                AudioInput.Drop(_handle);

                DataAvailable?.Invoke(this, new AudioDataAvailableEventArgs(buffer));
            }
            catch (Exception e)
            {
                Log.Error(nameof(AsyncAudioCapture), e.Message);
            }
        }
Example #5
0
        /// <summary>
        /// Prepares the AudioCapture for reading audio data by starting buffering of audio data from the device.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        ///     Operation failed due to an internal error.<br/>
        ///     -or-<br/>
        ///     The current state is not <see cref="AudioIOState.Idle"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">The AudioCaptureBase has already been disposed of.</exception>
        /// <seealso cref="Unprepare"/>
        /// <since_tizen> 3 </since_tizen>
        public void Prepare()
        {
            ValidateState(AudioIOState.Idle);

            AudioIOUtil.ThrowIfError(AudioInput.Prepare(_handle),
                                     "Failed to prepare the AudioCapture");
        }
Example #6
0
        /// <summary>
        /// Gets the size allocated for the audio input buffer.
        /// </summary>
        /// <exception cref="ObjectDisposedException">The AudioCaptureBase has already been disposed of.</exception>
        /// <since_tizen> 3 </since_tizen>
        public int GetBufferSize()
        {
            ValidateNotDisposed();

            AudioIOUtil.ThrowIfError(AudioInput.GetBufferSize(_handle, out var size));
            return(size);
        }
Example #7
0
    public static AudioInput ToAudioInput(this AudioInputJson json)
    {
        if (_nfi == null)
        {
            var cultureInfo = CultureInfo.CurrentCulture;
            _nfi = cultureInfo.NumberFormat;
        }

        var audioInput = new AudioInput();

        audioInput.Id          = -1;
        audioInput.Enabled     = json.Enabled;
        audioInput.Frequencies = new List <float>();
        audioInput.Frequencies.Add(CustomFloatParse(json.Hz0));
        audioInput.Frequencies.Add(CustomFloatParse(json.Hz1));
        audioInput.Frequencies.Add(CustomFloatParse(json.Hz2));
        audioInput.Frequencies.Add(CustomFloatParse(json.Hz3));
        audioInput.Frequencies.Add(CustomFloatParse(json.Hz4));
        audioInput.Peaks      = json.Peaks;
        audioInput.MouseInput = (MouseInput)json.MouseInputId;
        audioInput.Key        = (VirtualKeyCode)json.KeyboardInputId;
        audioInput.InputType  = (InputType)json.InputTypeId;
        audioInput.Param      = json.Param;
        return(audioInput);
    }
Example #8
0
        /// <summary>
        /// Unprepares the AudioCapture.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        ///     Operation failed due to an internal error.<br/>
        ///     -or-<br/>
        ///     The current state is <see cref="AudioIOState.Idle"/>.
        /// </exception>
        /// <exception cref="ObjectDisposedException">The AudioCaptureBase has already been disposed of.</exception>
        /// <seealso cref="Prepare"/>
        /// <since_tizen> 3 </since_tizen>
        public void Unprepare()
        {
            ValidateState(AudioIOState.Running, AudioIOState.Paused);

            AudioIOUtil.ThrowIfError(AudioInput.Unprepare(_handle),
                                     "Failed to unprepare the AudioCapture");
        }
Example #9
0
        public HueAudioVisualizer(
            Configuration config,
            AudioInput audio,
            HueOutput hue
            )
        {
            this.config = config;
            this.audio  = audio;
            this.hue    = hue;
            this.hue.RegisterVisualizer(this);

            this.random   = new Random();
            bins          = new Dictionary <String, double[]>();
            energyHistory = new Dictionary <String, float[]>();
            energyLevels  = new Dictionary <String, float>();

            // frequency detection bands
            // format: { bottom freq, top freq, activation level (delta)}
            bins.Add("midrange", new double[] { 250, 2000, .025 });
            bins.Add("total", new double[] { 60, 2000, .05 });
            // specific instruments
            bins.Add("kick", new double[] { 40, 50, .001 });
            bins.Add("snareattack", new double[] { 1500, 2500, .001 });
            foreach (String band in bins.Keys)
            {
                energyLevels.Add(band, 0);
                energyHistory.Add(band, Enumerable.Repeat((float)0, historyLength).ToArray());
            }
        }
    public void StartRecording()
    {
        Debug.Log("StartRecording------");
        // Start recording
        recordingClock = new RealtimeClock();
        videoRecorder  = new MP4Recorder(
            videoWidth,
            videoHeight,
            30,
            recordMicrophone ? AudioSettings.outputSampleRate : 0,
            recordMicrophone ? (int)AudioSettings.speakerMode : 0,
            OnReplay
            );

        // Create recording inputs
        cameraInput = new CameraInput(videoRecorder, recordingClock, _camere);
        if (recordMicrophone)
        {
            StartMicrophone();
            audioInput = new AudioInput(videoRecorder, recordingClock, microphoneSource, true);
        }

        isRecording = true;
        //Mvc.MvcTool.sendNotice(MessageKeys.ChangeRecState,isRecording);
    }
        public LEDDomeFlashVisualizer(
            Configuration config,
            AudioInput audio,
            MidiInput midi,
            LEDDomeOutput dome
            )
        {
            this.config = config;
            this.audio  = audio;
            this.midi   = midi;
            this.dome   = dome;
            this.dome.RegisterVisualizer(this);

            this.shapes = new Dictionary <ShapeType, List <Shape> >()
            {
                { ShapeType.Triangle, new List <Shape>() },
                { ShapeType.Triforce, new List <Shape>() },
                { ShapeType.Polygon, new List <Shape>() },
                { ShapeType.LargePolygon, new List <Shape>() },
                { ShapeType.Everything, new List <Shape>() },
            };
            this.strutsToShapes      = new Dictionary <int, List <Shape> >();
            this.activeAnimations    = new List <Animation>();
            this.padsToLastAnimation = new Dictionary <int, Animation>();

            this.rand = new Random();
            this.lastUserAnimationCreated = 0;

            this.BuildShapes();
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the AsyncAudioCapture class with the specified sample rate, channel and sampleType.
        /// </summary>
        /// <param name="sampleRate">The audio sample rate (8000 ~ 192000Hz).</param>
        /// <param name="channel">The audio channel type.</param>
        /// <param name="sampleType">The audio sample type.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     <paramref name="sampleRate"/> is less than <see cref="AudioCaptureBase.MinSampleRate"/>.<br/>
        ///     -or-<br/>
        ///     <paramref name="sampleRate"/> is greater than <see cref="AudioCaptureBase.MaxSampleRate"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="channel"/> is invalid.<br/>
        ///     -or-<br/>
        ///     <paramref name="sampleType"/> is invalid.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">The required privilege is not specified.</exception>
        /// <exception cref="NotSupportedException">The system does not support microphone.</exception>
        /// <since_tizen> 3 </since_tizen>
        public AsyncAudioCapture(int sampleRate, AudioChannel channel, AudioSampleType sampleType)
            : base(sampleRate, channel, sampleType)
        {
            _streamCallback = (IntPtr handle, uint length, IntPtr _) => { OnInputDataAvailable(handle, length); };

            AudioInput.SetStreamCallback(_handle, _streamCallback, IntPtr.Zero)
            .ThrowIfFailed("Failed to create instance.");
        }
 public void StartRecording()
 {
     // Start recording
     recorder   = new WAVRecorder(AudioSettings.outputSampleRate, (int)AudioSettings.speakerMode);
     audioInput = new AudioInput(recorder, microphoneSource, true);
     // Unmute microphone
     microphoneSource.mute = false;
 }
Example #14
0
    // Use this for initialization
    void Start()
    {
        Debug.Log(AudioInput.GetPeakLevel(FilterType.Bypass));

        AudioInput.RetrieveWaveform(FilterType.Bypass, _samples);

        Debug.Log(_samples[0]);
    }
Example #15
0
        /// <summary>
        /// Flushes and discards buffered audio data from the input stream.
        /// </summary>
        /// <exception cref="InvalidOperationException">The current state is <see cref="AudioIOState.Idle"/>.</exception>
        /// <exception cref="ObjectDisposedException">The AudioCaptureBase has already been disposed of.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void Flush()
        {
            ValidateState(AudioIOState.Running, AudioIOState.Paused);

            int ret = AudioInput.Flush(_handle);

            MultimediaDebug.AssertNoError(ret);
        }
Example #16
0
        /// <summary>
        /// Initializes a new instance of the AsyncAudioCapture class with the specified sample rate, channel and sampleType.
        /// </summary>
        /// <param name="sampleRate">The audio sample rate (8000 ~ 48000Hz).</param>
        /// <param name="channel">The audio channel type.</param>
        /// <param name="sampleType">The audio sample type.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     <paramref name="sampleRate"/> is less than <see cref="AudioCaptureBase.MinSampleRate"/>.<br/>
        ///     -or-<br/>
        ///     <paramref name="sampleRate"/> is greater than <see cref="AudioCaptureBase.MaxSampleRate"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="channel"/> is invalid.<br/>
        ///     -or-<br/>
        ///     <paramref name="sampleType"/> is invalid.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">The required privilege is not specified.</exception>
        /// <exception cref="NotSupportedException">The system does not support microphone.</exception>
        /// <since_tizen> 3 </since_tizen>
        public AsyncAudioCapture(int sampleRate, AudioChannel channel, AudioSampleType sampleType)
            : base(sampleRate, channel, sampleType)
        {
            _streamCallback = (IntPtr handle, uint length, IntPtr _) => { OnInputDataAvailable(handle, length); };

            AudioIOUtil.ThrowIfError(
                AudioInput.SetStreamCallback(_handle, _streamCallback, IntPtr.Zero),
                $"Failed to initialize a { nameof(AsyncAudioCapture) }");
        }
Example #17
0
        /// <summary>
        /// Gets the size allocated for the audio input buffer.
        /// </summary>
        /// <returns>The buffer size of audio data captured.</returns>
        /// <exception cref="ObjectDisposedException">The AudioCaptureBase has already been disposed of.</exception>
        /// <since_tizen> 3 </since_tizen>
        public int GetBufferSize()
        {
            ValidateNotDisposed();

            AudioInput.GetBufferSize(_handle, out var size)
            .ThrowIfFailed("Failed to get buffer size.");

            return(size);
        }
Example #18
0
        /// <summary>
        /// Resumes buffering audio data from the device.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        ///     The current state is <see cref="AudioIOState.Idle"/>.<br/>
        ///     -or-<br/>
        ///     The method is called in the <see cref="AsyncAudioCapture.DataAvailable"/> event handler.
        /// </exception>
        /// <exception cref="ObjectDisposedException">The AudioCaptureBase has already been disposed of.</exception>
        /// <seealso cref="Pause"/>
        /// <since_tizen> 3 </since_tizen>
        public void Resume()
        {
            if (_state == AudioIOState.Running)
            {
                return;
            }
            ValidateState(AudioIOState.Paused);

            AudioIOUtil.ThrowIfError(AudioInput.Resume(_handle));
        }
Example #19
0
        /// <summary>
        /// Resumes buffering audio data from the device.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        ///     The current state is <see cref="AudioIOState.Idle"/>.<br/>
        ///     -or-<br/>
        ///     The method is called in the <see cref="AsyncAudioCapture.DataAvailable"/> event handler.
        /// </exception>
        /// <exception cref="ObjectDisposedException">The AudioCaptureBase has already been disposed of.</exception>
        /// <seealso cref="Pause"/>
        /// <since_tizen> 3 </since_tizen>
        public void Resume()
        {
            if (_state == AudioIOState.Running)
            {
                return;
            }
            ValidateState(AudioIOState.Paused);

            AudioInput.Resume(_handle).ThrowIfFailed("Failed to resume.");
        }
Example #20
0
        /// <summary>
        /// Disposes the instance. WARNING: Calling this method will
        /// also dispose the dependencies passed to it in the constructor.
        /// Be mindful of this if you're sharing dependencies between multiple
        /// instances and/or using them outside this instance.
        /// </summary>
        public void Dispose()
        {
            AudioInput.Dispose();

            RemoveAllPeers();
            PeerSettings.Clear();
            PeerOutputs.Clear();

            Network.Dispose();
        }
Example #21
0
    public GameObject NewAudioInput(Transform listSource, Vector3 offset, AudioInput audioInput, int id, Panel01Bhv panelBhv)
    {
        var tmpAudioInputObject   = Resources.Load <GameObject>("Prefabs/AudioInput");
        var tmpAudioInputInstance = Instantiate(tmpAudioInputObject, listSource.position + offset, tmpAudioInputObject.transform.rotation);

        tmpAudioInputInstance.name = $"AudioInputs[{id}]";
        tmpAudioInputInstance.transform.SetParent(listSource);
        tmpAudioInputInstance.GetComponent <AudioInputBhv>().Init(audioInput, panelBhv, id);
        return(tmpAudioInputInstance);
    }
Example #22
0
        /// <summary>
        /// Sets the sound stream information to the audio input.
        /// </summary>
        /// <param name="streamPolicy">The <see cref="AudioStreamPolicy"/> to apply for the AudioCapture.</param>
        /// <exception cref="ArgumentNullException"><paramref name="streamPolicy"/> is null.</exception>
        /// <exception cref="ObjectDisposedException">
        ///     <paramref name="streamPolicy"/> has already been disposed of.<br/>
        ///     -or-<br/>
        ///     The AudioCaptureBase has already been disposed of.
        /// </exception>
        /// <exception cref="NotSupportedException"><paramref name="streamPolicy"/> is not supported.</exception>
        /// <exception cref="ArgumentException">Not able to retrieve information from <paramref name="streamPolicy"/>.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void ApplyStreamPolicy(AudioStreamPolicy streamPolicy)
        {
            if (streamPolicy == null)
            {
                throw new ArgumentNullException(nameof(streamPolicy));
            }

            ValidateNotDisposed();

            AudioIOUtil.ThrowIfError(AudioInput.SetStreamInfo(_handle, streamPolicy.Handle));
        }
Example #23
0
            public double RevsPerSecondBeats(AudioInput audio, Configuration config)
            {
                double BPS =
                    // If we don't have a beet counter, fake it as 60 BPM.
                    config.beatBroadcaster.MeasureLength == -1 ? 1 :
                    // Taken from the BPM toString method, and multiply by 60 for seconds.
                    1000.0 / config.beatBroadcaster.MeasureLength;

                // Make a full revolution after 4 beats.
                return(1.0 * BPS / 4);
            }
Example #24
0
 public LEDPanelVolumeVisualizer(
     Configuration config,
     AudioInput audio,
     LEDBoardOutput teensy
     )
 {
     this.config = config;
     this.audio  = audio;
     this.teensy = teensy;
     this.teensy.RegisterVisualizer(this);
 }
 public LEDDomeRadialVisualizer(
     Configuration config,
     AudioInput audio,
     LEDDomeOutput dome
     )
 {
     this.config = config;
     this.audio  = audio;
     this.dome   = dome;
     this.dome.RegisterVisualizer(this);
 }
Example #26
0
 public LEDPanelVolumeVisualizer(
     Configuration config,
     AudioInput audio,
     LEDBoardOutput board
     )
 {
     this.config = config;
     this.audio  = audio;
     this.board  = board;
     this.board.RegisterVisualizer(this);
 }
Example #27
0
        /// <summary>
        /// Sets the sound stream information to the audio input.
        /// </summary>
        /// <param name="streamPolicy">The <see cref="AudioStreamPolicy"/> to apply for the AudioCapture.</param>
        /// <exception cref="ArgumentNullException"><paramref name="streamPolicy"/> is null.</exception>
        /// <exception cref="ObjectDisposedException">
        ///     <paramref name="streamPolicy"/> has already been disposed of.<br/>
        ///     -or-<br/>
        ///     The AudioCaptureBase has already been disposed of.
        /// </exception>
        /// <exception cref="NotSupportedException"><paramref name="streamPolicy"/> is not supported.</exception>
        /// <exception cref="ArgumentException">Not able to retrieve information from <paramref name="streamPolicy"/>.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void ApplyStreamPolicy(AudioStreamPolicy streamPolicy)
        {
            if (streamPolicy == null)
            {
                throw new ArgumentNullException(nameof(streamPolicy));
            }

            ValidateNotDisposed();

            AudioInput.SetStreamInfo(_handle, streamPolicy.Handle)
            .ThrowIfFailed("Failed to apply stream policy.");
        }
Example #28
0
    // Update is called once per frame
    void Update()
    {
        // Get the Root Mean Square of the frequencies
        float scale = AudioInput.CalculateRMS(FilterType.Bypass);

        // scale the circle accordingly
        scale = scale * 25;
        transform.localScale = new Vector3(scale, scale, scale);

        // read the frequencies in to the array
        AudioInput.RetrieveWaveform(FilterType.Bypass, _samples);
    }
Example #29
0
        public override void Init(PitchPitch parent)
        {
            base.Init(parent);

            _audioInput = parent.AudioInput;
            _audioInput.DeviceInfoUpdated += (s, e) => { _needUpdate = true; };
            updateDevices();

            _isCalStarted   = false;
            _calSelectedIdx = IDX_MAXPITCH;
            _state          = SelectionState.Device;
        }
 public HueSilentVisualizer(
     Configuration config,
     AudioInput audio,
     HueOutput hue
     )
 {
     this.config = config;
     this.hue    = hue;
     this.audio  = audio;
     this.hue.RegisterVisualizer(this);
     this.stopwatch = new Stopwatch();
     this.stopwatch.Start();
 }
        private bool SetInputToWaveFile()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.DefaultExt = ".wav";
            dialog.Filter = "Audio Files (*.wav)|*.wav";
            dialog.Title = "Select Audio Input file";

            Nullable<bool> result = dialog.ShowDialog();

            if (result == true)
            {
                string fileName = dialog.FileName;
                Log("Setting input to wave file " + fileName + "... ");

                try
                {
                    _speechRecognitionEngine.SetInputToWaveFile(fileName);
                }
                catch (FormatException)
                {
                    LogLine("Failed");
                    LogLine(fileName + " is not a valid wave file.");

                    return false;
                }
                catch (InvalidOperationException e)
                {
                    LogLine("Failed");
                    LogLine(e.Message);

                    return false;
                }

                _textBoxWaveFile.Text = fileName;
                _audioInput = AudioInput.AudioFile;
                LogLine("Done");

                return true;
            }
            else
            {
                return false;
            }
        }
 private void SetInputToDefaultAudioDevice()
 {
     Log("Setting input to default audio device... ");
     _speechRecognitionEngine.SetInputToDefaultAudioDevice();
     _audioInput = AudioInput.DefaultAudioDevice;
     LogLine("Done");
 }
Example #33
0
 private void Start() {
    audioInput = (AudioInput) audioInputGameObject.GetComponent("AudioInput");
    gunDeckManager = (GunDeckManager) gunDeckGameObject.GetComponent("GunDeckManager");
 }