| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <string.h> |
| 4 |
#include <sndfile.h> |
| 5 |
|
| 6 |
#define BUF_SIZE 8192 |
| 7 |
|
| 8 |
// usage: assert_delta file |
| 9 |
// return values: |
| 10 |
// - 0: pass (file is silence) |
| 11 |
// - 1: fail (noise found) |
| 12 |
// - 2: command line error |
| 13 |
// - 3: file open error |
| 14 |
int main(int argc, char** argv) { |
| 15 |
if (argc<2) return 2; |
| 16 |
|
| 17 |
SF_INFO si; |
| 18 |
memset(&si,0,sizeof(SF_INFO)); |
| 19 |
SNDFILE* sf=sf_open(argv[1],SFM_READ,&si); |
| 20 |
if (sf==NULL) { |
| 21 |
fprintf(stderr,"open: %s\n",sf_strerror(NULL)); |
| 22 |
return 3; |
| 23 |
} |
| 24 |
|
| 25 |
if (si.channels<1) { |
| 26 |
fprintf(stderr,"invalid channel count\n"); |
| 27 |
return 3; |
| 28 |
} |
| 29 |
|
| 30 |
float* buf=malloc(BUF_SIZE*si.channels*sizeof(float)); |
| 31 |
|
| 32 |
sf_count_t totalRead=0; |
| 33 |
size_t seekPos=0; |
| 34 |
while ((totalRead=sf_readf_float(sf,buf,BUF_SIZE))!=0) { |
| 35 |
for (int i=0; i<totalRead*si.channels; i++) { |
| 36 |
if (buf[i]!=0.0f) { |
| 37 |
//printf("%ld\n",seekPos+(i/si.channels)); |
| 38 |
sf_close(sf); |
| 39 |
free(buf); |
| 40 |
return 1; |
| 41 |
} |
| 42 |
} |
| 43 |
seekPos+=BUF_SIZE; |
| 44 |
} |
| 45 |
|
| 46 |
sf_close(sf); |
| 47 |
free(buf); |
| 48 |
return 0; |
| 49 |
} |