Skip to content

Instantly share code, notes, and snippets.

@udalov
Created February 22, 2013 22:41
Show Gist options
  • Select an option

  • Save udalov/5017161 to your computer and use it in GitHub Desktop.

Select an option

Save udalov/5017161 to your computer and use it in GitHub Desktop.

Revisions

  1. udalov created this gist Feb 22, 2013.
    30 changes: 30 additions & 0 deletions gistfile1.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #include <cstdio>
    #include <vector>

    #include <sndfile.h>

    using namespace std;

    int main() {
    SF_INFO sfinfo;
    const int BUF_LEN = 2048;
    double buffer[BUF_LEN];

    SNDFILE* f = sf_open("/Users/udalov/c/ch24/PreEC/input/P/1.wav", SFM_READ, &sfinfo);

    int read;
    vector<double> data;
    while ((read = sf_read_double(f, buffer, BUF_LEN))) {
    for (int i = 0; i < read; i++) {
    data.push_back(buffer[i]);
    }
    }

    printf("Sample rate: %d\n", sfinfo.samplerate);
    printf("Samples: %lu\n", data.size());
    for (size_t i = 0; i < data.size(); i++) {
    printf("%.3lf\n", data[i]);
    }

    return 0;
    }