Mercurial > hg > vamp-fanchirp
comparison FChTransformF0gram.cpp @ 14:44b86c346a5a perf
Switch to Vamp SDK FFT implementation (it is close enough in performance - FFTs aren't really a bottleneck here - and simpler for the build) and use bqvec allocators
author | Chris Cannam |
---|---|
date | Tue, 02 Oct 2018 16:38:52 +0100 |
parents | fc8f351d2cd6 |
children | 0a860992b4f4 |
comparison
equal
deleted
inserted
replaced
13:69069fc86e18 | 14:44b86c346a5a |
---|---|
17 | 17 |
18 #include "FChTransformF0gram.h" | 18 #include "FChTransformF0gram.h" |
19 #include "FChTransformUtils.h" | 19 #include "FChTransformUtils.h" |
20 #include <math.h> | 20 #include <math.h> |
21 #include <float.h> | 21 #include <float.h> |
22 | |
23 #include "bqvec/Allocators.h" | |
24 | |
25 using namespace breakfastquay; | |
26 | |
22 //#define DEBUG | 27 //#define DEBUG |
23 | 28 |
24 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) | 29 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) |
25 | 30 |
26 FChTransformF0gram::FChTransformF0gram(float inputSampleRate) : | 31 FChTransformF0gram::FChTransformF0gram(float inputSampleRate) : |
69 | 74 |
70 m_num_f0s = 0; | 75 m_num_f0s = 0; |
71 | 76 |
72 } | 77 } |
73 | 78 |
74 FChTransformF0gram::~FChTransformF0gram() { | 79 FChTransformF0gram::~FChTransformF0gram() |
75 // remeber to delete everything that deserves to | 80 { |
81 if (!m_blockSize) { | |
82 return; // nothing was allocated | |
83 } | |
84 | |
85 deallocate(m_warpings.pos_int); | |
86 deallocate(m_warpings.pos_frac); | |
87 deallocate(m_warpings.chirp_rates); | |
88 | |
89 clean_LPF(); | |
90 | |
91 deallocate(m_timeWindow); | |
92 | |
93 deallocate(mp_HanningWindow); | |
94 | |
95 // Warping | |
96 deallocate(x_warping); | |
97 delete fft_xwarping; | |
98 deallocate(m_absFanChirpTransform); | |
99 deallocate(m_auxFanChirpTransform); | |
100 | |
101 // design_GLogS | |
102 deallocate(m_glogs_f0); | |
103 deallocate(m_glogs); | |
104 deallocate(m_glogs_n); | |
105 deallocate(m_glogs_index); | |
106 deallocate(m_glogs_posint); | |
107 deallocate(m_glogs_posfrac); | |
108 deallocate(m_glogs_interp); | |
109 deallocate(m_glogs_third_harmonic_posint); | |
110 deallocate(m_glogs_third_harmonic_posfrac); | |
111 deallocate(m_glogs_third_harmonic); | |
112 deallocate(m_glogs_fifth_harmonic_posint); | |
113 deallocate(m_glogs_fifth_harmonic_posfrac); | |
114 deallocate(m_glogs_fifth_harmonic); | |
115 deallocate(m_glogs_f0_preference_weights); | |
116 deallocate(m_glogs_median_correction); | |
117 deallocate(m_glogs_sigma_correction); | |
76 } | 118 } |
77 | 119 |
78 string | 120 string |
79 FChTransformF0gram::getIdentifier() const { | 121 FChTransformF0gram::getIdentifier() const { |
80 return "fchtransformf0gram"; | 122 return "fchtransformf0gram"; |
477 // Every plugin must have at least one output. | 519 // Every plugin must have at least one output. |
478 | 520 |
479 /* f0 values of F0gram grid as string values */ | 521 /* f0 values of F0gram grid as string values */ |
480 vector<string> f0values; | 522 vector<string> f0values; |
481 int ind = 0; | 523 int ind = 0; |
482 char f0String[10]; | 524 char f0String[100]; |
483 while (ind < m_num_f0s) { | 525 while (ind < m_num_f0s) { |
484 sprintf(f0String, "%4.2f", m_f0s[ind]); | 526 sprintf(f0String, "%4.2f", m_f0s[ind]); |
485 f0values.push_back(f0String); | 527 f0values.push_back(f0String); |
486 ind++; | 528 ind++; |
487 } | 529 } |
489 /* The F0gram */ | 531 /* The F0gram */ |
490 OutputDescriptor d; | 532 OutputDescriptor d; |
491 d.identifier = "f0gram"; | 533 d.identifier = "f0gram"; |
492 d.name = "F0gram: salience of f0s"; | 534 d.name = "F0gram: salience of f0s"; |
493 d.description = "This representation show the salience of the different f0s in the signal."; | 535 d.description = "This representation show the salience of the different f0s in the signal."; |
494 d.unit = "Hertz"; | |
495 d.hasFixedBinCount = true; | 536 d.hasFixedBinCount = true; |
496 //d.binCount = m_num_f0s; | 537 d.binCount = m_f0_params.num_octs * m_f0_params.num_f0s_per_oct; |
497 //d.binCount = m_blockSize/2+1; | |
498 //d.binCount = m_warp_params.nsamps_twarp/2+1; | |
499 //d.binCount = m_warpings.nsamps_torig; | |
500 d.binCount = m_f0_params.num_octs*m_f0_params.num_f0s_per_oct; | |
501 d.binNames = f0values; | 538 d.binNames = f0values; |
502 d.hasKnownExtents = false; | 539 d.hasKnownExtents = false; |
503 d.isQuantized = false; | 540 d.isQuantized = false; |
504 d.sampleType = OutputDescriptor::OneSamplePerStep; | 541 d.sampleType = OutputDescriptor::OneSamplePerStep; |
505 d.hasDuration = false; | 542 d.hasDuration = false; |
509 } | 546 } |
510 | 547 |
511 bool | 548 bool |
512 FChTransformF0gram::initialise(size_t channels, size_t stepSize, size_t blockSize) { | 549 FChTransformF0gram::initialise(size_t channels, size_t stepSize, size_t blockSize) { |
513 if (channels < getMinChannelCount() || | 550 if (channels < getMinChannelCount() || |
514 channels > getMaxChannelCount()) return false; | 551 channels > getMaxChannelCount()) { |
552 return false; | |
553 } | |
515 | 554 |
516 // set blockSize and stepSize (but changed below) | 555 // set blockSize and stepSize (but changed below) |
517 m_blockSize = blockSize; | 556 m_blockSize = blockSize; |
518 m_stepSize = stepSize; | 557 m_stepSize = stepSize; |
519 | 558 |
521 // these values in fact are determined by the sampling frequency m_fs | 560 // these values in fact are determined by the sampling frequency m_fs |
522 // the parameters used below correspond to default values i.e. m_fs = 44.100 Hz | 561 // the parameters used below correspond to default values i.e. m_fs = 44.100 Hz |
523 //m_blockSize = 4 * m_warp_params.nsamps_twarp; | 562 //m_blockSize = 4 * m_warp_params.nsamps_twarp; |
524 m_stepSize = floor(m_hop / m_warp_params.fact_over_samp); | 563 m_stepSize = floor(m_hop / m_warp_params.fact_over_samp); |
525 | 564 |
526 /* initialise m_warp_params */ | |
527 // FChTF0gram:warping_design m_warpings = new warping_design; | |
528 /* initialise m_f0_params */ | |
529 | |
530 /* initialise m_glogs_params */ | 565 /* initialise m_glogs_params */ |
531 design_GLogS(); | 566 design_GLogS(); |
532 | 567 |
533 /* design of FChT */ | 568 /* design of FChT */ |
534 design_FChT(); | 569 design_FChT(); |
536 design_LPF(); | 571 design_LPF(); |
537 | 572 |
538 design_time_window(); | 573 design_time_window(); |
539 | 574 |
540 // Create Hanning window for warped signals | 575 // Create Hanning window for warped signals |
541 mp_HanningWindow = new double[m_warp_params.nsamps_twarp]; | 576 mp_HanningWindow = allocate<double>(m_warp_params.nsamps_twarp); |
542 bool normalize = false; | 577 bool normalize = false; |
543 hanning_window(mp_HanningWindow, m_warp_params.nsamps_twarp, normalize); | 578 Utils::hanning_window(mp_HanningWindow, m_warp_params.nsamps_twarp, normalize); |
544 | 579 |
545 return true; | 580 return true; |
546 } | 581 } |
547 | 582 |
548 void | 583 void |
551 // total number & initial quantity of f0s | 586 // total number & initial quantity of f0s |
552 m_glogs_init_f0s = (int)(((double)m_f0_params.num_f0s_per_oct)*log2(5.0))+1; | 587 m_glogs_init_f0s = (int)(((double)m_f0_params.num_f0s_per_oct)*log2(5.0))+1; |
553 m_glogs_num_f0s = (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct + m_glogs_init_f0s; | 588 m_glogs_num_f0s = (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct + m_glogs_init_f0s; |
554 | 589 |
555 // Initialize arrays | 590 // Initialize arrays |
556 m_glogs_f0 = new double[m_glogs_num_f0s]; | 591 m_glogs_f0 = allocate<double>(m_glogs_num_f0s); |
557 m_glogs = new double[m_glogs_num_f0s*m_warp_params.num_warps]; | 592 m_glogs = allocate<double>(m_glogs_num_f0s*m_warp_params.num_warps); |
558 m_glogs_n = new int[m_glogs_num_f0s]; | 593 m_glogs_n = allocate<int>(m_glogs_num_f0s); |
559 m_glogs_index = new int[m_glogs_num_f0s]; | 594 m_glogs_index = allocate<int>(m_glogs_num_f0s); |
560 | 595 |
561 // Compute f0 values | 596 // Compute f0 values |
562 m_glogs_harmonic_count = 0; | 597 m_glogs_harmonic_count = 0; |
563 double factor = (double)(m_warp_params.nsamps_twarp/2)/(double)(m_warp_params.nsamps_twarp/2+1); | 598 double factor = (double)(m_warp_params.nsamps_twarp/2)/(double)(m_warp_params.nsamps_twarp/2+1); |
564 for (int i = 0; i < m_glogs_num_f0s; i++) { | 599 for (int i = 0; i < m_glogs_num_f0s; i++) { |
568 m_glogs_index[i] = m_glogs_harmonic_count; | 603 m_glogs_index[i] = m_glogs_harmonic_count; |
569 m_glogs_harmonic_count += m_glogs_n[i]; | 604 m_glogs_harmonic_count += m_glogs_n[i]; |
570 } | 605 } |
571 | 606 |
572 // Initialize arrays for interpolation | 607 // Initialize arrays for interpolation |
573 m_glogs_posint = new int[m_glogs_harmonic_count]; | 608 m_glogs_posint = allocate<int>(m_glogs_harmonic_count); |
574 m_glogs_posfrac = new double[m_glogs_harmonic_count]; | 609 m_glogs_posfrac = allocate<double>(m_glogs_harmonic_count); |
575 m_glogs_interp = new double[m_glogs_harmonic_count]; | 610 m_glogs_interp = allocate<double>(m_glogs_harmonic_count); |
576 | 611 |
577 // Compute int & frac of interpolation positions | 612 // Compute int & frac of interpolation positions |
578 int aux_index = 0; | 613 int aux_index = 0; |
579 double aux_pos; | 614 double aux_pos; |
580 for (int i = 0; i < m_glogs_num_f0s; i++) { | 615 for (int i = 0; i < m_glogs_num_f0s; i++) { |
587 } | 622 } |
588 } | 623 } |
589 | 624 |
590 // Third harmonic attenuation | 625 // Third harmonic attenuation |
591 double aux_third_harmonic; | 626 double aux_third_harmonic; |
592 m_glogs_third_harmonic_posint = new int[(m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct]; | 627 m_glogs_third_harmonic_posint = allocate<int>((m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); |
593 m_glogs_third_harmonic_posfrac = new double[(m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct]; | 628 m_glogs_third_harmonic_posfrac = allocate<double>((m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); |
594 for (int i = 0; i < (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct; i++) { | 629 for (int i = 0; i < (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct; i++) { |
595 aux_third_harmonic = (double)i + (double)m_glogs_init_f0s - ((double)m_f0_params.num_f0s_per_oct)*log2(3.0); | 630 aux_third_harmonic = (double)i + (double)m_glogs_init_f0s - ((double)m_f0_params.num_f0s_per_oct)*log2(3.0); |
596 m_glogs_third_harmonic_posint[i] = (int)aux_third_harmonic; | 631 m_glogs_third_harmonic_posint[i] = (int)aux_third_harmonic; |
597 m_glogs_third_harmonic_posfrac[i] = aux_third_harmonic - (double)(m_glogs_third_harmonic_posint[i]); | 632 m_glogs_third_harmonic_posfrac[i] = aux_third_harmonic - (double)(m_glogs_third_harmonic_posint[i]); |
598 } | 633 } |
599 m_glogs_third_harmonic = new double[(m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct]; | 634 m_glogs_third_harmonic = allocate<double>((m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); |
600 | 635 |
601 // Fifth harmonic attenuation | 636 // Fifth harmonic attenuation |
602 double aux_fifth_harmonic; | 637 double aux_fifth_harmonic; |
603 m_glogs_fifth_harmonic_posint = new int[(m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct]; | 638 m_glogs_fifth_harmonic_posint = allocate<int>((m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); |
604 m_glogs_fifth_harmonic_posfrac = new double[(m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct]; | 639 m_glogs_fifth_harmonic_posfrac = allocate<double>((m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); |
605 for (int i = 0; i < (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct; i++) { | 640 for (int i = 0; i < (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct; i++) { |
606 aux_fifth_harmonic = (double)i + (double)m_glogs_init_f0s - ((double)m_f0_params.num_f0s_per_oct)*log2(5.0); | 641 aux_fifth_harmonic = (double)i + (double)m_glogs_init_f0s - ((double)m_f0_params.num_f0s_per_oct)*log2(5.0); |
607 m_glogs_fifth_harmonic_posint[i] = (int)aux_fifth_harmonic; | 642 m_glogs_fifth_harmonic_posint[i] = (int)aux_fifth_harmonic; |
608 m_glogs_fifth_harmonic_posfrac[i] = aux_fifth_harmonic - (double)(m_glogs_fifth_harmonic_posint[i]); | 643 m_glogs_fifth_harmonic_posfrac[i] = aux_fifth_harmonic - (double)(m_glogs_fifth_harmonic_posint[i]); |
609 } | 644 } |
610 m_glogs_fifth_harmonic = new double[(m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct]; | 645 m_glogs_fifth_harmonic = allocate<double>((m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); |
611 | 646 |
612 // Normalization & attenuation windows | 647 // Normalization & attenuation windows |
613 m_glogs_f0_preference_weights = new double[m_f0_params.num_octs*m_f0_params.num_f0s_per_oct]; | 648 m_glogs_f0_preference_weights = allocate<double>(m_f0_params.num_octs*m_f0_params.num_f0s_per_oct); |
614 m_glogs_median_correction = new double[m_f0_params.num_octs*m_f0_params.num_f0s_per_oct]; | 649 m_glogs_median_correction = allocate<double>(m_f0_params.num_octs*m_f0_params.num_f0s_per_oct); |
615 m_glogs_sigma_correction = new double[m_f0_params.num_octs*m_f0_params.num_f0s_per_oct]; | 650 m_glogs_sigma_correction = allocate<double>(m_f0_params.num_octs*m_f0_params.num_f0s_per_oct); |
616 m_glogs_hf_smoothing_window = new double[m_warp_params.nsamps_twarp/2+1]; | |
617 double MIDI_value; | 651 double MIDI_value; |
618 for (int i = 0; i < m_f0_params.num_octs*m_f0_params.num_f0s_per_oct; i++) { | 652 for (int i = 0; i < m_f0_params.num_octs*m_f0_params.num_f0s_per_oct; i++) { |
619 MIDI_value = 69.0 + 12.0 * log2(m_glogs_f0[i + m_glogs_init_f0s]/440.0); | 653 MIDI_value = 69.0 + 12.0 * log2(m_glogs_f0[i + m_glogs_init_f0s]/440.0); |
620 m_glogs_f0_preference_weights[i] = 1.0/sqrt(2.0*M_PI*m_f0_params.prefer_stdev*m_f0_params.prefer_stdev)*exp(-(MIDI_value-m_f0_params.prefer_mean)*(MIDI_value-m_f0_params.prefer_mean)/(2.0*m_f0_params.prefer_stdev*m_f0_params.prefer_stdev)); | 654 m_glogs_f0_preference_weights[i] = 1.0/sqrt(2.0*M_PI*m_f0_params.prefer_stdev*m_f0_params.prefer_stdev)*exp(-(MIDI_value-m_f0_params.prefer_mean)*(MIDI_value-m_f0_params.prefer_mean)/(2.0*m_f0_params.prefer_stdev*m_f0_params.prefer_stdev)); |
621 m_glogs_f0_preference_weights[i] = (0.01 + m_glogs_f0_preference_weights[i]) / (1.01); | 655 m_glogs_f0_preference_weights[i] = (0.01 + m_glogs_f0_preference_weights[i]) / (1.01); |
622 | 656 |
623 m_glogs_median_correction[i] = m_glogs_params.median_poly_coefs[0]*(i+1.0)*(i+1.0) + m_glogs_params.median_poly_coefs[1]*(i+1.0) + m_glogs_params.median_poly_coefs[2]; | 657 m_glogs_median_correction[i] = m_glogs_params.median_poly_coefs[0]*(i+1.0)*(i+1.0) + m_glogs_params.median_poly_coefs[1]*(i+1.0) + m_glogs_params.median_poly_coefs[2]; |
624 m_glogs_sigma_correction[i] = 1.0 / (m_glogs_params.sigma_poly_coefs[0]*(i+1.0)*(i+1.0) + m_glogs_params.sigma_poly_coefs[1]*(i+1.0) + m_glogs_params.sigma_poly_coefs[2]); | 658 m_glogs_sigma_correction[i] = 1.0 / (m_glogs_params.sigma_poly_coefs[0]*(i+1.0)*(i+1.0) + m_glogs_params.sigma_poly_coefs[1]*(i+1.0) + m_glogs_params.sigma_poly_coefs[2]); |
625 } | 659 } |
626 | |
627 double smooth_width = 1000.0; // hertz. | |
628 double smooth_aux = (double)(m_warp_params.nsamps_twarp/2+1)*(m_fmax-smooth_width)/m_fmax; | |
629 for (int i = 0; i < m_warp_params.nsamps_twarp/2+1; i++) { | |
630 if (i < smooth_aux) { | |
631 m_glogs_hf_smoothing_window[i] = 1.0; | |
632 } else { | |
633 m_glogs_hf_smoothing_window[i] = ((double)i - (double)m_warp_params.nsamps_twarp/2.0)*(-1.0/((double)(m_warp_params.nsamps_twarp/2+1)-smooth_aux)); | |
634 } | |
635 } | |
636 } | 660 } |
637 | 661 |
638 void | 662 void |
639 FChTransformF0gram::design_FChT() { | 663 FChTransformF0gram::design_FChT() { |
640 | 664 |
653 // number of samples of the original signal frame | 677 // number of samples of the original signal frame |
654 m_warpings.nsamps_torig = 4 * m_warp_params.fact_over_samp * m_warp_params.nsamps_twarp; | 678 m_warpings.nsamps_torig = 4 * m_warp_params.fact_over_samp * m_warp_params.nsamps_twarp; |
655 // equivalent to: m_warpings.nsamps_torig = m_warp_params.fact_over_samp * m_blockSize; | 679 // equivalent to: m_warpings.nsamps_torig = m_warp_params.fact_over_samp * m_blockSize; |
656 | 680 |
657 // time instants of the original signal frame | 681 // time instants of the original signal frame |
658 double t_orig[m_warpings.nsamps_torig]; | 682 double *t_orig = allocate<double>(m_warpings.nsamps_torig); |
659 //float * t_orig = new float [m_warpings.nsamps_torig]; | |
660 for (int ind = 0; ind < m_warpings.nsamps_torig; ind++) { | 683 for (int ind = 0; ind < m_warpings.nsamps_torig; ind++) { |
661 t_orig[ind] = ((double)(ind + 1) - (double)m_warpings.nsamps_torig / 2.0) / m_warpings.fs_orig; | 684 t_orig[ind] = ((double)(ind + 1) - (double)m_warpings.nsamps_torig / 2.0) / m_warpings.fs_orig; |
662 } | 685 } |
663 | 686 |
664 // linear chirps warping definition as relative frequency deviation | 687 // linear chirps warping definition as relative frequency deviation |
665 //double * freq_relative = new double [m_warpings.nsamps_torig * m_warp_params.num_warps]; | |
666 //TODO | 688 //TODO |
667 double *freq_relative = new double [m_warpings.nsamps_torig * m_warp_params.num_warps]; | 689 double *freq_relative = allocate<double>(m_warpings.nsamps_torig * m_warp_params.num_warps); |
668 define_warps_linear_chirps(freq_relative, t_orig); | 690 define_warps_linear_chirps(freq_relative, t_orig); |
669 | 691 |
670 // maximum relative frequency deviation | 692 // maximum relative frequency deviation |
671 double freq_relative_max = 0; | 693 double freq_relative_max = 0; |
672 for (int i = 0; i < m_warpings.nsamps_torig; i++) | 694 for (int i = 0; i < m_warpings.nsamps_torig; i++) { |
673 for (int j = 0; j < m_warp_params.num_warps; j++) | 695 for (int j = 0; j < m_warp_params.num_warps; j++) { |
674 if (freq_relative_max < freq_relative[j * m_warpings.nsamps_torig + i]) | 696 if (freq_relative_max < freq_relative[j * m_warpings.nsamps_torig + i]) { |
675 freq_relative_max = freq_relative[j * m_warpings.nsamps_torig + i]; | 697 freq_relative_max = freq_relative[j * m_warpings.nsamps_torig + i]; |
698 } | |
699 } | |
700 } | |
676 | 701 |
677 // sampling frequency of warped signal to be free of aliasing up to fmax | 702 // sampling frequency of warped signal to be free of aliasing up to fmax |
678 m_warpings.fs_warp = 2 * m_fmax * freq_relative_max; | 703 m_warpings.fs_warp = 2 * m_fmax * freq_relative_max; |
679 | 704 |
680 // time instants of the warped signal frame | 705 // time instants of the warped signal frame |
681 double t_warp[m_warp_params.nsamps_twarp]; | 706 double *t_warp = allocate<double>(m_warp_params.nsamps_twarp); |
682 for (int ind = 0; ind < m_warp_params.nsamps_twarp; ind++) { | 707 for (int ind = 0; ind < m_warp_params.nsamps_twarp; ind++) { |
683 t_warp[ind] = ((double)((int)(ind + 1)- (int)m_warp_params.nsamps_twarp / 2)) / (double)m_warpings.fs_warp; | 708 t_warp[ind] = ((double)((int)(ind + 1)- (int)m_warp_params.nsamps_twarp / 2)) / (double)m_warpings.fs_warp; |
684 } | 709 } |
685 | 710 |
686 // design of warpings for efficient interpolation | 711 // design of warpings for efficient interpolation |
712 for (int i = 0; i < m_warpings.nsamps_torig; i++){ | 737 for (int i = 0; i < m_warpings.nsamps_torig; i++){ |
713 output << t_orig[i] << endl ; | 738 output << t_orig[i] << endl ; |
714 } | 739 } |
715 */ | 740 */ |
716 | 741 |
717 delete [] freq_relative; | 742 deallocate(freq_relative); |
743 deallocate(t_orig); | |
744 deallocate(t_warp); | |
745 | |
718 //output.close(); | 746 //output.close(); |
719 | 747 |
720 /* ============= FFTW PLAN DESIGN ============= */ | 748 /* ============= FFTW PLAN DESIGN ============= */ |
721 // Initialize 2-d array for warped signals | 749 // Initialize 2-d array for warped signals |
722 x_warping = new double[m_warp_params.nsamps_twarp]; | 750 x_warping = allocate<double>(m_warp_params.nsamps_twarp); |
723 m_absFanChirpTransform = (double*)fftw_malloc(sizeof (double) * m_warp_params.num_warps * (m_warp_params.nsamps_twarp/2 + 1)); | 751 m_absFanChirpTransform = allocate<double>(m_warp_params.num_warps * (m_warp_params.nsamps_twarp/2 + 1)); |
724 m_auxFanChirpTransform = (fftw_complex*)fftw_malloc(sizeof ( fftw_complex) * (m_warp_params.nsamps_twarp/2 + 1)); | 752 m_auxFanChirpTransform = allocate<double>(2 * (m_warp_params.nsamps_twarp/2 + 1)); |
725 plan_forward_xwarping = fftw_plan_dft_r2c_1d(m_warp_params.nsamps_twarp, x_warping, m_auxFanChirpTransform, FFTW_ESTIMATE); | 753 fft_xwarping = new FFTReal(m_warp_params.nsamps_twarp); |
726 | |
727 } | 754 } |
728 | 755 |
729 void | 756 void |
730 FChTransformF0gram::design_warps(double * freq_relative, double * t_orig, double * t_warp) { | 757 FChTransformF0gram::design_warps(double * freq_relative, double * t_orig, double * t_warp) { |
731 /* the warping is done by interpolating the original signal in time instants | 758 /* the warping is done by interpolating the original signal in time instants |
732 given by the desired frequency deviation, to do this, the interpolation | 759 given by the desired frequency deviation, to do this, the interpolation |
733 instants are stored in a structure as an integer index and a fractional value | 760 instants are stored in a structure as an integer index and a fractional value |
734 hypothesis: sampling frequency at the central point equals the original | 761 hypothesis: sampling frequency at the central point equals the original |
735 */ | 762 */ |
736 | 763 |
737 m_warpings.pos_int = new int[m_warp_params.num_warps * m_warp_params.nsamps_twarp]; | 764 m_warpings.pos_int = allocate<int>(m_warp_params.num_warps * m_warp_params.nsamps_twarp); |
738 m_warpings.pos_frac = new double[m_warp_params.num_warps * m_warp_params.nsamps_twarp]; | 765 m_warpings.pos_frac = allocate<double>(m_warp_params.num_warps * m_warp_params.nsamps_twarp); |
739 | 766 |
740 // vector of phase values | 767 // vector of phase values |
741 double *phi = new double[m_warpings.nsamps_torig]; | 768 double *phi = allocate<double>(m_warpings.nsamps_torig); |
742 double aux; | 769 double aux; |
743 | 770 |
744 // warped positions | 771 // warped positions |
745 double *pos1 = new double[m_warp_params.nsamps_twarp*m_warp_params.num_warps]; | 772 double *pos1 = allocate<double>(m_warp_params.nsamps_twarp*m_warp_params.num_warps); |
746 | 773 |
747 for (int i = 0; i < m_warp_params.num_warps; i++) { | 774 for (int i = 0; i < m_warp_params.num_warps; i++) { |
748 | 775 |
749 // integration of relative frequency to obtain phase values | 776 // integration of relative frequency to obtain phase values |
750 cumtrapz(t_orig, freq_relative + i*(m_warpings.nsamps_torig), m_warpings.nsamps_torig, phi); | 777 Utils::cumtrapz(t_orig, freq_relative + i*(m_warpings.nsamps_torig), m_warpings.nsamps_torig, phi); |
751 | 778 |
752 // centering of phase values to force original frequency in the middle | 779 // centering of phase values to force original frequency in the middle |
753 aux = phi[m_warpings.nsamps_torig/2]; | 780 aux = phi[m_warpings.nsamps_torig/2]; |
754 for (int j = 0; j < m_warpings.nsamps_torig; j++) { | 781 for (int j = 0; j < m_warpings.nsamps_torig; j++) { |
755 phi[j] -= aux; | 782 phi[j] -= aux; |
756 } //for | 783 } //for |
757 | 784 |
758 // interpolation of phase values to obtain warped positions | 785 // interpolation of phase values to obtain warped positions |
759 interp1(phi, t_orig, m_warpings.nsamps_torig, t_warp, pos1 + i*m_warp_params.nsamps_twarp, m_warp_params.nsamps_twarp); | 786 Utils::interp1(phi, t_orig, m_warpings.nsamps_torig, t_warp, pos1 + i*m_warp_params.nsamps_twarp, m_warp_params.nsamps_twarp); |
760 } | 787 } |
761 | 788 |
762 // % previous sample index | 789 // % previous sample index |
763 // pos1_int = uint32(floor(pos1))'; | 790 // pos1_int = uint32(floor(pos1))'; |
764 // % integer corresponding to previous sample index in "c" | 791 // % integer corresponding to previous sample index in "c" |
771 pos1[j] = pos1[j]*m_warpings.fs_orig + m_warpings.nsamps_torig/2 + 1; | 798 pos1[j] = pos1[j]*m_warpings.fs_orig + m_warpings.nsamps_torig/2 + 1; |
772 m_warpings.pos_int[j] = (int) pos1[j]; | 799 m_warpings.pos_int[j] = (int) pos1[j]; |
773 m_warpings.pos_frac[j] = pos1[j] - (double)(m_warpings.pos_int[j]); | 800 m_warpings.pos_frac[j] = pos1[j] - (double)(m_warpings.pos_int[j]); |
774 } //for | 801 } //for |
775 | 802 |
776 delete [] phi; | 803 deallocate(phi); |
777 delete [] pos1; | 804 deallocate(pos1); |
778 } | 805 } |
779 | 806 |
780 void | 807 void |
781 FChTransformF0gram::define_warps_linear_chirps(double * freq_relative, double * t_orig) { | 808 FChTransformF0gram::define_warps_linear_chirps(double * freq_relative, double * t_orig) { |
782 /** define warps as relative frequency deviation from original frequency | 809 /** define warps as relative frequency deviation from original frequency |
784 freq_relative : relative frequency deviations | 811 freq_relative : relative frequency deviations |
785 */ | 812 */ |
786 if (m_warp_params.alpha_dist == 0) { | 813 if (m_warp_params.alpha_dist == 0) { |
787 | 814 |
788 // linear alpha values spacing | 815 // linear alpha values spacing |
789 m_warpings.chirp_rates = new double [m_warp_params.num_warps]; | 816 m_warpings.chirp_rates = allocate<double>(m_warp_params.num_warps); |
790 // WARNING m_warp_params.num_warps must be odd | 817 // WARNING m_warp_params.num_warps must be odd |
791 m_warpings.chirp_rates[0] = -m_warp_params.alpha_max; | 818 m_warpings.chirp_rates[0] = -m_warp_params.alpha_max; |
792 double increment = (double) m_warp_params.alpha_max / ((m_warp_params.num_warps - 1) / 2); | 819 double increment = (double) m_warp_params.alpha_max / ((m_warp_params.num_warps - 1) / 2); |
793 | 820 |
794 for (int ind = 1; ind < m_warp_params.num_warps; ind++) { | 821 for (int ind = 1; ind < m_warp_params.num_warps; ind++) { |
797 // force zero value | 824 // force zero value |
798 m_warpings.chirp_rates[(int) ((m_warp_params.num_warps - 1) / 2)] = 0; | 825 m_warpings.chirp_rates[(int) ((m_warp_params.num_warps - 1) / 2)] = 0; |
799 | 826 |
800 } else { | 827 } else { |
801 // log alpha values spacing | 828 // log alpha values spacing |
802 m_warpings.chirp_rates = new double [m_warp_params.num_warps]; | 829 m_warpings.chirp_rates = allocate<double>(m_warp_params.num_warps); |
803 | 830 |
804 // force zero value | 831 // force zero value |
805 int middle_point = (int) ((m_warp_params.num_warps - 1) / 2); | 832 int middle_point = (int) ((m_warp_params.num_warps - 1) / 2); |
806 m_warpings.chirp_rates[middle_point] = 0; | 833 m_warpings.chirp_rates[middle_point] = 0; |
807 | 834 |
821 m_warpings.chirp_rates[ind] = -m_warpings.chirp_rates[m_warp_params.num_warps - 1 - ind]; | 848 m_warpings.chirp_rates[ind] = -m_warpings.chirp_rates[m_warp_params.num_warps - 1 - ind]; |
822 } | 849 } |
823 } | 850 } |
824 | 851 |
825 // compute relative frequency deviation | 852 // compute relative frequency deviation |
826 for (int i = 0; i < m_warpings.nsamps_torig; i++) | 853 for (int i = 0; i < m_warpings.nsamps_torig; i++) { |
827 for (int j = 0; j < m_warp_params.num_warps; j++) | 854 for (int j = 0; j < m_warp_params.num_warps; j++) { |
828 freq_relative[j * m_warpings.nsamps_torig + i] = 1.0 + t_orig[i] * m_warpings.chirp_rates[j]; | 855 freq_relative[j * m_warpings.nsamps_torig + i] = 1.0 + t_orig[i] * m_warpings.chirp_rates[j]; |
829 //freq_relative[i * m_warpings.nsamps_torig + j] = 1.0 + t_orig[i] * m_warpings.chirp_rates[j]; | 856 } |
830 //freq_relative[i][j] = 1.0 + t_orig[i] * m_warpings.chirp_rates[j]; | 857 } |
831 } | 858 } |
832 | 859 |
833 void | 860 void |
834 FChTransformF0gram::design_LPF() { | 861 FChTransformF0gram::design_LPF() |
835 | 862 { |
836 // in = (fftw_complex*) fftw_malloc(sizeof (fftw_complex) * tamanoVentana); | 863 double *lp_LPFWindow_aux = allocate<double>(m_blockSize/2+1); |
837 // out = (fftw_complex*) fftw_malloc(sizeof (fftw_complex) * tamanoVentana); | 864 mp_LPFWindow = allocate<double>(m_blockSize/2+1); |
838 // in_window = (float*) fftw_malloc(sizeof (float) * tamanoVentana); | |
839 // p = fftw_plan_dft_1d(tamanoVentana, in, out, FFTW_FORWARD, FFTW_ESTIMATE); | |
840 double *lp_LPFWindow_aux = new double[m_blockSize/2+1]; | |
841 mp_LPFWindow = new double[m_blockSize/2+1]; | |
842 | 865 |
843 int i_max = (int) ((2.0*m_fmax/m_fs) * ( (double)m_blockSize / 2.0 + 1.0 )); | 866 int i_max = (int) ((2.0*m_fmax/m_fs) * ( (double)m_blockSize / 2.0 + 1.0 )); |
844 for (int i = 0; i < m_blockSize/2+1; i++) { | 867 for (int i = 0; i < m_blockSize/2+1; i++) { |
845 if (i >= i_max) { | 868 if (i >= i_max) { |
846 lp_LPFWindow_aux[i] = 0.0; | 869 lp_LPFWindow_aux[i] = 0.0; |
847 } else { | 870 } else { |
848 lp_LPFWindow_aux[i] = 1.0; | 871 lp_LPFWindow_aux[i] = 1.0; |
849 } | 872 } |
850 } | 873 } |
851 LPF_time = (double*)fftw_malloc(sizeof ( double) * m_warpings.nsamps_torig); | 874 |
852 //memset((char*)LPF_time, 0, m_warpings.nsamps_torig * sizeof(double)); | 875 LPF_time = allocate_and_zero<double>(m_warpings.nsamps_torig); |
853 // sustituyo el memset por un for: | 876 LPF_frequency = allocate_and_zero<double>(2 * (m_warpings.nsamps_torig/2 + 1)); |
854 for (int i = 0; i < m_warpings.nsamps_torig; i++) { | 877 |
855 LPF_time[i] = 0.0; | 878 fft_forward_LPF = new FFTReal(m_blockSize); |
856 } | 879 fft_inverse_LPF = new FFTReal(m_warpings.nsamps_torig); |
857 #ifdef DEBUG | |
858 printf(" Corrio primer memset...\n"); | |
859 #endif | |
860 LPF_frequency = (fftw_complex*)fftw_malloc(sizeof ( fftw_complex) * (m_warpings.nsamps_torig/2 + 1)); //tamaño de la fft cuando la entrada es real | |
861 //memset((char*)LPF_frequency, 0, sizeof(fftw_complex) * (m_warpings.nsamps_torig/2 + 1)); | |
862 // sustituyo el memset por un for: | |
863 for (int i = 0; i < (m_warpings.nsamps_torig/2 + 1); i++) { | |
864 LPF_frequency[i][0] = 0.0; | |
865 LPF_frequency[i][1] = 0.0; | |
866 } | |
867 // for (int i=0; i<(m_blockSize/2+1); i++) { | |
868 // LPF_frequency[i] = new fftw_complex; | |
869 // } | |
870 plan_forward_LPF = fftw_plan_dft_r2c_1d(m_blockSize, LPF_time, LPF_frequency, FFTW_ESTIMATE); | |
871 plan_backward_LPF = fftw_plan_dft_c2r_1d(m_warpings.nsamps_torig, LPF_frequency, LPF_time, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT); | |
872 | 880 |
873 int winWidth = 11; | 881 int winWidth = 11; |
874 double *lp_hanningWindow = new double[winWidth]; | 882 double *lp_hanningWindow = allocate<double>(winWidth); |
875 double accum=0; | 883 double accum=0; |
876 for (int i = 0; i < winWidth; i++) { | 884 for (int i = 0; i < winWidth; i++) { |
877 lp_hanningWindow[i]=0.5*(1.0-cos(2*M_PI*(double)(i+1)/((double)winWidth+1.0))); | 885 lp_hanningWindow[i]=0.5*(1.0-cos(2*M_PI*(double)(i+1)/((double)winWidth+1.0))); |
878 accum+=lp_hanningWindow[i]; | 886 accum+=lp_hanningWindow[i]; |
879 | 887 |
892 } | 900 } |
893 mp_LPFWindow[i]=accum; | 901 mp_LPFWindow[i]=accum; |
894 } | 902 } |
895 } | 903 } |
896 | 904 |
897 delete[] lp_LPFWindow_aux; | 905 deallocate(lp_LPFWindow_aux); |
898 delete[] lp_hanningWindow; | 906 deallocate(lp_hanningWindow); |
899 } | 907 } |
900 | 908 |
901 void FChTransformF0gram::apply_LPF() { | 909 void FChTransformF0gram::apply_LPF() |
902 fftw_execute(plan_forward_LPF); | 910 { |
911 fft_forward_LPF->forward(LPF_time, LPF_frequency); | |
912 | |
903 for (int i = 0; i < m_blockSize/2+1; i++) { | 913 for (int i = 0; i < m_blockSize/2+1; i++) { |
904 LPF_frequency[i][0]*=mp_LPFWindow[i]; | 914 LPF_frequency[i*2] *= mp_LPFWindow[i] * m_warpings.nsamps_torig; |
905 LPF_frequency[i][1]*=mp_LPFWindow[i]; | 915 LPF_frequency[i*2 + 1] *= mp_LPFWindow[i] * m_warpings.nsamps_torig; |
906 } | 916 } |
907 fftw_execute(plan_backward_LPF); | 917 |
918 fft_inverse_LPF->inverse(LPF_frequency, LPF_time); | |
908 | 919 |
909 // TODO ver si hay que hacer fftshift para corregir la fase respecto al centro del frame. | 920 // TODO ver si hay que hacer fftshift para corregir la fase respecto al centro del frame. |
910 // nota: además de aplicar el LPF, esta función resamplea la señal original. | 921 // nota: además de aplicar el LPF, esta función resamplea la señal original. |
911 } | 922 } |
912 | 923 |
913 void FChTransformF0gram::clean_LPF() { | 924 void FChTransformF0gram::clean_LPF() |
914 delete[] mp_LPFWindow; | 925 { |
915 | 926 delete fft_forward_LPF; |
916 fftw_destroy_plan(plan_forward_LPF); | 927 delete fft_inverse_LPF; |
917 fftw_destroy_plan(plan_backward_LPF); | 928 deallocate(LPF_time); |
918 fftw_free(LPF_time); | 929 deallocate(LPF_frequency); |
919 fftw_free(LPF_frequency); | 930 deallocate(mp_LPFWindow); |
920 } | 931 } |
921 | 932 |
922 void FChTransformF0gram::reset() { | 933 void FChTransformF0gram::reset() |
923 | 934 { |
924 // Clear buffers, reset stored values, etc | |
925 | |
926 delete [] m_warpings.pos_int; | |
927 delete [] m_warpings.pos_frac; | |
928 | |
929 clean_LPF(); | |
930 | |
931 delete [] m_timeWindow; | |
932 | |
933 delete [] mp_HanningWindow; | |
934 | |
935 // Warping | |
936 delete [] x_warping; | |
937 fftw_destroy_plan(plan_forward_xwarping); | |
938 fftw_free(m_absFanChirpTransform); | |
939 fftw_free(m_auxFanChirpTransform); | |
940 | |
941 // design_GLogS | |
942 delete [] m_glogs_f0; | |
943 delete [] m_glogs; | |
944 delete [] m_glogs_n; | |
945 delete [] m_glogs_index; | |
946 delete [] m_glogs_posint; | |
947 delete [] m_glogs_posfrac; | |
948 delete [] m_glogs_third_harmonic_posint; | |
949 delete [] m_glogs_third_harmonic_posfrac; | |
950 delete [] m_glogs_third_harmonic; | |
951 delete [] m_glogs_fifth_harmonic_posint; | |
952 delete [] m_glogs_fifth_harmonic_posfrac; | |
953 delete [] m_glogs_fifth_harmonic; | |
954 delete [] m_glogs_f0_preference_weights; | |
955 delete [] m_glogs_median_correction; | |
956 delete [] m_glogs_sigma_correction; | |
957 delete [] m_glogs_hf_smoothing_window; | |
958 | |
959 } | 935 } |
960 | 936 |
961 FChTransformF0gram::FeatureSet | 937 FChTransformF0gram::FeatureSet |
962 FChTransformF0gram::process(const float *const *inputBuffers, Vamp::RealTime) { | 938 FChTransformF0gram::process(const float *const *inputBuffers, Vamp::RealTime) { |
963 | 939 |
990 printf(" m_warpings.nsamps_torig = %d.\n",m_warpings.nsamps_torig); | 966 printf(" m_warpings.nsamps_torig = %d.\n",m_warpings.nsamps_torig); |
991 printf(" m_warp_params.num_warps = %d.\n",m_warp_params.num_warps); | 967 printf(" m_warp_params.num_warps = %d.\n",m_warp_params.num_warps); |
992 printf(" m_glogs_harmonic_count = %d.\n",m_glogs_harmonic_count); | 968 printf(" m_glogs_harmonic_count = %d.\n",m_glogs_harmonic_count); |
993 #endif | 969 #endif |
994 | 970 |
995 // int n = m_nfft/2 + 1; | |
996 // double *tbuf = in_window; | |
997 | |
998 for (int i = 0; i < m_blockSize; i++) { | 971 for (int i = 0; i < m_blockSize; i++) { |
999 LPF_time[i] = (double)(inputBuffers[0][i]) * m_timeWindow[i]; | 972 LPF_time[i] = (double)(inputBuffers[0][i]) * m_timeWindow[i]; |
1000 } | 973 } |
1001 | 974 |
1002 // #ifdef DEBUG | 975 // #ifdef DEBUG |
1016 double max_glogs = -DBL_MAX; | 989 double max_glogs = -DBL_MAX; |
1017 int ind_max_glogs = 0; | 990 int ind_max_glogs = 0; |
1018 | 991 |
1019 for (int i_warp = 0; i_warp < m_warp_params.num_warps; i_warp++) { | 992 for (int i_warp = 0; i_warp < m_warp_params.num_warps; i_warp++) { |
1020 // Interpolate | 993 // Interpolate |
1021 interp1q(LPF_time, (m_warpings.pos_int) + i_warp*m_warp_params.nsamps_twarp, m_warpings.pos_frac + i_warp*m_warp_params.nsamps_twarp, x_warping, m_warp_params.nsamps_twarp); | 994 Utils::interp1q(LPF_time, (m_warpings.pos_int) + i_warp*m_warp_params.nsamps_twarp, m_warpings.pos_frac + i_warp*m_warp_params.nsamps_twarp, x_warping, m_warp_params.nsamps_twarp); |
1022 | 995 |
1023 // Apply window | 996 // Apply window |
1024 for (int i = 0; i < m_warp_params.nsamps_twarp; i++) { | 997 for (int i = 0; i < m_warp_params.nsamps_twarp; i++) { |
1025 x_warping[i] *= mp_HanningWindow[i]; | 998 x_warping[i] *= mp_HanningWindow[i]; |
1026 } | 999 } |
1027 | 1000 |
1028 // Transform | 1001 // Transform |
1029 fftw_execute(plan_forward_xwarping); | 1002 fft_xwarping->forward(x_warping, m_auxFanChirpTransform); |
1030 | 1003 |
1031 // Copy result | 1004 // Copy result |
1032 //memcpy(m_absFanChirpTransform + i_warp*(m_warp_params.nsamps_twarp/2+1), m_auxFanChirpTransform, (m_warp_params.nsamps_twarp/2+1)*sizeof(fftw_complex)); asi como esta no funciona | |
1033 double *aux_abs_fcht = m_absFanChirpTransform + i_warp*(m_warp_params.nsamps_twarp/2+1); | 1005 double *aux_abs_fcht = m_absFanChirpTransform + i_warp*(m_warp_params.nsamps_twarp/2+1); |
1034 for (int i = 0; i < (m_warp_params.nsamps_twarp/2+1); i++) { | 1006 for (int i = 0; i < (m_warp_params.nsamps_twarp/2+1); i++) { |
1035 aux_abs_fcht[i] = log10(1.0 + 10.0*sqrt(m_auxFanChirpTransform[i][0]*m_auxFanChirpTransform[i][0]+m_auxFanChirpTransform[i][1]*m_auxFanChirpTransform[i][1])); | 1007 aux_abs_fcht[i] = log10(1.0 + 10.0*sqrt(m_auxFanChirpTransform[i*2]*m_auxFanChirpTransform[i*2]+m_auxFanChirpTransform[i*2+1]*m_auxFanChirpTransform[i*2+1])); |
1036 // smoothing high frequency values | |
1037 //aux_abs_fcht[i] *= m_glogs_hf_smoothing_window[i]; | |
1038 } | 1008 } |
1039 | 1009 |
1040 // ----------------------------------------------------------------------------------------- | 1010 // ----------------------------------------------------------------------------------------- |
1041 // GLogS | 1011 // GLogS |
1042 interp1q(aux_abs_fcht, m_glogs_posint, m_glogs_posfrac, m_glogs_interp, m_glogs_harmonic_count); | 1012 Utils::interp1q(aux_abs_fcht, m_glogs_posint, m_glogs_posfrac, m_glogs_interp, m_glogs_harmonic_count); |
1043 int glogs_ind = 0; | 1013 int glogs_ind = 0; |
1044 for (int i = 0; i < m_glogs_num_f0s; i++) { | 1014 for (int i = 0; i < m_glogs_num_f0s; i++) { |
1045 double glogs_accum = 0; | 1015 double glogs_accum = 0; |
1046 for (int j = 1; j <= m_glogs_n[i]; j++) { | 1016 for (int j = 1; j <= m_glogs_n[i]; j++) { |
1047 glogs_accum += m_glogs_interp[glogs_ind++]; | 1017 glogs_accum += m_glogs_interp[glogs_ind++]; |
1048 } | 1018 } |
1049 m_glogs[i + i_warp*m_glogs_num_f0s] = glogs_accum/(double)m_glogs_n[i]; | 1019 m_glogs[i + i_warp*m_glogs_num_f0s] = glogs_accum/(double)m_glogs_n[i]; |
1050 } | 1020 } |
1051 | 1021 |
1052 // Sub/super harmonic correction | 1022 // Sub/super harmonic correction |
1053 interp1q(m_glogs + i_warp*m_glogs_num_f0s, m_glogs_third_harmonic_posint, m_glogs_third_harmonic_posfrac, m_glogs_third_harmonic, (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); | 1023 Utils::interp1q(m_glogs + i_warp*m_glogs_num_f0s, m_glogs_third_harmonic_posint, m_glogs_third_harmonic_posfrac, m_glogs_third_harmonic, (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); |
1054 interp1q(m_glogs + i_warp*m_glogs_num_f0s, m_glogs_fifth_harmonic_posint, m_glogs_fifth_harmonic_posfrac, m_glogs_fifth_harmonic, (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); | 1024 Utils::interp1q(m_glogs + i_warp*m_glogs_num_f0s, m_glogs_fifth_harmonic_posint, m_glogs_fifth_harmonic_posfrac, m_glogs_fifth_harmonic, (m_f0_params.num_octs+1)*m_f0_params.num_f0s_per_oct); |
1055 for (int i = m_glogs_num_f0s-1; i >= m_glogs_init_f0s; i--) { | 1025 for (int i = m_glogs_num_f0s-1; i >= m_glogs_init_f0s; i--) { |
1056 m_glogs[i + i_warp*m_glogs_num_f0s] -= MAX(MAX(m_glogs[i-m_f0_params.num_f0s_per_oct + i_warp*m_glogs_num_f0s],m_glogs_third_harmonic[i-m_glogs_init_f0s]),m_glogs_fifth_harmonic[i-m_glogs_init_f0s]); | 1026 m_glogs[i + i_warp*m_glogs_num_f0s] -= MAX(MAX(m_glogs[i-m_f0_params.num_f0s_per_oct + i_warp*m_glogs_num_f0s],m_glogs_third_harmonic[i-m_glogs_init_f0s]),m_glogs_fifth_harmonic[i-m_glogs_init_f0s]); |
1057 //m_glogs[i] -= MAX(m_glogs[i-m_f0_params.num_f0s_per_oct],m_glogs_third_harmonic[i-m_glogs_init_f0s]); | 1027 //m_glogs[i] -= MAX(m_glogs[i-m_f0_params.num_f0s_per_oct],m_glogs_third_harmonic[i-m_glogs_init_f0s]); |
1058 } | 1028 } |
1059 for (int i = m_glogs_init_f0s; i < m_glogs_num_f0s-m_f0_params.num_f0s_per_oct; i++) { | 1029 for (int i = m_glogs_init_f0s; i < m_glogs_num_f0s-m_f0_params.num_f0s_per_oct; i++) { |
1072 } | 1042 } |
1073 | 1043 |
1074 // ---------------------------------------------------------------------------------------------- | 1044 // ---------------------------------------------------------------------------------------------- |
1075 | 1045 |
1076 for (int i=m_glogs_init_f0s; i< m_glogs_num_f0s - m_f0_params.num_f0s_per_oct; i++) { | 1046 for (int i=m_glogs_init_f0s; i< m_glogs_num_f0s - m_f0_params.num_f0s_per_oct; i++) { |
1077 //for (int i=0; i<(m_warp_params.nsamps_twarp/2+1); i++) { | |
1078 //feature.values.push_back((float)(m_warpings.pos_int[i])+ (float)(m_warpings.pos_frac[i])); | |
1079 //feature.values.push_back((float)(phi[i]*100000.0)); | |
1080 //feature.values.push_back((float)(t_orig[i])); | |
1081 //feature.values.push_back((float)(pos1[i])); | |
1082 //feature.values.push_back((float)x_warping[i]); | |
1083 //feature.values.push_back(m_absFanChirpTransform[i + ind_max_glogs*(m_warp_params.nsamps_twarp/2+1)]); | |
1084 //feature.values.push_back((float)m_glogs[i+(long)ind_max_glogs*(long)m_glogs_num_f0s]); | |
1085 switch (m_f0gram_mode) { | 1047 switch (m_f0gram_mode) { |
1086 case 1: | 1048 case 1: |
1087 max_glogs = -DBL_MAX; | 1049 max_glogs = -DBL_MAX; |
1088 for (int i_warp = 0; i_warp < m_warp_params.num_warps; i_warp++) { | 1050 for (int i_warp = 0; i_warp < m_warp_params.num_warps; i_warp++) { |
1089 if (m_glogs[i + i_warp*m_glogs_num_f0s] > max_glogs) { | 1051 if (m_glogs[i + i_warp*m_glogs_num_f0s] > max_glogs) { |
1095 break; | 1057 break; |
1096 case 0: | 1058 case 0: |
1097 feature.values.push_back((float)m_glogs[i+(int)ind_max_glogs*(int)m_glogs_num_f0s]); | 1059 feature.values.push_back((float)m_glogs[i+(int)ind_max_glogs*(int)m_glogs_num_f0s]); |
1098 break; | 1060 break; |
1099 } | 1061 } |
1100 //feature.values.push_back((float)m_glogs_hf_smoothing_window[i]); | |
1101 } | 1062 } |
1102 | 1063 |
1103 // ---------------------------------------------------------------------------------------------- | 1064 // ---------------------------------------------------------------------------------------------- |
1104 | 1065 |
1105 fs[0].push_back(feature); | 1066 fs[0].push_back(feature); |
1109 #endif | 1070 #endif |
1110 | 1071 |
1111 return fs; | 1072 return fs; |
1112 //--------------------------------------------------------------------------- | 1073 //--------------------------------------------------------------------------- |
1113 | 1074 |
1114 //return FeatureSet(); | |
1115 } | 1075 } |
1116 | 1076 |
1117 FChTransformF0gram::FeatureSet | 1077 FChTransformF0gram::FeatureSet |
1118 FChTransformF0gram::getRemainingFeatures() { | 1078 FChTransformF0gram::getRemainingFeatures() { |
1119 return FeatureSet(); | 1079 return FeatureSet(); |
1121 | 1081 |
1122 void | 1082 void |
1123 FChTransformF0gram::design_time_window() { | 1083 FChTransformF0gram::design_time_window() { |
1124 | 1084 |
1125 int transitionWidth = (int)m_blockSize/128 + 1;; | 1085 int transitionWidth = (int)m_blockSize/128 + 1;; |
1126 m_timeWindow = new double[m_blockSize]; | 1086 m_timeWindow = allocate<double>(m_blockSize); |
1127 double *lp_transitionWindow = new double[transitionWidth]; | 1087 double *lp_transitionWindow = allocate<double>(transitionWidth); |
1128 | 1088 |
1129 //memset(m_timeWindow, 1.0, m_blockSize); | 1089 //memset(m_timeWindow, 1.0, m_blockSize); |
1130 for (int i = 0; i < m_blockSize; i++) { | 1090 for (int i = 0; i < m_blockSize; i++) { |
1131 m_timeWindow[i] = 1.0; | 1091 m_timeWindow[i] = 1.0; |
1132 } | 1092 } |
1146 printf(" m_timeWindow[%d] = %f.\n",i,m_timeWindow[i]); | 1106 printf(" m_timeWindow[%d] = %f.\n",i,m_timeWindow[i]); |
1147 } | 1107 } |
1148 } | 1108 } |
1149 #endif | 1109 #endif |
1150 | 1110 |
1151 delete [] lp_transitionWindow; | 1111 deallocate(lp_transitionWindow); |
1152 } | 1112 } |
1153 | 1113 |