-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConverters.cpp
More file actions
63 lines (57 loc) · 2.18 KB
/
Copy pathConverters.cpp
File metadata and controls
63 lines (57 loc) · 2.18 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "Converters.h"
#include "WAVParser.h"
#include "SoundProcessor.h"
#include <algorithm>
#include <iostream>
void Converters::MuteConverter::convert(SamplesProduct* input) {
for(unsigned long long i = start * SAMPLES_IN_SECOND; i < std::min(input->size(), (unsigned long long)end * SAMPLES_IN_SECOND); i++) {
(*input)[i] = 0;
}
}
Converters::MuteConverter::MuteConverter(std::vector<std::string> args) {
if (args.size() != 3) {
throw std::runtime_error("Wrong number of arguments for mute converter");
}
start = std::stoi(args[1]);
end = std::stoi(args[2]);
}
void Converters::MixConverter::convert(SamplesProduct* input) {
WAVParser parser(fileName);
std::vector<short int> toMixWith = parser.parse();
int j = 0;
for(unsigned long long i = time * SAMPLES_IN_SECOND; i < std::min(input->size(), time * SAMPLES_IN_SECOND + toMixWith.size()); i++) {
(*input)[i] = (toMixWith[j++] + (*input)[i]) / 2;
}
}
Converters::MixConverter::MixConverter(std::vector<std::string> args) {
if (args.size() != 2 and args.size() != 3) {
throw std::runtime_error("Wrong number of arguments for mix converter");
} else if (args.size() == 2) {
time = 0;
} else {
time = std::stoi(args[2]);
}
fileName = SoundProcessor::other_input_names[stoi(args[1].substr(1))];
}
void Converters::VolumeConverter::convert(SamplesProduct* input) {
if(start == -1) {
for(short int& sample : *input) {
sample *= factor;
}
} else {
for(unsigned long long i = start * SAMPLES_IN_SECOND; i < std::min(input->size(), (unsigned long long)end * SAMPLES_IN_SECOND); i++) {
(*input)[i] = (*input)[i] * factor;
}
}
}
Converters::VolumeConverter::VolumeConverter(std::vector<std::string> args) {
if (args.size() != 2 and args.size() != 4) {
throw std::runtime_error("Wrong number of arguments for volume converter");
} else if (args.size() == 2) {
factor = std::stof(args[1]);
} else {
factor = std::stof(args[1]);
start = std::stoi(args[2]);
end = std::stoi(args[3]);
}
}