Пример #1
0
        /// <summary>
        /// Convert from another stream file.
        /// </summary>
        /// <param name="other">Other stream file.</param>
        /// <param name="audioEncoding">Audio encoding to use.</param>
        /// <param name="targetBlockSize">Target block size.</param>
        public void FromOtherStreamFile(SoundFile other, Type audioEncoding, int targetBlockSize = -2)
        {
            //Set data.
            Loops             = other.Loops;
            LoopStart         = other.LoopStart;
            LoopEnd           = other.LoopEnd;
            OriginalLoopStart = other.OriginalLoopStart;
            OriginalLoopEnd   = other.OriginalLoopEnd;
            SampleRate        = other.SampleRate;
            Audio             = other.Audio.Duplicate();

            //Set track data.
            Tracks = new List <TrackData>();
            foreach (var t in other.Tracks)
            {
                Tracks.Add(t.Duplicate());
            }

            //Hook.
            BeforeConversion();

            //Set channel data.
            Audio.Convert(audioEncoding, targetBlockSize == -2 ? Audio.BlockSize : targetBlockSize, Loops ? (int)LoopStart : -1, Loops ? (int)LoopEnd : -1);

            //Activate on conversion hook.
            AfterConversion();
        }
Пример #2
0
        /// <summary>
        /// Convert this to another sound format.
        /// </summary>
        /// <param name="targetType">Target type to convert to.</param>
        /// <returns>Converted sound file.</returns>
        public SoundFile Convert(Type targetType)
        {
            SoundFile ret = (SoundFile)Activator.CreateInstance(targetType);

            ret.FromOtherStreamFile(this);
            return(ret);
        }
Пример #3
0
        /// <summary>
        /// Convert from another streamed audio file.
        /// </summary>
        /// <param name="other">The other file converted from.</param>
        /// <param name="targetBlockSize">Target block size.</param>
        public void FromOtherStreamFile(SoundFile other, int targetBlockSize = -2)
        {
            //Set data.
            Loops             = other.Loops;
            LoopStart         = other.LoopStart;
            LoopEnd           = other.LoopEnd;
            OriginalLoopStart = other.OriginalLoopStart;
            OriginalLoopEnd   = other.OriginalLoopEnd;
            SampleRate        = other.SampleRate;
            Audio             = other.Audio.Duplicate();

            //Set track data.
            Tracks = new List <TrackData>();
            foreach (var t in other.Tracks)
            {
                Tracks.Add(t.Duplicate());
            }

            //Hook.
            BeforeConversion();

            //Convert to preffered encoding.
            if (PreferredEncoding() != null && !Audio.EncodingType.Equals(PreferredEncoding()))
            {
                Audio.Convert(PreferredEncoding(), targetBlockSize == -2 ? Audio.BlockSize : targetBlockSize, Loops ? (int)LoopStart : -1, Loops ? (int)LoopEnd : -1);
                AfterConversion();
                return;
            }

            //If any of the encodings match then that's good.
            var e = SupportedEncodings();

            foreach (var t in e)
            {
                if (t.Equals(other.Audio.EncodingType))
                {
                    AfterConversion();
                    return;
                }
            }

            //By default convert to first type on list.
            Audio.Convert(SupportedEncodings()[0], targetBlockSize == -2 ? Audio.BlockSize : targetBlockSize, Loops ? (int)LoopStart : -1, Loops ? (int)LoopEnd : -1);

            //Activate on conversion hook.
            AfterConversion();
        }