-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkcut.c
54 lines (46 loc) · 1.37 KB
/
mkcut.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* Copyright (C) 1999-2011 Erik de Castro Lopo <[email protected]>
* mod rf.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sndfile.h>
#define SAMPLE_RATE 44100
#define SAMPD 2 /* sample duration */
#define SAMCH 2 /* sample duration */
#define SAMPLE_COUNT (SAMPLE_RATE * SAMPD * SAMCH)
int main (int argc, char *argv[])
{
/* argument accounting */
if(argc!=2) {
printf("Error. Pls supply argument (name of file with ints in\n");
exit(EXIT_FAILURE);
}
FILE *fp=fopen(argv[1], "r");
short *si=calloc(SAMPLE_COUNT, sizeof(short));
int ct=0, j;
while(ct<SAMPLE_COUNT) {
j=fscanf(fp, "%hi", si+ct);
ct +=j;
}
fclose(fp);
printf("%hi\n", si[45]);
SNDFILE *file ;
SF_INFO sfinfo ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
/* take these are hard-coded for the time being */
sfinfo.samplerate = SAMPLE_RATE;
sfinfo.frames = SAMPLE_RATE*SAMPD;
sfinfo.channels = SAMCH;
sfinfo.format = (SF_FORMAT_WAV | SF_FORMAT_PCM_16);
if (! (file = sf_open ("cut.wav", SFM_WRITE, &sfinfo))) {
printf ("Error : Not able to open output file.\n") ;
exit(EXIT_FAILURE);
}
if (sf_write_short(file, si, SAMPLE_COUNT) != SAMPLE_COUNT)
puts (sf_strerror (file));
free(si);
sf_close (file) ;
return 0 ;
}