@@ -33,6 +33,9 @@ public class SFF
33
33
public List < double [ ] > Ffts { get ; private set ; }
34
34
public int ImageHeight { get { return ( Ffts is null ) ? 0 : Ffts [ 0 ] . Length ; } }
35
35
public int ImageWidth { get { return ( Ffts is null ) ? 0 : Ffts . Count ; } }
36
+ public double [ ] times { get ; private set ; }
37
+ public double [ ] freqs { get ; private set ; }
38
+ public double [ ] mels { get ; private set ; }
36
39
37
40
[ Obsolete ( "use ImageWidth" , error : false ) ]
38
41
public int FftWidth { get { return ImageWidth ; } }
@@ -53,6 +56,8 @@ public override string ToString()
53
56
public SFF ( string loadFilePath )
54
57
{
55
58
Load ( loadFilePath ) ;
59
+ CalculateTimes ( ) ;
60
+ CalculateFrequencies ( ) ;
56
61
}
57
62
58
63
public SFF ( Spectrogram spec , int melBinCount = 0 )
@@ -65,10 +70,9 @@ public SFF(Spectrogram spec, int melBinCount = 0)
65
70
Height = spec . Height ;
66
71
OffsetHz = spec . OffsetHz ;
67
72
MelBinCount = melBinCount ;
68
- if ( MelBinCount > 0 )
69
- Ffts = spec . GetMelFFTs ( melBinCount ) ;
70
- else
71
- Ffts = spec . GetFFTs ( ) ;
73
+ Ffts = ( melBinCount > 0 ) ? spec . GetMelFFTs ( melBinCount ) : spec . GetFFTs ( ) ;
74
+ CalculateTimes ( ) ;
75
+ CalculateFrequencies ( ) ;
72
76
}
73
77
74
78
public Bitmap GetBitmap ( Colormap cmap = null , double intensity = 1 , bool dB = false )
@@ -247,5 +251,36 @@ public void Save(string filePath)
247
251
248
252
return ( timeSec , freq , mag ) ;
249
253
}
254
+
255
+ private void CalculateTimes ( )
256
+ {
257
+ times = new double [ ImageWidth ] ;
258
+ double stepSec = ( double ) StepSize / SampleRate ;
259
+ for ( int i = 0 ; i < ImageWidth ; i ++ )
260
+ times [ i ] = i * stepSec ;
261
+ }
262
+
263
+ private void CalculateFrequencies ( )
264
+ {
265
+ freqs = new double [ ImageHeight ] ;
266
+ mels = new double [ ImageHeight ] ;
267
+
268
+ double maxFreq = SampleRate / 2 ;
269
+ double maxMel = FftSharp . Transform . MelFromFreq ( maxFreq ) ;
270
+ for ( int y = 0 ; y < ImageHeight ; y ++ )
271
+ {
272
+ double frac = ( ImageHeight - y ) / ( double ) ImageHeight ;
273
+ if ( IsMel )
274
+ {
275
+ mels [ y ] = frac * maxMel ;
276
+ freqs [ y ] = FftSharp . Transform . MelToFreq ( mels [ y ] ) ;
277
+ }
278
+ else
279
+ {
280
+ freqs [ y ] = frac * maxFreq ;
281
+ mels [ y ] = FftSharp . Transform . MelFromFreq ( freqs [ y ] ) ;
282
+ }
283
+ }
284
+ }
250
285
}
251
286
}
0 commit comments