forked from Roplax/AudioTimeStretch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResample.c
More file actions
48 lines (41 loc) · 1.02 KB
/
Resample.c
File metadata and controls
48 lines (41 loc) · 1.02 KB
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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "wav.h"
int main(int argc, char *argv[]) {
char* filename = argv[1];
int stretchFactor = atoi(argv[2]);
if (stretchFactor < 1) {
printf("Invalid stretch factor\n");
return 1;
}
struct wav_info info;
FILE* fp = fopen(filename, "rb");
if (!fp) {
printf("Error reading file\n");
return 1;
}
char* outputName;
asprintf(&outputName, "STRETCH_%s", filename);
FILE* op = fopen(outputName, "wb");
if (!op) {
printf("Error writing file\n");
return 1;
}
read_wav_info(&info, fp);
int originalSampleNum = info.num_samples;
info.num_samples *= stretchFactor;
write_wav_hdr(&info, op);
int_fast32_t sample[info.num_channels];
for (int i = 0; i < originalSampleNum; i++) {
for (int j = 0; j < info.num_channels; j++) {
fread(&sample[j], info.bits_per_sample/8, 1, fp);
}
for (int k = 0; k < stretchFactor; k++) {
write_sample(&info, op, sample);
}
}
fclose(fp);
fclose(op);
printf("Successfully stretched file by given factor\n");
}