Ejemplo n.º 1
0
        public void ChangeEffects()
        {
            if (waveOutDevice != null)
            {
                Stop();
                waveOutDevice.Dispose();
                waveOutDevice = null;
            }

            waveOutDevice = new WaveOut()
            {
                DesiredLatency = 100
            };

            if (inputStream == null)
            {
                throw new NullReferenceException("InputStream is null,, can't apply effects.");
            }

            effectStream = new EffectStream(inputStream);
            if (Effects.Count % inputStream.WaveFormat.Channels != 0)
            {
                throw new FormatException("Effect and track channels don't match");
            }
            for (int i = 0; i < this.Effects.Count; i++)
            {
                effectStream.Effects.Add(this.Effects[i]);
                Console.Write(this.Effects[i].ToString() + "\n");
            }
            outputStream   = new WaveChannel32(effectStream);
            waveFormStream = new WaveChannel32(effectStream);

            outputStream.Sample += outputStream_Sample;

            waveOutDevice.Init(outputStream);

            ChannelLength = outputStream.TotalTime.TotalSeconds;
            GenerateWaveformData(waveFormStream);
            CanPlay = true;
        }
Ejemplo n.º 2
0
        public void OpenFile(string path)
        {
            Stop();

            if (ActiveStream != null)
            {
                SelectionBegin  = TimeSpan.Zero;
                SelectionEnd    = TimeSpan.Zero;
                ChannelPosition = 0;
            }

            StopAndCloseStream();

            if (System.IO.File.Exists(path))
            {
                try
                {
                    waveOutDevice = new WaveOut()
                    {
                        DesiredLatency = 100
                    };
                    var extension = Path.GetExtension(path);

                    if (extension == ".mp3")
                    {
                        ActiveStream = new Mp3FileReader(path);
                    }
                    else if (extension == ".wav")
                    {
                        ActiveStream = new WaveFileReader(path);
                    }
                    else
                    {
                        throw new ArgumentException("Wrong file extension.");
                    }


                    inputStream  = new WaveChannel32(ActiveStream);
                    effectStream = new EffectStream(inputStream);

                    outputStream   = new WaveChannel32(effectStream);
                    waveFormStream = new WaveChannel32(effectStream);

                    sampleAggregator = new SampleAggregator(fftDataSize);

                    outputStream.Sample += outputStream_Sample;
                    waveOutDevice.Init(outputStream);

                    ChannelLength = outputStream.TotalTime.TotalSeconds;
                    FileTag       = TagLib.File.Create(path);

                    GenerateWaveformData(waveFormStream);

                    CanPlay = true;
                }
                catch
                {
                    ActiveStream = null;
                    CanPlay      = false;
                }
            }
        }