-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSound.cpp
More file actions
48 lines (36 loc) · 1.08 KB
/
Sound.cpp
File metadata and controls
48 lines (36 loc) · 1.08 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
// GettingStarted.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include "sndfile.h"
#include "Include/Sound.h"
#include "Include/Preprocessing.h"
#undef main
using namespace std;
Sound::Sound(vector <double> signal, int samples, int rate) : audioSignal(signal), sampleCount(samples), sampleRate(rate)
{
}
const int Sound::getSampleCount() const
{
return this->sampleCount;
}
const int Sound::getSampleRate() const
{
return this->sampleRate;
}
const vector <double> Sound::getAudioSignal() const
{
return this->audioSignal;
}
Sound getSoundFromFile(const char * filepath)
{
SF_INFO audioInfo;
SNDFILE * sndFile = sf_open(filepath, SFM_READ, &audioInfo);
double * buffer = new double[audioInfo.channels * audioInfo.frames];
sf_readf_double(sndFile, buffer, audioInfo.frames);
vector <double> signal = downMix(buffer, audioInfo.frames, audioInfo.channels);
delete[] buffer;
sf_close(sndFile);
return Sound(signal, audioInfo.frames, audioInfo.samplerate);
}