-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudio.cpp
58 lines (55 loc) · 1.44 KB
/
Audio.cpp
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
//Audio.cpp
//Author: Alan Berman
//30/4/2015
#include <memory>
#include <cstdint>
#include <vector>
#include <numeric>
#include <string>
#include "Audio.h"
//Creates mono/stereo audio clips (instances of the Audio class)
//The clips may be reversed, added, concatenated, cut, added over ranges
//adjusted by a volume factor or normalized. The RMS of the clips may
//also be retrieved.
namespace BRMALA003
{
using namespace std;
void Audio::loadAudio<int8_t>(string inputFile)
{
ifstream file (inputFile, ifstream::binary);
int length;
if (file)
{
//Adapted from http://www.cplusplus.com/reference/istream/istream/tellg/
file.seekg(0,file.end);
length = file.tellg();
file.seekg(0,file.beg);
noSamples = length/(sizeof(int8_t));
for (int i = 0; i<noSamples;++i)
{
char * buffer = new char [length/noSamples];
&(data_vector[i]) = file.read(buffer,(length/noSamples));
delete[] buffer;
}
}
}
void Audio::loadAudio<pair<int16_t,int16_t>>(string inputFile)
{
ifstream file (inputFile, ifstream::binary);
int length;
if (file)
{
//Adapted from http://www.cplusplus.com/reference/istream/istream/tellg/
file.seekg(0,file.end);
length = file.tellg();
file.seekg(0,file.beg);
noSamples = length/(sizeof(int16_t) * 2);
for (int i = 0; i<noSamples;++i)
{
char * buffer = new char [length/noSamples];
&(data_vector[i]) = file.read(buffer,(length/noSamples));
delete[] buffer;
}
}
}
}