示例#1
0
文件: Form1.cs 项目: fxbit/FxMath
        private void button4_Click( object sender, EventArgs e )
        {
            // init the signal
            signal = new FxMaths.Vector.FxVectorF( 1024, new Fx1DGeneratorF( SignalGenerator ), 0.1f );

            // create a plot base on signal
            PloterElement plot = new PloterElement( signal );
            plot.Position.X = 0;
            plot.Position.Y = 50;
            plot.Origin = new FxVector2f(10, 100);
            plot.FitPlots();

            // add the signal to canva
            Signal_Canva.AddElements( plot );

            // add text for the signal plot
            TextElement text= new TextElement( "Signal Plot:" );
            text.Position.X = 10;
            text.Position.Y = 10;

            // add the text to canva
            Signal_Canva.AddElements( text );
        }
示例#2
0
文件: Form1.cs 项目: fxbit/FxMath
        private void button9_Click( object sender, EventArgs e )
        {
            // check if we have select file
            if ( String.IsNullOrEmpty( audioFileName ) ) {
                button8_Click( sender, e );
            }

            if ( String.IsNullOrEmpty( audioFileName ) ) {
                return;
            }

            // create wave out device
            CreateWaveOut();

            // create steram file
            ISampleProvider sampleProvider = null;

            try {

                // read the file
                fileWaveStream = new Mp3FileReader( audioFileName );

                // cretae the wave channel
                var waveChannel =  new SampleChannel( this.fileWaveStream );
                waveChannel.Volume = 0.5f;

                // create the sampler
                sampleProvider = new MeteringSampleProvider( waveChannel );

            } catch ( Exception createException ) {
                MessageBox.Show( String.Format( "{0}", createException.Message ), "Error Loading File" );
                return;
            }

            try {

                // in the wave out ( give and the call back for the editing
                waveOut.Init( new SampleToWaveProvider( sampleProvider), callback);

            } catch ( Exception initException ) {
                MessageBox.Show( String.Format( "{0}", initException.Message ), "Error Initializing Output" );
                return;
            }

            if ( plot_signal_spectrum == null )
            {

                #region Plot Creation

                signal_spectrum = new FxVectorF(256);

                // insert the plot of the time filter
                filterPlot = new PloterElement(signal_spectrum);
                filterPlot.Position.X = 0;
                filterPlot.Position.Y = 410;
                filterPlot.Origin = new FxVector2f(10, 100);
                filterPlot.FitPlots();
                canvas_audio.AddElements(filterPlot);

                // create the plot for the spectrum
                plot_signal_spectrum = new PloterElement( signal_spectrum );
                plot_signal_spectrum.Position.X = 0;
                plot_signal_spectrum.Position.Y = 10;
                plot_signal_spectrum.Origin = new FxVector2f(10, 100);
                plot_signal_spectrum.FitPlots();
                plot_signal_spectrum.AddPlot(signal_spectrum, PlotType.Lines, Color.Aqua);

                // add the signal to canva
                canvas_audio.AddElements(plot_signal_spectrum);

                // create the plot for the spectrum
                plot_signal_spectrum_original = new PloterElement(signal_spectrum);
                plot_signal_spectrum_original.Position.X = 600;
                plot_signal_spectrum_original.Position.Y = 10;
                plot_signal_spectrum_original.Origin = new FxVector2f(10, 100);
                plot_signal_spectrum_original.FitPlots();

                // add the signal to canva
                canvas_audio.AddElements(plot_signal_spectrum_original);

                // create the plot for the spectrum
                plot_filter_spectrum = new PloterElement(signal_spectrum);
                plot_filter_spectrum.Position.X = 600;
                plot_filter_spectrum.Position.Y = 410;
                plot_filter_spectrum.Origin = new FxVector2f(10, 100);
                plot_filter_spectrum.FitPlots();

                // add the signal to canva
                canvas_audio.AddElements(plot_filter_spectrum);
                #endregion

                // add filter
                UpdateFilter(BiQuadFilter.BandPassFilterConstantPeakGain(44100, 20000, 0.5f));

            }

            // start play
            waveOut.Play();
        }
示例#3
0
文件: Form1.cs 项目: fxbit/FxMath
        private void button13_Click( object sender, EventArgs e )
        {
            // process the white noise data with the dsp
            if ( wn != null ) {

                tmpWn = new FxVectorF( wn.Size );

                // create the signal spectrum graphs
                if ( plot_signal_spectrum == null ) {

                    power = new FxVectorF( 256 );

                    #region Plot Creation

                    signal_spectrum = new FxVectorF( 256 );

                    // insert the plot of the time filter
                    filterPlot = new PloterElement( signal_spectrum );
                    filterPlot.Position.X = 0;
                    filterPlot.Position.Y = 410;
                    filterPlot.Origin = new FxVector2f(10, 100);
                    filterPlot.FitPlots();
                    canvas_audio.AddElements( filterPlot );

                    // create the plot for the spectrum
                    plot_signal_spectrum = new PloterElement( signal_spectrum );
                    plot_signal_spectrum.Position.X = 0;
                    plot_signal_spectrum.Position.Y = 10;
                    plot_signal_spectrum.Origin = new FxVector2f(10, 100);
                    plot_signal_spectrum.FitPlots();
                    plot_signal_spectrum.AddPlot( signal_spectrum, PlotType.Lines, Color.Aqua );

                    // add the signal to canva
                    canvas_audio.AddElements( plot_signal_spectrum );

                    // create the plot for the spectrum
                    plot_signal_spectrum_original = new PloterElement( signal_spectrum );
                    plot_signal_spectrum_original.Position.X = 600;
                    plot_signal_spectrum_original.Position.Y = 10;
                    plot_signal_spectrum_original.Origin = new FxVector2f(10, 100);
                    plot_signal_spectrum_original.FitPlots();

                    // add the signal to canva
                    canvas_audio.AddElements( plot_signal_spectrum_original );

                    // create the plot for the spectrum
                    plot_filter_spectrum = new PloterElement( signal_spectrum );
                    plot_filter_spectrum.Position.X = 600;
                    plot_filter_spectrum.Position.Y = 410;
                    plot_filter_spectrum.Origin = new FxVector2f(10, 100);
                    plot_filter_spectrum.FitPlots();

                    // add the signal to canva
                    canvas_audio.AddElements( plot_filter_spectrum );
                    #endregion

                    // add filter
                    UpdateFilter( BiQuadFilter.BandPassFilterConstantPeakGain( 44100, 20000, 0.5f ) );

                }

                if ( this.fil != null ) {
                    // use the filter directly
                    this.fil.Transform( wn, tmpWn );
                }

                FxVectorF tmpImag,tmpReal;

                // calc spectrum
                int mod = (int)Math.Ceiling( tmpWn.Size / ( (double)power.Size * 2 ) );

                // ===============================================================================================

                if ( ShowOutputAudioSpectrum ) {
                    power.SetValue( 0.0f );
                    FxVectorF local=tmpWn;
                    if ( Math.Pow( 2, Math.Floor( Math.Log( local.Size, 2 ) ) ) != local.Size ) {
                        int newSize;

                        // calc the size of log2
                        int sizeLog2 = (int)Math.Floor( Math.Log( local.Size, 2 ) ) - 1;

                        // calc the new size
                        newSize = (int)Math.Pow( 2, sizeLog2 );
                        if ( newSize < 512 )
                            newSize = 512;

                        local = tmpWn.GetSubVector( 0, newSize ) as FxVectorF;
                    }

                    mod = (int)Math.Ceiling( local.Size / ( (double)power.Size * 2 ) );

                    // calc the fft
                    SignalTools.FFT_F( local, null, true, out tmpReal, out tmpImag );

                    // pass all the data in form of blocks
                    for ( int i = 0; i < mod; i++ ) {
                        for ( int j = 0; j < power.Size; j++ ) {
                            power[j] += (float)( Math.Sqrt( tmpReal[j * mod + i] * tmpReal[j * mod + i] + tmpImag[j * mod + i] * tmpImag[j * mod + i] ) );
                        }
                    }

                    // normalize the result
                    power.Divide( power.Max() );

                    // refresh the plot
                    plot_signal_spectrum.RefreshPlot( power, 0 );
                    plot_signal_spectrum.FitPlots();

                    // redraw canvas if we are not going to show output spectrum
                    if ( !ShowInputAudioSpectrum )
                        canvas_audio.ReDraw();
                }

                // ===============================================================================================

                if ( ShowInputAudioSpectrum ) {
                    // calc spectrum

                    // reset the power
                    power.SetValue( 0.0f );
                    FxVectorF local=wn;

                    if ( Math.Pow( 2, Math.Floor( Math.Log( local.Size, 2 ) ) ) != local.Size ) {
                        int newSize;

                        // calc the size of log2
                        int sizeLog2 = (int)Math.Floor( Math.Log( local.Size, 2 ) ) - 1;

                        // calc the new size
                        newSize = (int)Math.Pow( 2, sizeLog2 );
                        if ( newSize < 512 )
                            newSize = 512;

                        local = wn.GetSubVector( 0, newSize ) as FxVectorF;
                    }

                    mod = (int)Math.Ceiling( local.Size / ( (double)power.Size * 2 ) );

                    // calc the fft
                    SignalTools.FFT_Safe_F( local, null, true, out tmpReal, out tmpImag );

                    // pass all the data in form of blocks
                    for ( int i = 0; i < mod; i++ ) {
                        for ( int j = 0; j < power.Size; j++ ) {
                            power[j] += (float)( Math.Sqrt( tmpReal[j * mod + i] * tmpReal[j * mod + i] + tmpImag[j * mod + i] * tmpImag[j * mod + i] ) );
                        }

                    }

                    // normalize the result
                    power.Divide( power.Max() );

                    // refresh the plot
                    plot_signal_spectrum_original.RefreshPlot( power, 0 );
                    plot_signal_spectrum_original.FitPlots();

                    // redraw canvas
                    canvas_audio.ReDraw();
                }
            }
        }