コード例 #1
0
        public AudioStream Load(string streamKey, string filename)
        {
            if (!File.Exists(filename))
            {
                throw new Exception("Cannot find file " + filename);
            }
            if (GetStreamSection(streamKey) != null)
            {
                throw new Exception("AudioStream already exists with streamKey " + streamKey);
            }

            var audioStream = new Sample
            {
                Filename = filename
            };

            var tags = TagHelper.LoadTags(filename);

            if (tags != null)
            {
                if (tags.Gain.HasValue)
                {
                    audioStream.Gain = tags.Gain.Value;
                }
                if (tags.Bpm.HasValue)
                {
                    audioStream.Bpm = tags.Bpm.Value;
                }

                audioStream.Description = TrackHelper.GuessTrackDescription(filename, tags.Artist, tags.Title);
            }

            AudioStreamHelper.LoadAudio(audioStream);

            audioStream.SyncProc = OnSync;
            AudioStreamHelper.AddToMixer(audioStream, Output);
            AudioStreamHelper.SetPosition(audioStream, 0);

            lock (_streamSections)
            {
                _streamSections.Add(new AudioStreamSection
                {
                    Key           = streamKey,
                    AudioStream   = audioStream,
                    AudioSections = new List <AudioSection>()
                });
            }

            return(audioStream);
        }
コード例 #2
0
        /// <summary>
        ///     Loads a track for playing as the raw loop track.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Cannot find file  + filename</exception>
        public Track LoadRawLoopTrack(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new Exception("Cannot find file " + filename);
            }

            if (RawLoopTrack != null)
            {
                UnloadRawLoopTrack();
            }

            var track = new Track
            {
                Id       = _nextTrackId++,
                Filename = filename
            };

            SetArtistAndTitle(track, "", "");
            LoadTagData(track);
            ExtenedAttributesHelper.LoadExtendedAttributes(track);
            LoadTrackAudioData(track);

            // DebugHelper.WriteLine("Loaded raw loop track " + track.Description);

            // set track sync event
            track.SyncProc         = OnTrackSync;
            track.CurrentStartLoop = 0;
            track.CurrentEndLoop   = 0;
            track.RawLoopStart     = 0;
            track.RawLoopEnd       = track.Length;

            // DebugHelper.WriteLine("Loading raw loop track " + track.Description);

            AudioStreamHelper.AddToMixer(track, _rawLoopMixer);
            RawLoopTrack = track;

            SetRawLoopPositions(0, track.Length, 0);

            return(RawLoopTrack);
        }