-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathwav-write.cpp
More file actions
48 lines (41 loc) · 1.06 KB
/
wav-write.cpp
File metadata and controls
48 lines (41 loc) · 1.06 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
#define DR_WAV_IMPLEMENTATION
#include <iostream>
#include <string>
#include "dr_wav.h"
using namespace std;
int main(int argc, char* argv[]) {
string fileName("out.wav");
if (argc > 1) fileName = argv[1];
string line;
getline(cin, line);
bool stereo = line.find(",") != string::npos;
drwav_data_format format;
format.channels = stereo ? 2 : 1;
format.container = drwav_container_riff;
format.format = DR_WAVE_FORMAT_IEEE_FLOAT;
format.sampleRate = 48000;
format.bitsPerSample = 32;
drwav* pWav = drwav_open_file_write(fileName.c_str(), &format);
if (stereo) {
while (line != "") {
float f[2] = {0};
f[0] = stof(line);
f[1] = stof(line.substr(1 + line.find(",")));
if (2 != drwav_write(pWav, 2, &f)) {
cout << "FAIL" << endl;
exit(1);
}
getline(std::cin, line);
}
} else {
while (line != "") {
float f = stof(line);
if (1 != drwav_write(pWav, 1, &f)) {
cout << "FAIL" << endl;
exit(1);
}
getline(std::cin, line);
}
}
drwav_close(pWav);
}