comparison FChTransformF0gram.cpp @ 24:430c730ae912 spect

Remove nfft for unimplemented oversampling option; rejig nsamp param to use indexed list
author Chris Cannam
date Thu, 04 Oct 2018 15:22:23 +0100
parents 2c54d83a196f
children 8e57d2f41926 9ebd08bdd168
comparison
equal deleted inserted replaced
23:2c54d83a196f 24:430c730ae912
24 24
25 #include "bqvec/Allocators.h" 25 #include "bqvec/Allocators.h"
26 26
27 using namespace breakfastquay; 27 using namespace breakfastquay;
28 28
29 //#define DEBUG 29 #define DEBUG
30 30
31 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 31 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
32 32
33 FChTransformF0gram::FChTransformF0gram(ProcessingMode mode, 33 FChTransformF0gram::FChTransformF0gram(ProcessingMode mode,
34 float inputSampleRate) : 34 float inputSampleRate) :
36 m_processingMode(mode), 36 m_processingMode(mode),
37 m_initialised(false), 37 m_initialised(false),
38 m_stepSize(256), 38 m_stepSize(256),
39 m_blockSize(8192) { 39 m_blockSize(8192) {
40 40
41 nsamp_options.push_back(256);
42 nsamp_options.push_back(512);
43 nsamp_options.push_back(1024);
44 nsamp_options.push_back(2048);
45 nsamp_options.push_back(4096);
46 nsamp_options.push_back(8192);
47
41 m_fs = inputSampleRate; 48 m_fs = inputSampleRate;
42 // max frequency of interest (Hz) 49 // max frequency of interest (Hz)
43 m_fmax = 10000.f; 50 m_fmax = 10000.f;
44 // warping parameters 51 // warping parameters
45 m_warp_params.nsamps_twarp = 2048; 52 m_warp_params.nsamps_twarp = 2048;
66 73
67 m_glogs_params.sigma_poly_coefs[0] = 0.000000092782308; 74 m_glogs_params.sigma_poly_coefs[0] = 0.000000092782308;
68 m_glogs_params.sigma_poly_coefs[1] = 0.000057283574898; 75 m_glogs_params.sigma_poly_coefs[1] = 0.000057283574898;
69 m_glogs_params.sigma_poly_coefs[2] = 0.022199903714288; 76 m_glogs_params.sigma_poly_coefs[2] = 0.022199903714288;
70 77
71 // number of fft points (controls zero-padding)
72 m_nfft = m_warp_params.nsamps_twarp;
73 // hop in samples
74 m_hop = m_warp_params.fact_over_samp * 256;
75
76 m_num_f0s = 0; 78 m_num_f0s = 0;
77 m_f0s = 0; 79 m_f0s = 0;
78 } 80 }
79 81
80 FChTransformF0gram::~FChTransformF0gram() 82 FChTransformF0gram::~FChTransformF0gram()
232 fmax.isQuantized = true; 234 fmax.isQuantized = true;
233 fmax.quantizeStep = 1.0; 235 fmax.quantizeStep = 1.0;
234 list.push_back(fmax); 236 list.push_back(fmax);
235 237
236 ParameterDescriptor nsamp; 238 ParameterDescriptor nsamp;
237 nsamp.identifier = "nsamp"; 239 nsamp.identifier = "nsamp_ix";
238 nsamp.name = "Number of samples"; 240 nsamp.name = "Number of samples";
239 nsamp.description = "Number of samples of the time warped frame"; 241 nsamp.description = "Number of samples of the time warped frame";
240 nsamp.unit = "samples"; 242 nsamp.minValue = 0;
241 nsamp.minValue = 128; 243 nsamp.maxValue = nsamp_options.size()-1;
242 nsamp.maxValue = 4096; 244 nsamp.defaultValue = 3;
243 nsamp.defaultValue = 2048; 245 nsamp.isQuantized = true;
246 nsamp.quantizeStep = 1.0;
247 char label[100];
248 for (int i = 0; i < int(nsamp_options.size()); ++i) {
249 sprintf(label, "%d", nsamp_options[i]);
250 nsamp.valueNames.push_back(label);
251 }
244 nsamp.isQuantized = true; 252 nsamp.isQuantized = true;
245 nsamp.quantizeStep = 1.0; 253 nsamp.quantizeStep = 1.0;
246 list.push_back(nsamp); 254 list.push_back(nsamp);
247
248 ParameterDescriptor nfft;
249 nfft.identifier = "nfft";
250 nfft.name = "FFT number of points";
251 nfft.description = "Number of FFT points (controls zero-padding)";
252 nfft.unit = "samples";
253 nfft.minValue = 0;
254 nfft.maxValue = 4;
255 nfft.defaultValue = 3;
256 nfft.isQuantized = true;
257 nfft.quantizeStep = 1.0;
258 nfft.valueNames.push_back("256");
259 nfft.valueNames.push_back("512");
260 nfft.valueNames.push_back("1024");
261 nfft.valueNames.push_back("2048");
262 nfft.valueNames.push_back("4096");
263 nfft.valueNames.push_back("8192");
264 list.push_back(nfft);
265 255
266 ParameterDescriptor alpha_max; 256 ParameterDescriptor alpha_max;
267 alpha_max.identifier = "alpha_max"; 257 alpha_max.identifier = "alpha_max";
268 alpha_max.name = "Maximum alpha value"; 258 alpha_max.name = "Maximum alpha value";
269 alpha_max.description = "Maximum value for the alpha parameter of the transform."; 259 alpha_max.description = "Maximum value for the alpha parameter of the transform.";
394 float 384 float
395 FChTransformF0gram::getParameter(string identifier) const { 385 FChTransformF0gram::getParameter(string identifier) const {
396 386
397 if (identifier == "fmax") { 387 if (identifier == "fmax") {
398 return m_fmax; 388 return m_fmax;
399 } else if (identifier == "nsamp") { 389 } else if (identifier == "nsamp_ix") {
400 return m_warp_params.nsamps_twarp; 390 for (int i = 0; i < int(nsamp_options.size()); ++i) {
391 if (m_warp_params.nsamps_twarp == nsamp_options[i]) {
392 return i;
393 }
394 }
395 throw std::logic_error("internal error: nsamps_twarp not in nsamp_options");
401 } else if (identifier == "alpha_max") { 396 } else if (identifier == "alpha_max") {
402 return m_warp_params.alpha_max; 397 return m_warp_params.alpha_max;
403 } else if (identifier == "num_warps") { 398 } else if (identifier == "num_warps") {
404 return m_warp_params.num_warps; 399 return m_warp_params.num_warps;
405 } else if (identifier == "alpha_dist") { 400 } else if (identifier == "alpha_dist") {
406 return m_warp_params.alpha_dist; 401 return m_warp_params.alpha_dist;
407 } else if (identifier == "nfft") {
408 return m_nfft;
409 } else if (identifier == "f0min") { 402 } else if (identifier == "f0min") {
410 return m_f0_params.f0min; 403 return m_f0_params.f0min;
411 } else if (identifier == "num_octs") { 404 } else if (identifier == "num_octs") {
412 return m_f0_params.num_octs; 405 return m_f0_params.num_octs;
413 } else if (identifier == "f0s_per_oct") { 406 } else if (identifier == "f0s_per_oct") {
428 421
429 void FChTransformF0gram::setParameter(string identifier, float value) 422 void FChTransformF0gram::setParameter(string identifier, float value)
430 { 423 {
431 if (identifier == "fmax") { 424 if (identifier == "fmax") {
432 m_fmax = value; 425 m_fmax = value;
433 } else if (identifier == "nsamp") { 426 } else if (identifier == "nsamp_ix") {
434 m_warp_params.nsamps_twarp = value; 427 int n = int(roundf(value));
428 for (int i = 0; i < int(nsamp_options.size()); ++i) {
429 if (i == n) {
430 m_warp_params.nsamps_twarp = nsamp_options[i];
431 m_blockSize = m_warp_params.nsamps_twarp * 4;
432 }
433 }
435 } else if (identifier == "alpha_max") { 434 } else if (identifier == "alpha_max") {
436 m_warp_params.alpha_max = value; 435 m_warp_params.alpha_max = value;
437 } else if (identifier == "num_warps") { 436 } else if (identifier == "num_warps") {
438 m_warp_params.num_warps = value; 437 m_warp_params.num_warps = value;
439 } else if (identifier == "alpha_dist") { 438 } else if (identifier == "alpha_dist") {
440 m_warp_params.alpha_dist = value; 439 m_warp_params.alpha_dist = value;
441 } else if (identifier == "nfft") {
442 m_nfft = value;
443 } else if (identifier == "f0min") { 440 } else if (identifier == "f0min") {
444 m_f0_params.f0min = value; 441 m_f0_params.f0min = value;
445 } else if (identifier == "num_octs") { 442 } else if (identifier == "num_octs") {
446 m_f0_params.num_octs = value; 443 m_f0_params.num_octs = value;
447 } else if (identifier == "f0s_per_oct") { 444 } else if (identifier == "f0s_per_oct") {
512 list.push_back(d); 509 list.push_back(d);
513 510
514 } else { 511 } else {
515 512
516 for (int i = 0; i < m_warp_params.nsamps_twarp/2+1; ++i) { 513 for (int i = 0; i < m_warp_params.nsamps_twarp/2+1; ++i) {
517 double freq = i * (m_warpings.fs_warp / m_nfft); 514 double freq = i * (m_warpings.fs_warp / m_warp_params.nsamps_twarp);
518 sprintf(label, "%4.2f Hz", freq); 515 sprintf(label, "%4.2f Hz", freq);
519 labels.push_back(label); 516 labels.push_back(label);
520 } 517 }
521 518
522 OutputDescriptor d; 519 OutputDescriptor d;
923 #ifdef DEBUG 920 #ifdef DEBUG
924 fprintf(stderr, "\n ----- DEBUG INFORMATION ----- \n"); 921 fprintf(stderr, "\n ----- DEBUG INFORMATION ----- \n");
925 fprintf(stderr, " m_fs = %f Hz.\n",m_fs); 922 fprintf(stderr, " m_fs = %f Hz.\n",m_fs);
926 fprintf(stderr, " fs_orig = %f Hz.\n",m_warpings.fs_orig); 923 fprintf(stderr, " fs_orig = %f Hz.\n",m_warpings.fs_orig);
927 fprintf(stderr, " fs_warp = %f Hz.\n",m_warpings.fs_warp); 924 fprintf(stderr, " fs_warp = %f Hz.\n",m_warpings.fs_warp);
928 fprintf(stderr, " m_nfft = %d.\n",m_nfft);
929 fprintf(stderr, " m_blockSize = %d.\n",m_blockSize); 925 fprintf(stderr, " m_blockSize = %d.\n",m_blockSize);
930 fprintf(stderr, " m_warpings.nsamps_torig = %d.\n",m_warpings.nsamps_torig); 926 fprintf(stderr, " m_warpings.nsamps_torig = %d.\n",m_warpings.nsamps_torig);
927 fprintf(stderr, " m_warp_params.nsamps_twarp = %d.\n",m_warp_params.nsamps_twarp);
931 fprintf(stderr, " m_warp_params.num_warps = %d.\n",m_warp_params.num_warps); 928 fprintf(stderr, " m_warp_params.num_warps = %d.\n",m_warp_params.num_warps);
932 fprintf(stderr, " m_glogs_harmonic_count = %d.\n",m_glogs_harmonic_count); 929 fprintf(stderr, " m_glogs_harmonic_count = %d.\n",m_glogs_harmonic_count);
933 #endif 930 #endif
934 931
935 for (int i = 0; i < m_blockSize - m_stepSize; ++i) { 932 for (int i = 0; i < m_blockSize - m_stepSize; ++i) {