-
Notifications
You must be signed in to change notification settings - Fork 15
/
adpcm-driver-test.c
57 lines (48 loc) · 1.41 KB
/
adpcm-driver-test.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
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "adpcm_pcm_mix_driver.h"
#include "tools.h"
#include "wav.h"
int main(int argc, char **argv) {
if(argc < 2) {
fprintf(stderr, "Not enough arguments\n");
return 1;
}
struct adpcm_pcm_mix_driver driver;
adpcm_pcm_mix_driver_init(&driver, 48000, 0);
uint8_t *sample;
size_t sample_len;
sample = load_file(argv[1], &sample_len);
if(!sample) {
fprintf(stderr, "Could not load %s\n", argv[1]);
return 1;
}
adpcm_driver_play((struct adpcm_driver *)&driver, 2, sample, sample_len, 4, 255);
adpcm_driver_play((struct adpcm_driver *)&driver, 4, sample, sample_len, 2, 255);
adpcm_driver_play((struct adpcm_driver *)&driver, 3, sample, sample_len, 0, 255);
struct wav wav;
char wavname[256];
replace_ext(wavname, sizeof(wavname), argv[1], "wav");
wav_open(&wav, wavname, 48000, 2, 16);
int target_samples = 48000 * 6;
stream_sample_t bufL[1024], bufR[1024];
int inc = 1;
for(int i = 0; i <= target_samples; i += inc) {
int estimated = adpcm_pcm_mix_driver_estimate(&driver, inc);
adpcm_pcm_mix_driver_run(&driver, bufL, bufR, estimated);
for(int n = 0; n < estimated; n++) {
if(bufL[n] > 32767)
bufL[n] = 32767;
if(bufL[n] < -32767)
bufL[n] = -32767;
if(bufR[n] > 32767)
bufR[n] = 32767;
if(bufR[n] < -32767)
bufR[n] = -32767;
wav_write_stereo_sample(&wav, bufL[n], bufR[n]);
}
}
wav_close(&wav);
return 0;
}