Example #1
0
        protected internal override bool BeginRecording(RecordingSession session)
        {
            if (!base.BeginRecording(session))
            {
                return(false);
            }

            try
            {
                Settings.fileNameGenerator.CreateDirectory(session);
            }
            catch (Exception)
            {
                ConsoleLogMessage($"Unable to create the output directory \"{Settings.fileNameGenerator.BuildAbsolutePath(session)}\".", LogType.Error);
                Recording = false;
                return(false);
            }

            var audioInput     = (AudioInput)m_Inputs[0];
            var audioAttrsList = new List <AudioTrackAttributes>();

            if (audioInput.audioSettings.PreserveAudio)
            {
                var audioAttrs = new AudioTrackAttributes
                {
                    sampleRate = new MediaRational
                    {
                        numerator   = audioInput.sampleRate,
                        denominator = 1
                    },
                    channelCount = audioInput.channelCount,
                    language     = ""
                };

                audioAttrsList.Add(audioAttrs);

                if (RecorderOptions.VerboseMode)
                {
                    ConsoleLogMessage($"Audio starting to write audio {audioAttrs.channelCount}ch @ {audioAttrs.sampleRate.numerator}Hz", LogType.Log);
                }
            }

            try
            {
                var path = Settings.fileNameGenerator.BuildAbsolutePath(session);
                m_Encoder = new WavEncoder(path);

                return(true);
            }
            catch (Exception ex)
            {
                if (RecorderOptions.VerboseMode)
                {
                    ConsoleLogMessage($"Unable to create encoder: '{ex.Message}'", LogType.Error);
                }
            }

            return(false);
        }
Example #2
0
        public override bool BeginRecording(RecordingSession session)
        {
            if (!base.BeginRecording(session))
            {
                return(false);
            }

            try
            {
                m_Settings.fileNameGenerator.CreateDirectory(session);
            }
            catch (Exception)
            {
                Debug.LogError(string.Format("Audio recorder output directory \"{0}\" could not be created.", m_Settings.fileNameGenerator.BuildAbsolutePath(session)));
                return(false);
            }

            var audioInput     = (AudioInput)m_Inputs[0];
            var audioAttrsList = new List <AudioTrackAttributes>();

            if (audioInput.audioSettings.preserveAudio)
            {
                var audioAttrs = new AudioTrackAttributes
                {
                    sampleRate = new MediaRational
                    {
                        numerator   = audioInput.sampleRate,
                        denominator = 1
                    },
                    channelCount = audioInput.channelCount,
                    language     = ""
                };

                audioAttrsList.Add(audioAttrs);

                if (Options.verboseMode)
                {
                    Debug.Log(string.Format("Audio starting to write audio {0}ch @ {1}Hz", audioAttrs.channelCount, audioAttrs.sampleRate.numerator));
                }
            }

            try
            {
                var path = m_Settings.fileNameGenerator.BuildAbsolutePath(session);
                m_Encoder = new WavEncoder(path);

                return(true);
            }
            catch
            {
                if (Options.verboseMode)
                {
                    Debug.LogError("AudioRecorder unable to create MovieEncoder.");
                }
            }

            return(false);
        }
Example #3
0
        public override void EndRecording(RecordingSession session)
        {
            base.EndRecording(session);

            if (m_Encoder != null)
            {
                m_Encoder.Dispose();
                m_Encoder = null;
            }

            // When adding a file to Unity's assets directory, trigger a refresh so it is detected.
            if (settings.fileNameGenerator.root == OutputPath.Root.AssetsFolder || settings.fileNameGenerator.root == OutputPath.Root.StreamingAssets)
            {
                AssetDatabase.Refresh();
            }
        }