@@ -54,8 +54,18 @@ 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 , fixedSize : pictureBox1 . Width ) ;
58- renderNeeded = true ;
57+ try
58+ {
59+ if ( waterfall )
60+ spec . AddScroll ( buffer , fixedSize : pictureBox1 . Width ) ;
61+ else
62+ spec . AddCircular ( buffer , fixedSize : pictureBox1 . Width ) ;
63+ renderNeeded = true ;
64+ }
65+ catch ( Exception ex )
66+ {
67+ Console . WriteLine ( "EXCEPTION: " + ex ) ;
68+ }
5969 }
6070
6171 private void AudioMonitorInitialize (
@@ -66,21 +76,7 @@ private void AudioMonitorInitialize(
6676 int bufferMilliseconds = 10
6777 )
6878 {
69- int fftSize = 1024 ;
70-
71- switch ( cbDisplay . Text )
72- {
73- case "waterfall" :
74- spec = new Spectrogram . Spectrogram ( sampleRate , fftSize ) ;
75- break ;
76-
77- case "horizontal repeat" :
78- spec = new Spectrogram . Spectrogram ( sampleRate , fftSize ) ;
79- break ;
80-
81- default :
82- throw new NotImplementedException ( "unknown display type" ) ;
83- }
79+ spec = new Spectrogram . Spectrogram ( sampleRate , 1024 ) ;
8480
8581 wvin = new NAudio . Wave . WaveInEvent ( ) ;
8682 wvin . DeviceNumber = DeviceIndex ;
@@ -91,32 +87,30 @@ private void AudioMonitorInitialize(
9187 }
9288
9389 bool renderNeeded = false ;
90+ bool busyRendering = false ;
9491 private void Timer1_Tick ( object sender , EventArgs e )
9592 {
9693 if ( ! renderNeeded )
9794 return ;
9895
99- if ( ( spec == null ) || ( spec . ffts . Count == 0 ) )
96+ if ( ( spec == null ) || ( spec . fftList . Count == 0 ) )
10097 return ;
10198
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- }
99+ if ( busyRendering )
100+ return ;
101+ else
102+ busyRendering = true ;
103+
104+ pictureBox1 . BackgroundImage = spec . GetBitmap (
105+ intensity : ( float ) nudIntensity . Value ,
106+ decibels : cbDecibels . Checked ,
107+ frequencyMin : 0 ,
108+ frequencyMax : 4000 ,
109+ vertical : waterfall
110+ ) ;
111+ lblStatus . Text = $ "spectrogram contains { spec . fftList . Count } FFT samples | last render: { spec . GetLastRenderTime ( ) } ms";
112+ renderNeeded = false ;
113+ busyRendering = false ;
120114
121115 }
122116
@@ -127,7 +121,13 @@ private void TbIntensity_Scroll(object sender, EventArgs e)
127121
128122 private void PictureBox1_Click ( object sender , EventArgs e )
129123 {
130- MessageBox . Show ( spec . GetConfigDetails ( ) , "Configuration Details" ) ;
124+ MessageBox . Show ( spec . GetFftInfo ( ) , "Configuration Details" ) ;
125+ }
126+
127+ public bool waterfall = false ;
128+ private void CbDisplay_SelectedIndexChanged ( object sender , EventArgs e )
129+ {
130+ waterfall = ( cbDisplay . Text == "waterfall" ) ;
131131 }
132132 }
133133}
0 commit comments