]> git.sesse.net Git - pitch/blobdiff - pitch.cpp
Port from OSS to ALSA, as OSS is pretty much dying these days.
[pitch] / pitch.cpp
index bc97ee50695d85747aef55b2231483efb9d963c6..421c2f24cea126da2dc786f4a918624dd459ac41 100644 (file)
--- a/pitch.cpp
+++ b/pitch.cpp
@@ -9,16 +9,15 @@
 #include "pitchdetector.h"
 
 void print_spectrogram(double freq, double amp);
-void write_sine(int dsp_fd, double freq, unsigned num_samples);
 
 int main()
 {
        PitchDetector pd(SAMPLE_RATE, FFT_LENGTH, PAD_FACTOR, OVERLAP);
-       int fd = get_dsp_fd(SAMPLE_RATE, FFT_LENGTH, OVERLAP);
+       snd_pcm_t *pcm = get_dsp_handle(SAMPLE_RATE);
        for ( ;; ) {
                short buf[FFT_LENGTH / PAD_FACTOR / OVERLAP];
 
-               read_chunk(fd, buf, FFT_LENGTH / PAD_FACTOR / OVERLAP);
+               read_chunk(pcm, buf, FFT_LENGTH / PAD_FACTOR / OVERLAP);
                std::pair<double, double> peak = pd.detect_pitch(buf);
 
                if (peak.first < 50.0 || peak.second - log10(FFT_LENGTH) < 0.0) {
@@ -78,19 +77,6 @@ void print_spectrogram(double freq, double amp)
 
 }
 #else
-struct note {
-       char notename[16];
-       double freq;
-};
-static note notes[] = {
-       { "E-3", BASE_PITCH/4.0 * (3.0/4.0) },
-       { "A-3", BASE_PITCH/4.0 },
-       { "D-4", BASE_PITCH/4.0 * (4.0/3.0) },
-       { "G-4", BASE_PITCH/4.0 * (4.0/3.0)*(4.0/3.0) },
-       { "B-4", BASE_PITCH * (3.0/4.0)*(3.0/4.0) },
-       { "E-5", BASE_PITCH * (3.0/4.0) }
-};
-
 void print_spectrogram(double freq, double amp)
 {
        double best_away = 999999999.9;