Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            bool normalized = false;

            Crossover crossover = Crossover.createThreeWayCrossover(Int32.Parse(txtLowerFreq.Text),
                                                                    Int32.Parse(txtUpperFreq.Text), Int32.Parse(txtLowerTrans.Text), Int32.Parse(txtUpperTrans.Text),
                                                                    44100, normalized, false, 10.0);

            RawFileReader rdr = new RawFileReader(lblFileName.Text, 16, 44100, 2);

            ConvertBitsPerSample bps = new ConvertBitsPerSample(rdr, 24);

            CrossoverThreeWayFilter filter = new CrossoverThreeWayFilter(bps, crossover);

            measureErrorDB(filter, crossover.wooferFilterKernel.Length);
        }
Exemplo n.º 2
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            IAudioFilter waveRdr;

            // For the purposes of testing we process .raw files as
            // containing 16-bit stereo PCM data at 44.1KHz.  This is much
            // like a .wav file but without the header.
            if (lblFileName.Text.EndsWith(".raw"))
            {
                waveRdr = new RawFileReader(lblFileName.Text, 16, 44100, 2);
            }
            else
            {
                IWaveSource inputFile = CodecFactory.Instance.GetCodec(lblFileName.Text);

                waveRdr = new WaveSourceReader(inputFile);
            }

            // Convert to 24 bit samples (if needed)
            ConvertBitsPerSample bpsConvert = new ConvertBitsPerSample(waveRdr, 24);

            // Create a crossover and catch any errors in case the frequency parameters
            // are not valid
            Crossover crossover;

            try
            {
                crossover = Crossover.createThreeWayCrossover(Int32.Parse(txtLowerFreq.Text),
                                                              Int32.Parse(txtUpperFreq.Text), Int32.Parse(txtLowerTrans.Text), Int32.Parse(txtUpperTrans.Text),
                                                              waveRdr.SampleRate, true, false, 10.0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error building crossover: " + ex.Message);
                return;
            }

            // Start creating filters...
            CrossoverThreeWayFilter filter = new CrossoverThreeWayFilter(bpsConvert, crossover);

            sampleTap = new SampleTap(filter, SAMPLE_LEN);



            int crossoverIdx = 1;

            if (rdoPlayWoofer.Checked)
            {
                crossoverIdx = 0;
            }
            else if (rdoPlayMidrange.Checked)
            {
                crossoverIdx = 1;
            }
            else if (rdoPlayTweeter.Checked)
            {
                crossoverIdx = 2;
            }

            channelSelectFilter = new SelectCrossover(sampleTap, crossoverIdx);

            volumeControlFilter = new VolumeControl(channelSelectFilter);

            // Only needed for playback through Windows
            lastFilterStep = new ConvertBitsPerSample(volumeControlFilter, 16);

            // Done creating filters...



            tbarFilePosition.Value = 0;
            // Max in seconds
            tbarFilePosition.Maximum = (int)(lastFilterStep.Length / lastFilterStep.SampleRate / lastFilterStep.NumberOfChannels);
            tbarFilePosition.Enabled = true;


            // Playback through Windows
            IWaveSource finalWaveSource = new FilterToWaveSource(lastFilterStep);

            //_soundOut = new WasapiOut();
            soundOutDevice = new WaveOut();
            soundOutDevice.Initialize(finalWaveSource);
            soundOutDevice.Play();

            tmrUpdateViz.Start();
        }