AudioBuffer.cpp 732 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "AudioBuffer.h"
namespace glare
{
	namespace core
	{
		al::BufferFormat AudioBuffer::format(unsigned bits_per_sample, unsigned channels)
		{
			if (bits_per_sample == 8)
			{
				return channels == 1 ? al::BufferFormat::eMono8 : al::BufferFormat::eStereo8;
			}
			return channels == 1 ? al::BufferFormat::eMono16 : al::BufferFormat::eStereo16;
		}

		AudioBuffer::AudioBuffer(const fs::path &from_file)
		{
17
			m_data = audio::loadWAV(from_file);
18
19
20
21
22
23
24
25
26
27
28
29
			m_format = format(m_data.bits_per_sample, m_data.channels);

			al::bufferData(m_handle, m_format, unsigned(m_data.data.size()), m_data.sample_rate, m_data.data.data());
		}

		unsigned AudioBuffer::id() const
		{
			return m_handle;
		}

	}
}