Skip to content

Commit f55e3f8

Browse files
committed
rework audio data
1 parent dba18b6 commit f55e3f8

16 files changed

Lines changed: 312 additions & 627 deletions

File tree

src/include/sndx/audio/al.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "./al/al.hpp"
44
#include "./al/abo.hpp"
5-
#include "./al/audio_data.hpp"
65
#include "./al/source.hpp"
76
#include "./al/context.hpp"
87
#include "./al/device.hpp"

src/include/sndx/audio/al/abo.hpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "./al.hpp"
44

5-
#include "./audio_data.hpp"
5+
#include "../audio_data.hpp"
66

77
#include "../../mixin/handle.hpp"
88

@@ -55,11 +55,27 @@ namespace sndx::audio {
5555
destroy();
5656
}
5757

58-
ABO& setData(const ALaudioData& data) {
59-
if (auto size = ALsizei(data.getByteSize()); size > 0) {
60-
gen();
61-
alBufferData(m_id, ALenum(data.getFormat()), data.data(), size, ALsizei(data.getFrequency()));
58+
template <class SampleT>
59+
ABO& setData(const AudioData<SampleT>& data) {
60+
if (auto size = ALsizei(data.byteSize()); size <= 0) {
61+
return *this;
6262
}
63+
gen();
64+
65+
66+
if constexpr (std::is_same_v<SampleT, uint8_t> || std::is_same_v<SampleT, int16_t>) {
67+
ALenum format = determineALformat(sizeof(SampleT), data.channels());
68+
alBufferData(m_id, format, data.data(), size, ALsizei(data.frequency()));
69+
}
70+
else {
71+
if (data.channels() > 2)
72+
throw std::runtime_error("OpenAL does not support > 2 channels");
73+
74+
ALenum format = data.channels() == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
75+
auto converted = convert<uint16_t>(data);
76+
alBufferData(m_id, format, converted.data(), size, ALsizei(converted.frequency()));
77+
}
78+
6379
return *this;
6480
}
6581

src/include/sndx/audio/al/al.hpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -108,47 +108,6 @@ namespace sndx::audio {
108108
constexpr unsigned char getBytesPerSample(ALformat format) noexcept {
109109
return static_cast<unsigned char>(getByteDepth(format) * getChannels(format));
110110
}
111-
112-
[[nodiscard]]
113-
constexpr long double getMaxValue(ALformat format) {
114-
if (is8Bit(format)) return (long double)std::numeric_limits<uint8_t>::max();
115-
116-
return (long double)std::numeric_limits<int16_t>::max();
117-
}
118-
119-
[[nodiscard]]
120-
constexpr long double getMinValue(ALformat format) {
121-
if (is8Bit(format)) return (long double)std::numeric_limits<uint8_t>::lowest();
122-
123-
return (long double)std::numeric_limits<int16_t>::lowest();
124-
}
125-
126-
[[nodiscard]]
127-
constexpr long double getCenterValue(ALformat format) {
128-
if (is8Bit(format)) return 128.0l;
129-
130-
return 0.0l;
131-
}
132-
133-
[[nodiscard]]
134-
constexpr ALformat toMono(ALformat format) {
135-
return determineALformat(getBitDepth(format), 1);
136-
}
137-
138-
[[nodiscard]]
139-
constexpr ALformat toStereo(ALformat format) {
140-
return determineALformat(getBitDepth(format), 2);
141-
}
142-
143-
[[nodiscard]]
144-
constexpr ALformat to8Bit(ALformat format) {
145-
return determineALformat(8, getChannels(format));
146-
}
147-
148-
[[nodiscard]]
149-
constexpr ALformat to16Bit(ALformat format) {
150-
return determineALformat(16, getChannels(format));
151-
}
152111
}
153112

154113
#ifdef UNDEF_WIN32_LEAN_AND_MEAN

src/include/sndx/audio/al/audio_data.hpp

Lines changed: 0 additions & 191 deletions
This file was deleted.

0 commit comments

Comments
 (0)