Implement new spectrum mode, toggled by left click
The new spectrum mode is linear frequency. Both modes also now have a lower range of 10Hz, where possible. Signed-off-by: Christopher Snowhill <kode54@gmail.com>CQTexperiment
parent
6d052bc1ac
commit
1ac1fe29c7
|
@ -63,14 +63,19 @@ extern NSString *CogPlaybackDidStopNotficiation;
|
|||
|
||||
[self colorsDidChange:nil];
|
||||
|
||||
BOOL freqMode = [[NSUserDefaults standardUserDefaults] boolForKey:@"spectrumFreqMode"];
|
||||
|
||||
ddb_analyzer_init(&_analyzer);
|
||||
_analyzer.db_lower_bound = LOWER_BOUND;
|
||||
_analyzer.min_freq = 10;
|
||||
_analyzer.max_freq = 22000;
|
||||
_analyzer.peak_hold = 10;
|
||||
_analyzer.view_width = 64;
|
||||
_analyzer.fractional_bars = 1;
|
||||
_analyzer.octave_bars_step = 2;
|
||||
_analyzer.max_of_stereo_data = 1;
|
||||
_analyzer.mode = DDB_ANALYZER_MODE_OCTAVE_NOTE_BANDS;
|
||||
_analyzer.freq_is_log = 0;
|
||||
_analyzer.mode = freqMode ? DDB_ANALYZER_MODE_FREQUENCIES : DDB_ANALYZER_MODE_OCTAVE_NOTE_BANDS;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(colorsDidChange:)
|
||||
|
@ -254,4 +259,14 @@ extern NSString *CogPlaybackDidStopNotficiation;
|
|||
[self drawAnalyzer];
|
||||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent *)event {
|
||||
BOOL freqMode = ![[NSUserDefaults standardUserDefaults] boolForKey:@"spectrumFreqMode"];
|
||||
[[NSUserDefaults standardUserDefaults] setBool:freqMode forKey:@"spectrumFreqMode"];
|
||||
|
||||
_analyzer.mode = freqMode ? DDB_ANALYZER_MODE_FREQUENCIES : DDB_ANALYZER_MODE_OCTAVE_NOTE_BANDS;
|
||||
_analyzer.mode_did_change = 1;
|
||||
|
||||
[self repaint];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -75,6 +75,7 @@ ddb_analyzer_init(ddb_analyzer_t *analyzer) {
|
|||
analyzer->peak_speed_scale = 1000.f;
|
||||
analyzer->db_lower_bound = -80;
|
||||
analyzer->octave_bars_step = 1;
|
||||
analyzer->freq_is_log = 1;
|
||||
analyzer->bar_gap_denominator = 3;
|
||||
return analyzer;
|
||||
}
|
||||
|
@ -272,10 +273,18 @@ _generate_frequency_labels(ddb_analyzer_t *analyzer) {
|
|||
|
||||
static void
|
||||
_generate_frequency_bars(ddb_analyzer_t *analyzer) {
|
||||
float min_freq_log = log10(analyzer->min_freq);
|
||||
float max_freq_log = log10(analyzer->max_freq);
|
||||
float min_freq = analyzer->min_freq;
|
||||
float min_freq_log;
|
||||
float view_width = analyzer->view_width;
|
||||
float width_log = view_width / (max_freq_log - min_freq_log);
|
||||
float width;
|
||||
if(analyzer->freq_is_log) {
|
||||
min_freq_log = log10(analyzer->min_freq);
|
||||
float max_freq_log = log10(analyzer->max_freq);
|
||||
width = view_width / (max_freq_log - min_freq_log);
|
||||
} else {
|
||||
min_freq = analyzer->min_freq;
|
||||
width = view_width / (analyzer->max_freq - min_freq);
|
||||
}
|
||||
|
||||
float minIndex = _bin_for_freq_floor(analyzer, analyzer->min_freq);
|
||||
float maxIndex = _bin_for_freq_round(analyzer, analyzer->max_freq);
|
||||
|
@ -294,7 +303,11 @@ _generate_frequency_bars(ddb_analyzer_t *analyzer) {
|
|||
float freq = _freq_for_bin(analyzer, i);
|
||||
|
||||
// FIXME: only int position!
|
||||
int pos = width_log * (log10(freq) - min_freq_log);
|
||||
int pos;
|
||||
if(analyzer->freq_is_log)
|
||||
pos = width * (log10(freq) - min_freq_log);
|
||||
else
|
||||
pos = width * (freq - min_freq);
|
||||
|
||||
if(pos > prev && pos >= 0) {
|
||||
// start accumulating frequencies for the new band
|
||||
|
|
|
@ -101,6 +101,7 @@ typedef struct ddb_analyzer_s {
|
|||
float db_upper_bound; // dB value corresponding to the top of the view
|
||||
float db_lower_bound; // dB value corresponding to the bottom of the view
|
||||
int octave_bars_step; // how many notes in one bar (default 1)
|
||||
int freq_is_log; // whether frequency mode is in logarithmic or linear space (default 1)
|
||||
|
||||
/// The bars get created / updated by calling @c ddb_analyzer_process.
|
||||
/// The same bars get updated on every call to @c ddb_analyzer_tick.
|
||||
|
|
Loading…
Reference in New Issue