Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileSegment"/> class.
        /// Allow specifying an absolutely aligned (to the nearest minute) file segment.
        /// Implies `FileDateBehavior.Required`.
        /// NOTE: Start offset will be set to start of file, and end offset set to the end of the file.
        /// </summary>
        public FileSegment(
            FileInfo source,
            TimeAlignment alignment,
            IAudioUtility utility         = null,
            FileDateBehavior dateBehavior = FileDateBehavior.Try)
        {
            Contract.Requires(source != null);
            if (alignment != TimeAlignment.None)
            {
                Contract.Requires(
                    dateBehavior == FileDateBehavior.Required,
                    "If TimeAlignment is required, a date must be required in the filename");
            }

            this.dateBehavior = dateBehavior;
            this.Source       = source;
            this.Alignment    = alignment;

            var fileDate = this.ParseDate(null);

            var info = (utility ?? DefaultMasterAudioUtility).Info(source);

            var basename = Path.GetFileNameWithoutExtension(this.Source.Name);

            this.SourceMetadata = new SourceMetadata(info.Duration.Value, info.SampleRate.Value, basename, fileDate);

            Contract.Ensures(this.Validate(), "FileSegment did not validate");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SoxSpectrogramUtility"/> class.
        /// </summary>
        /// <param name="audioUtility">
        /// The audio utility.
        /// </param>
        /// <param name="soxExe">
        /// The sox exe.
        /// </param>
        public SoxSpectrogramUtility(IAudioUtility audioUtility, FileInfo soxExe, DirectoryInfo temporaryFilesDirectory)
        {
            this.CheckExe(soxExe, "sox");
            this.audioUtility = audioUtility;
            this.soxExe       = soxExe;

            this.TemporaryFilesDirectory = temporaryFilesDirectory;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SoxSpectrogramUtility"/> class.
        /// </summary>
        /// <param name="audioUtility">
        /// The audio utility.
        /// </param>
        /// <param name="soxExe">
        /// The sox exe.
        /// </param>
        public SoxSpectrogramUtility(IAudioUtility audioUtility, FileInfo soxExe)
        {
            this.CheckExe(soxExe, "sox");
            this.audioUtility = audioUtility;
            this.soxExe       = soxExe;

            this.TemporaryFilesDirectory = TempFileHelper.TempDir();
        }
Example #4
0
        public FileSegment(
            FileInfo source,
            DateTimeOffset startDate,
            IAudioUtility utility = null)
        {
            Contract.Requires(source != null);

            this.dateBehavior = FileDateBehavior.Required;
            this.Source       = source;
            this.Alignment    = TimeAlignment.None;

            var fileDate = this.ParseDate(startDate);

            var info     = (utility ?? DefaultMasterAudioUtility).Info(source);
            var basename = Path.GetFileNameWithoutExtension(this.Source.Name);

            this.SourceMetadata = new SourceMetadata(info.Duration.Value, info.SampleRate.Value, basename, fileDate);

            Contract.Ensures(this.Validate(), "FileSegment did not validate");
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomSpectrogramUtility"/> class.
 /// </summary>
 /// <param name="audioUtility">
 /// The audio utility.
 /// </param>
 public CustomSpectrogramUtility(IAudioUtility audioUtility, DirectoryInfo temporaryFilesDirectory)
 {
     this.audioUtility            = audioUtility;
     this.TemporaryFilesDirectory = temporaryFilesDirectory;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomSpectrogramUtility"/> class.
 /// </summary>
 /// <param name="audioUtility">
 /// The audio utility.
 /// </param>
 public CustomSpectrogramUtility(IAudioUtility audioUtility)
 {
     this.audioUtility            = audioUtility;
     this.TemporaryFilesDirectory = TempFileHelper.TempDir();
 }
        private static void AssertAdvancedChannelConversionFails(string file, string mediaType, IAudioUtility utility, string otherMediaType = null, bool skipMonoCheck = false)
        {
            // array of channels of frequencies (expected in each channel)
            var audioUtilityRequest = new AudioUtilityRequest {
                Channels = new[] { 1, 2, 3, 4 }, MixDownToMono = false
            };

            otherMediaType = otherMediaType ?? mediaType;

            Assert.ThrowsException <ChannelSelectionOperationNotImplemented>(
                () =>
            {
                utility.Modify(
                    TestHelper.GetAudioFile(file),
                    mediaType,
                    TempFileHelper.NewTempFile(MediaTypes.GetExtension(otherMediaType)),
                    otherMediaType,
                    audioUtilityRequest);
            });

            audioUtilityRequest.MixDownToMono = true;

            Assert.ThrowsException <ChannelSelectionOperationNotImplemented>(
                () =>
            {
                utility.Modify(
                    TestHelper.GetAudioFile(file),
                    mediaType,
                    TempFileHelper.NewTempFile(MediaTypes.GetExtension(otherMediaType)),
                    otherMediaType,
                    audioUtilityRequest);
            });

            if (skipMonoCheck)
            {
                return;
            }

            audioUtilityRequest.Channels = null;

            Assert.ThrowsException <ChannelSelectionOperationNotImplemented>(
                () =>
            {
                utility.Modify(
                    TestHelper.GetAudioFile(file),
                    mediaType,
                    TempFileHelper.NewTempFile(MediaTypes.GetExtension(otherMediaType)),
                    otherMediaType,
                    audioUtilityRequest);
            });
        }
Example #8
0
 public void Setup()
 {
     this.audioUtility = TestHelper.GetAudioUtility();
 }