]> git.sesse.net Git - pitch/blobdiff - pitch.cpp
Compile with -Wall.
[pitch] / pitch.cpp
index 1f639d6a22340d0b34d43e74288ad4646c54668a..1c272f1080b734bb7ae891611660edf6c915d2c0 100644 (file)
--- a/pitch.cpp
+++ b/pitch.cpp
@@ -93,6 +93,11 @@ int get_dsp_fd()
        int rate = SAMPLE_RATE;
        ioctl(fd, SOUND_PCM_WRITE_RATE, &rate);
 
        int rate = SAMPLE_RATE;
        ioctl(fd, SOUND_PCM_WRITE_RATE, &rate);
 
+       int max_fragments = 2;
+       int frag_shift = ffs(FFT_LENGTH / OVERLAP) - 1;
+       int fragments = (max_fragments << 16) | frag_shift;
+        ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fragments);
+       
        ioctl(3, SNDCTL_DSP_SYNC, 0);
        
        return fd;
        ioctl(3, SNDCTL_DSP_SYNC, 0);
        
        return fd;
@@ -243,7 +248,8 @@ std::pair<double, double> find_peak(double *in, unsigned num_samples)
 std::pair<double, double> adjust_for_overtones(std::pair<double, double> base, double *in, unsigned num_samples)
 {
        double mu = base.first, var = 1.0 / (base.second * base.second);
 std::pair<double, double> adjust_for_overtones(std::pair<double, double> base, double *in, unsigned num_samples)
 {
        double mu = base.first, var = 1.0 / (base.second * base.second);
-       printf("mu=%f, var=%f\n", mu, var);
+               
+       //printf("Base at %.2f (amp=%5.2fdB)\n", base.first, base.second);
 
        for (unsigned i = 2; i < 10; ++i) {
                unsigned middle = unsigned(floor(freq_to_bin(base.first, num_samples) * i + 0.5));
 
        for (unsigned i = 2; i < 10; ++i) {
                unsigned middle = unsigned(floor(freq_to_bin(base.first, num_samples) * i + 0.5));
@@ -283,8 +289,6 @@ std::pair<double, double> adjust_for_overtones(std::pair<double, double> base, d
                double k = var / (var + this_var);
                mu = (1.0 - k) * mu + k * this_mu;
                var *= (1.0 - k);
                double k = var / (var + this_var);
                mu = (1.0 - k) * mu + k * this_mu;
                var *= (1.0 - k);
-
-               printf("mu=%f, var=%f\n", mu, var);
        }
        return std::make_pair(mu, base.second);
 }
        }
        return std::make_pair(mu, base.second);
 }