Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sndfile.h>
  4. #include <iostream>
  5. //#include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10.     {
  11.     string path = "../libSndChecker/files/song.wav";
  12.     string outPath = "../libSndChecker/files/result.out";
  13.     SNDFILE *sf;
  14.     SF_INFO info;
  15.     int num_channels;
  16.     int num, num_items;
  17.     double* ptr;
  18.     int f,sr,c;
  19.     int i,j;
  20.     FILE *out;
  21.  
  22.     /* Open the WAV file. */
  23.     info.format = 0;
  24.     sf = sf_open(path.c_str(),SFM_READ,&info);
  25.     if (sf == NULL)
  26.     {
  27.         printf("Failed to open the file.\n");
  28.         return 0;
  29.     }
  30.  
  31.     /* Print some of the info, and figure out how much data to read. */
  32.     f = info.frames;
  33.     sr = info.samplerate;
  34.     c = info.channels;
  35.     printf("frames=%d\n",f);
  36.     printf("samplerate=%d\n",sr);
  37.     printf("channels=%d\n",c);
  38.     num_items = f*c;
  39.     printf("num_items=%d\n",num_items);
  40.  
  41.     /* Allocate space for the data to be read, then read it. */
  42.     ptr = new double[num_items];
  43.     num = sf_read_double(sf, ptr, num_items);
  44.     sf_close(sf);
  45.     printf("Read %d items\n",num);
  46.  
  47.     /* Write the data to filedata.out. */
  48.     out = fopen(outPath.c_str(),"write");
  49.     for (i = 0; i < num; i += c)
  50.         {
  51.         for (j = 0; j < c; ++j)
  52.             fprintf(out,"ch#=%d; fr#=%d; b#=%f ", j, i, ptr[i+j]);
  53.             fprintf(out,"\n");
  54.             //cout << ptr[i+j] << " ";
  55.         }
  56.     fclose(out);
  57.  
  58.     return 0;
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement