コード例 #1
0
ファイル: CSCorePlayer.cs プロジェクト: pva-br/Dopamine
        private IWaveSource GetCodec(string filename)
        {
            // FfmpegDecoder constructor which uses string as parameter throws exception
            // "Exception: avformat_open_input returned 0xffffffea: Invalid argument."
            // when the file name contains special characters.
            // See: https://github.com/filoe/cscore/issues/298
            // Workaround: use the constructor which uses stream as parameter.
            // IWaveSource waveSource = new FfmpegDecoder(this.filename);
            this.audioStream = File.OpenRead(this.filename);
            IWaveSource waveSource = new FfmpegDecoder(this.audioStream);

            // If the SampleRate < 32000, make it 32000. The Equalizer's maximum frequency is 16000Hz.
            // The sample rate has to be bigger than 2 * frequency.
            if (waveSource.WaveFormat.SampleRate < 32000)
            {
                waveSource = waveSource.ChangeSampleRate(32000);
            }

            return(waveSource
                   .ToSampleSource()
                   .AppendSource(this.Create10BandEqualizer, out this.equalizer)
                   .ToWaveSource());
        }
コード例 #2
0
        private IWaveSource GetCodec(string filename)
        {
            IWaveSource waveSource;

            try
            {
                if (System.IO.Path.GetExtension(this.filename.ToLower()) == FileFormats.MP3)
                {
                    // For MP3's, we force usage of MediaFoundationDecoder. CSCore uses DmoMp3Decoder
                    // by default. DmoMp3Decoder however is very slow at playing MP3's from a NAS.
                    // So we're using MediaFoundationDecoder until DmoMp3Decoder has improved.
                    waveSource = new MediaFoundationDecoder(this.filename);
                }
                else
                {
                    // Other file formats are using the default decoders
                    waveSource = CodecFactory.Instance.GetCodec(this.filename);
                }
            }
            catch (Exception)
            {
                waveSource = new FfmpegDecoder(filename); //try ffmpeg as last option
            }

            // If the SampleRate < 32000, make it 32000. The Equalizer's maximum frequency is 16000Hz.
            // The samplerate has to be bigger than 2 * frequency.
            if (waveSource.WaveFormat.SampleRate < 32000)
            {
                waveSource = waveSource.ChangeSampleRate(32000);
            }

            return(waveSource
                   .ToSampleSource()
                   .AppendSource(this.Create10BandEqualizer, out this.equalizer)
                   .ToWaveSource());
        }