@@ -54,7 +54,7 @@ private void OnDataAvailable(object sender, NAudio.Wave.WaveInEventArgs args)
5454 float [ ] buffer = new float [ args . BytesRecorded / bytesPerSample ] ;
5555 for ( int i = 0 ; i < buffer . Length ; i ++ )
5656 buffer [ i ] = BitConverter . ToInt16 ( args . Buffer , i * bytesPerSample ) ;
57- spec . Add ( buffer ) ;
57+ spec . Add ( buffer , fixedSize : pictureBox1 . Width ) ;
5858 renderNeeded = true ;
5959 }
6060
@@ -67,25 +67,20 @@ private void AudioMonitorInitialize(
6767 )
6868 {
6969 int fftSize = 1024 ;
70- int stepSize = 300 ;
71- int pixelUpper = 200 ;
7270
7371 switch ( cbDisplay . Text )
7472 {
7573 case "waterfall" :
76- spec = new Spectrogram . Spectrogram ( sampleRate , fftSize : fftSize , stepSize : stepSize , pixelUpper : pixelUpper ,
77- fixedSize : pictureBox1 . Height , scroll : true , vertical : true ) ;
74+ spec = new Spectrogram . Spectrogram ( sampleRate , fftSize ) ;
7875 break ;
7976
8077 case "horizontal repeat" :
81- spec = new Spectrogram . Spectrogram ( sampleRate , fftSize : fftSize , stepSize : stepSize , pixelUpper : pixelUpper ,
82- fixedSize : pictureBox1 . Width , scroll : false ) ;
78+ spec = new Spectrogram . Spectrogram ( sampleRate , fftSize ) ;
8379 break ;
8480
8581 default :
8682 throw new NotImplementedException ( "unknown display type" ) ;
8783 }
88- nudIntensity . Value = ( decimal ) spec . intensity ;
8984
9085 wvin = new NAudio . Wave . WaveInEvent ( ) ;
9186 wvin . DeviceNumber = DeviceIndex ;
@@ -104,24 +99,35 @@ private void Timer1_Tick(object sender, EventArgs e)
10499 if ( ( spec == null ) || ( spec . ffts . Count == 0 ) )
105100 return ;
106101
107- pictureBox1 . BackgroundImage = spec . GetBitmap ( ) ;
108- lblStatus . Text = $ "spectrogram has { spec . ffts . Count } FFT columns | last render: { spec . lastRenderMsec } ms";
109- renderNeeded = false ;
110- }
102+ try
103+ {
104+ pictureBox1 . BackgroundImage = spec . GetBitmap (
105+ intensity : ( float ) nudIntensity . Value ,
106+ decibels : cbDecibels . Checked ,
107+ pixelLower : spec . GetFftIndex ( 0 ) ,
108+ pixelUpper : spec . GetFftIndex ( 4000 ) ,
109+ vertical : ( cbDisplay . Text == "waterfall" ) ,
110+ scroll : ( cbDisplay . Text == "waterfall" )
111+ ) ;
112+ lblStatus . Text = $ "spectrogram contains { spec . ffts . Count } FFT samples | last render: { spec . lastRenderMsec } ms";
113+ renderNeeded = false ;
114+ }
115+ catch ( Exception ex )
116+ {
117+ Console . WriteLine ( ex ) ;
118+ lblStatus . Text = ex . ToString ( ) ;
119+ }
111120
112- private void NudIntensity_ValueChanged ( object sender , EventArgs e )
113- {
114- spec . intensity = ( float ) nudIntensity . Value ;
115121 }
116122
117123 private void TbIntensity_Scroll ( object sender , EventArgs e )
118124 {
119125 nudIntensity . Value = tbIntensity . Value ;
120126 }
121127
122- private void CheckBox1_CheckedChanged ( object sender , EventArgs e )
128+ private void PictureBox1_Click ( object sender , EventArgs e )
123129 {
124- spec . decibels = checkBox1 . Checked ;
130+ MessageBox . Show ( spec . GetConfigDetails ( ) , "Configuration Details" ) ;
125131 }
126132 }
127133}
0 commit comments