-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathaudiosample.cpp
More file actions
39 lines (32 loc) · 1.38 KB
/
audiosample.cpp
File metadata and controls
39 lines (32 loc) · 1.38 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
#include <fea/audio/audiosample.hpp>
#include <fea/audio/audiofile.hpp>
#include <fea/assert.hpp>
namespace fea
{
void AudioSample::loadSampleData(const AudioFile& audioFile)
{
std::vector<int16_t> sampleData = audioFile.getSampleData();
FEA_ASSERT(sampleData.size() > 0, "Trying to load samples from a file containing no samples!");
if(!mBuffer)
mBuffer = std::unique_ptr<AudioBuffer>(new AudioBuffer());
ALint format;
switch(audioFile.getChannelCount())
{
case 1 : format = AL_FORMAT_MONO16; break;
case 2 : format = AL_FORMAT_STEREO16; break;
case 4 : format = alGetEnumValue("AL_FORMAT_QUAD16"); break;
case 6 : format = alGetEnumValue("AL_FORMAT_51CHN16"); break;
case 7 : format = alGetEnumValue("AL_FORMAT_61CHN16"); break;
case 8 : format = alGetEnumValue("AL_FORMAT_71CHN16"); break;
default : format = 0; break;
}
// Fixes a bug on OS X supposedly
if (format == -1)
format = 0;
alBufferData(mBuffer->getBufferId(), format, sampleData.data(), sampleData.size() * sizeof(int16_t), audioFile.getSampleRate());
}
const AudioBuffer& AudioSample::getBuffer() const
{
return *mBuffer;
}
}