Add saner treatment of the fragments setting. Remove some debugging crap.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 2 Apr 2006 13:18:48 +0000 (13:18 +0000)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 2 Apr 2006 13:18:48 +0000 (13:18 +0000)
pitch.cpp

index 4e0e3eb..13efaf8 100644 (file)
--- a/pitch.cpp
+++ b/pitch.cpp
@@ -93,7 +93,9 @@ int get_dsp_fd()
        int rate = SAMPLE_RATE;
        ioctl(fd, SOUND_PCM_WRITE_RATE, &rate);
 
-       int fragments = 0x00020002;
+       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);
@@ -246,7 +248,6 @@ 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);
-       printf("mu=%f, var=%f\n", mu, var);
 
        for (unsigned i = 2; i < 10; ++i) {
                unsigned middle = unsigned(floor(freq_to_bin(base.first, num_samples) * i + 0.5));
@@ -286,8 +287,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);
-
-               printf("mu=%f, var=%f\n", mu, var);
        }
        return std::make_pair(mu, base.second);
 }