-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwav2aif.c
96 lines (81 loc) · 1.82 KB
/
wav2aif.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <portsf.h>
enum{ARG_NAME, ARG_INPUT, ARG_OUTPUT, ARGC};
int main(int argc, char *argv[])
{
PSF_PROPS props;
int infile;
int outfile;
float *buffer;
long num_frames;
if(argc!=ARGC)
{
printf("Please use wav2aif as: wav2aif INPUT_WAV OUTPUT_AIF\n");
return 1;
}
if(psf_init())
{
printf("Error: unable to open portsf\n");
return 1;
}
infile = psf_sndOpen(argv[ARG_INPUT], &props, 0);
if(infile<0)
{
printf("Error, unable to read %s\n", argv[ARG_INPUT]);
return 1;
}
props.format = PSF_AIFF;
outfile = psf_sndCreate(argv[ARG_OUTPUT], &props, 0, 0, PSF_CREATE_RDWR);
if(outfile<0)
{
printf("Unable to create %s\n", argv[ARG_OUTPUT]);
return 1;
}
num_frames = (long)psf_sndSize(infile);
buffer = (float*)malloc(num_frames*props.chans*sizeof(float));
if(buffer==NULL)
{
printf("Error unable to allocate buffer\n");
if(psf_sndClose(infile))
{
printf("Warning: error closing %s\n", argv[ARG_INPUT]);
}
if(psf_sndClose(outfile))
{
printf("Warning: error closing %s\n", argv[ARG_OUTPUT]);
}
return 1;
}
printf("Reading %s to buffer \n", argv[ARG_INPUT]);
if(psf_sndReadFloatFrames(infile, buffer, num_frames) !=num_frames)
{
printf("Warning: error writing %s\n", argv[ARG_OUTPUT]);
return 1;
}
printf("Writing %s ... \n", argv[ARG_OUTPUT]);
if(psf_sndWriteFloatFrames(outfile, buffer, num_frames) != num_frames)
{
printf("Warning: error writing %s\n", argv[ARG_OUTPUT]);
return 1;
}
if(infile >= 0)
{
if(psf_sndClose(infile))
{
printf("Warning error closing %s\n", argv[ARG_INPUT]);
}
}
if(outfile >= 0)
{
if(psf_sndClose(outfile))
{
printf("Warning error closing %s\n", argv[ARG_OUTPUT]);
}
printf("Closed fine \n");
}
psf_finish();
printf("Completed format conversion\n");
return 0;
}