Created
February 22, 2013 22:41
-
-
Save udalov/5017161 to your computer and use it in GitHub Desktop.
libsndfile usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment