Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sndfile.h>
- #include <iostream>
- //#include <windows.h>
- using namespace std;
- int main()
- {
- string path = "../libSndChecker/files/song.wav";
- string outPath = "../libSndChecker/files/result.out";
- SNDFILE *sf;
- SF_INFO info;
- int num_channels;
- int num, num_items;
- double* ptr;
- int f,sr,c;
- int i,j;
- FILE *out;
- /* Open the WAV file. */
- info.format = 0;
- sf = sf_open(path.c_str(),SFM_READ,&info);
- if (sf == NULL)
- {
- printf("Failed to open the file.\n");
- return 0;
- }
- /* Print some of the info, and figure out how much data to read. */
- f = info.frames;
- sr = info.samplerate;
- c = info.channels;
- printf("frames=%d\n",f);
- printf("samplerate=%d\n",sr);
- printf("channels=%d\n",c);
- num_items = f*c;
- printf("num_items=%d\n",num_items);
- /* Allocate space for the data to be read, then read it. */
- ptr = new double[num_items];
- num = sf_read_double(sf, ptr, num_items);
- sf_close(sf);
- printf("Read %d items\n",num);
- /* Write the data to filedata.out. */
- out = fopen(outPath.c_str(),"write");
- for (i = 0; i < num; i += c)
- {
- for (j = 0; j < c; ++j)
- fprintf(out,"ch#=%d; fr#=%d; b#=%f ", j, i, ptr[i+j]);
- fprintf(out,"\n");
- //cout << ptr[i+j] << " ";
- }
- fclose(out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement