-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSoundClip.cpp
More file actions
55 lines (44 loc) · 1.06 KB
/
Copy pathSoundClip.cpp
File metadata and controls
55 lines (44 loc) · 1.06 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
#include "Sound/SoundClip.h"
#include "Sound/OggLoader.h"
#include "Sound/WavLoader.h"
#include <algorithm>
#include <cctype>
namespace sh::sound
{
SH_SOUND_API SoundClip::SoundClip() = default;
SH_SOUND_API SoundClip::~SoundClip() = default;
SH_SOUND_API void SoundClip::SetAudioData(const AudioData& data)
{
audioData = data;
RebuildBuffer();
}
SH_SOUND_API void SoundClip::SetAudioData(AudioData&& data)
{
audioData = std::move(data);
RebuildBuffer();
}
SH_SOUND_API void SoundClip::LoadFromFile(const std::filesystem::path& path)
{
std::string ext = path.extension().u8string();
std::transform(ext.begin(), ext.end(), ext.begin(),
[](unsigned char ch)
{
return static_cast<char>(std::tolower(ch));
});
if (ext == ".ogg")
SetAudioData(OggLoader::Load(path));
else
SetAudioData(WavLoader::Load(path));
}
void SoundClip::RebuildBuffer()
{
if (audioData.Empty())
{
buffer.reset();
return;
}
if (buffer == nullptr)
buffer = std::make_unique<SoundBuffer>();
buffer->SetData(audioData);
}
}//namespace