-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
28 lines (23 loc) · 707 Bytes
/
main.cpp
File metadata and controls
28 lines (23 loc) · 707 Bytes
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
#include <iostream>
#include <fstream>
#include <string>
#include <utility>
#include <cmath>
#include "FileHandler.h"
#include "WaveFileHandler.h"
using namespace std;
// The default byte-write order is little-endian
// It changes only for writing strings, i.e. big-endian (the natural order) is used.
int main() {
WaveFileHandler wave_file("sample.wav");
int sample_rate = 44100;
int frequency = 500;
int duration = 5;
float amplitude = 0.1;
for (int i = 0; i <= sample_rate * duration; i++) {
short value = sin(2 * M_PI * i / sample_rate * frequency) * ((1 << 15) - 1) * amplitude;
wave_file.writeSample(value, 2);
}
wave_file.close();
return 0;
}