-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake-sample-wav-file.cc
61 lines (48 loc) · 1.42 KB
/
make-sample-wav-file.cc
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
#define MAKE_SAMPLE_WAV_FILE
#define PROGMEM
#include <stdint.h>
#include <stdio.h>
typedef signed char boolean;
typedef int32_t __int24;
typedef uint32_t __uint24;
inline uint8_t pgm_read_byte(const void* addr) {
const uint8_t* p = static_cast<const uint8_t*>(addr);
return p[0];
}
inline uint16_t pgm_read_word(const void* addr) {
// for little endian cpu
const uint8_t* p = static_cast<const uint8_t*>(addr);
return p[0] | (p[1] << 8);
}
inline uint32_t pgm_read_dword(const void* addr) {
// for little endian cpu
const uint8_t* p = static_cast<const uint8_t*>(addr);
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
}
#define ENABLE_OSCILLATOR_2
#include "./DigitalSynthVRA8Q/common.h"
#include "./DigitalSynthVRA8Q/synth.h"
#include "./wav-file-out.h"
const uint16_t RECORDING_SEC = 60;
const uint16_t SERIAL_SPEED_38400 = 38400;
int main(int argc, char *argv[]) {
// setup
Synth<0>::initialize();
FILE* bin_file = ::fopen(argv[1], "rb");
WAVFileOut<0>::open(argv[2], RECORDING_SEC);
// loop
int c;
while ((c = ::fgetc(bin_file)) != EOF) {
Synth<0>::receive_midi_byte(c);
uint16_t r = SAMPLING_RATE / (SERIAL_SPEED_38400 / 10);
for (uint16_t i = 0; i < r; i++) {
int8_t right_level;
int8_t left_level = Synth<0>::clock(right_level);
WAVFileOut<0>::write(left_level, right_level);
}
}
// teardown
WAVFileOut<0>::close();
::fclose(bin_file);
return 0;
}