@@ -16,6 +16,9 @@ public class Spectrogram
1616 public int FftSize { get { return settings . FftSize ; } }
1717 public double HzPerPx { get { return settings . HzPerPixel ; } }
1818 public double SecPerPx { get { return settings . StepLengthSec ; } }
19+ public int FftsToProcess { get { return ( newAudio . Count - settings . FftSize ) / settings . StepSize ; } }
20+ public int FftsProcessed { get ; private set ; }
21+ public int NextColumnIndex { get { return ( FftsProcessed + rollOffset ) % Width ; } }
1922
2023 private readonly Settings settings ;
2124 public readonly List < double [ ] > ffts = new List < double [ ] > ( ) ; // TODO: private
@@ -74,8 +77,11 @@ public void Add(double[] audio, bool process = true)
7477 Process ( ) ;
7578 }
7679
77- public int FftsToProcess { get { return ( newAudio . Count - settings . FftSize ) / settings . StepSize ; } }
78- public int FftsProcessed { get ; private set ; }
80+ private int rollOffset = 0 ;
81+ public void RollReset ( )
82+ {
83+ rollOffset = - FftsProcessed ;
84+ }
7985
8086 public double [ ] [ ] Process ( )
8187 {
@@ -110,7 +116,7 @@ public double[][] Process()
110116 }
111117
112118 public Bitmap GetBitmap ( double intensity = 1 , bool dB = false , bool roll = false ) =>
113- _GetBitmap ( ffts , cmap , intensity , dB , roll , FftsProcessed ) ;
119+ _GetBitmap ( ffts , cmap , intensity , dB , roll , NextColumnIndex ) ;
114120
115121 public void SaveImage ( string fileName , double intensity = 1 , bool dB = false , bool roll = false )
116122 {
@@ -128,7 +134,7 @@ public void SaveImage(string fileName, double intensity = 1, bool dB = false, bo
128134 else
129135 throw new ArgumentException ( "unknown file extension" ) ;
130136
131- _GetBitmap ( ffts , cmap , intensity , dB , roll , FftsProcessed ) . Save ( fileName , fmt ) ;
137+ _GetBitmap ( ffts , cmap , intensity , dB , roll , NextColumnIndex ) . Save ( fileName , fmt ) ;
132138 }
133139
134140 public Bitmap GetBitmapMax ( double intensity = 1 , bool dB = false , bool roll = false , int reduction = 4 )
@@ -143,10 +149,10 @@ public Bitmap GetBitmapMax(double intensity = 1, bool dB = false, bool roll = fa
143149 d2 [ j ] = Math . Max ( d2 [ j ] , d1 [ j * reduction + k ] ) ;
144150 ffts2 . Add ( d2 ) ;
145151 }
146- return _GetBitmap ( ffts2 , cmap , intensity , dB , roll , FftsProcessed ) ;
152+ return _GetBitmap ( ffts2 , cmap , intensity , dB , roll , NextColumnIndex ) ;
147153 }
148154
149- private static Bitmap _GetBitmap ( List < double [ ] > ffts , Colormap cmap , double intensity = 1 , bool dB = false , bool roll = false , int FftsProcessed = 0 )
155+ private static Bitmap _GetBitmap ( List < double [ ] > ffts , Colormap cmap , double intensity = 1 , bool dB = false , bool roll = false , int rollOffset = 0 )
150156 {
151157 int Width = ffts . Count ;
152158 int Height = ffts [ 0 ] . Length ;
@@ -164,7 +170,7 @@ private static Bitmap _GetBitmap(List<double[]> ffts, Colormap cmap, double inte
164170 int sourceCol = col ;
165171 if ( roll )
166172 {
167- sourceCol += Width - FftsProcessed % Width ;
173+ sourceCol += Width - rollOffset % Width ;
168174 if ( sourceCol >= Width )
169175 sourceCol -= Width ;
170176 }
0 commit comments