99#include < vector>
1010#include < memory>
1111#include < stdexcept>
12- #include < cassert>
1312#include " Logger.hpp"
1413
1514namespace audio {
1615
16+ struct DeviceInfo {
17+ std::string name;
18+ ma_device_id id;
19+ };
20+
1721class AudioEngine {
18- public:
19- struct DeviceInfo {
20- std::string name;
21- ma_device_id id;
22- };
2322
2423private:
2524 ma_context context_{};
@@ -91,7 +90,7 @@ class AudioEngine {
9190 RECORD_FUNC_TO_BACKTRACE (" AudioEngine::initEngineForDevice" );
9291 LOG_INFO (" Initializing playback device..." );
9392
94- assert (deviceId != nullptr && " initEngineForDevice called with nullptr deviceId" );
93+ ASSERT_MSG (deviceId != nullptr , " initEngineForDevice called with nullptr deviceId" );
9594
9695 auto device = std::make_unique<ma_device>();
9796 auto engine = std::make_unique<ma_engine>();
@@ -105,7 +104,7 @@ class AudioEngine {
105104 deviceConfig.pUserData = nullptr ;
106105
107106 ma_result result = ma_device_init (&context_, &deviceConfig, device.get ());
108- assert (result == MA_SUCCESS && " ma_device_init failed" );
107+ ASSERT_MSG (result == MA_SUCCESS , " ma_device_init failed" );
109108 if (result != MA_SUCCESS ) {
110109 LOG_CRITICAL (" Failed to initialize playback device." );
111110 throw std::runtime_error (" Failed to initialize playback device" );
@@ -117,18 +116,18 @@ class AudioEngine {
117116 engineConfig.noAutoStart = MA_TRUE ;
118117
119118 result = ma_engine_init (&engineConfig, engine.get ());
120- assert (result == MA_SUCCESS && " ma_engine_init failed" );
119+ ASSERT_MSG (result == MA_SUCCESS , " ma_engine_init failed" );
121120 if (result != MA_SUCCESS ) {
122121 LOG_ERROR (" Failed to initialize engine for device." );
123122 ma_device_uninit (device.get ());
124123 throw std::runtime_error (" Failed to initialize engine for device" );
125124 }
126125
127126 device->pUserData = engine.get ();
128- assert (device->pUserData == engine.get () && " pUserData pointer assignment failed!" );
127+ ASSERT_MSG (device->pUserData == engine.get (), " pUserData pointer assignment failed!" );
129128
130129 result = ma_engine_start (engine.get ());
131- assert (result == MA_SUCCESS && " ma_engine_start failed" );
130+ ASSERT_MSG (result == MA_SUCCESS , " ma_engine_start failed" );
132131 if (result != MA_SUCCESS ) {
133132 LOG_ERROR (" Failed to start audio engine." );
134133 ma_engine_uninit (engine.get ());
@@ -141,14 +140,14 @@ class AudioEngine {
141140 devices_.push_back (std::move (device));
142141 engines_.push_back (std::move (engine));
143142
144- assert (devices_.size () == engines_.size () && " Device/Engine arrays should match 1:1" );
145- assert (devices_.back ()->pUserData != nullptr && " Device pUserData should not be null after init" );
143+ ASSERT_MSG (devices_.size () == engines_.size (), " Device/Engine arrays should match 1:1" );
144+ ASSERT_MSG (devices_.back ()->pUserData != nullptr , " Device pUserData should not be null after init" );
146145 }
147146
148147 void loadSound (const std::string& filepath, size_t engineIndex = 0 ) {
149148 RECORD_FUNC_TO_BACKTRACE (" AudioEngine::loadSound" );
150- assert (!filepath.empty () && " Empty filepath passed to loadSound()" );
151- assert (engineIndex < engines_.size () && " Engine index out of range before loadSound" );
149+ ASSERT_MSG (!filepath.empty (), " Empty filepath passed to loadSound()" );
150+ ASSERT_MSG (engineIndex < engines_.size (), " Engine index out of range before loadSound" );
152151
153152 LOG_INFO (" Loading sound: {}" , filepath);
154153
@@ -160,7 +159,7 @@ class AudioEngine {
160159 MA_RESOURCE_MANAGER_DATA_SOURCE_FLAG_STREAM ,
161160 nullptr , nullptr , sound.get ());
162161
163- assert (result == MA_SUCCESS && " ma_sound_init_from_file failed" );
162+ ASSERT_MSG (result == MA_SUCCESS , " ma_sound_init_from_file failed" );
164163 if (result != MA_SUCCESS ) {
165164 LOG_ERROR (" Failed to load sound: {}" , filepath);
166165 throw std::runtime_error (" Failed to load sound: " + filepath);
@@ -174,26 +173,26 @@ class AudioEngine {
174173
175174 void play (size_t soundIndex = 0 ) {
176175 RECORD_FUNC_TO_BACKTRACE (" AudioEngine::play" );
177- assert (soundIndex < sounds_.size () && " Invalid sound index in play()" );
176+ ASSERT_MSG (soundIndex < sounds_.size (), " Invalid sound index in play()" );
178177 LOG_INFO (" Playing sound index {}" , soundIndex);
179178 ma_sound_start (sounds_[soundIndex].get ());
180179 }
181180
182181 void pause (size_t soundIndex = 0 ) {
183- assert (soundIndex < sounds_.size () && " Invalid sound index in pause()" );
182+ ASSERT_MSG (soundIndex < sounds_.size (), " Invalid sound index in pause()" );
184183 LOG_INFO (" Pausing sound index {}" , soundIndex);
185184 ma_sound_stop (sounds_[soundIndex].get ());
186185 }
187186
188187 void restart (size_t soundIndex = 0 ) {
189- assert (soundIndex < sounds_.size () && " Invalid sound index in restart()" );
188+ ASSERT_MSG (soundIndex < sounds_.size (), " Invalid sound index in restart()" );
190189 LOG_INFO (" Restarting sound index {}" , soundIndex);
191190 ma_sound_seek_to_pcm_frame (sounds_[soundIndex].get (), 0 );
192191 ma_sound_start (sounds_[soundIndex].get ());
193192 }
194193
195194 [[nodiscard]] auto getPlaybackTime (size_t soundIndex = 0 ) const -> std::pair<double, double> {
196- assert (soundIndex < sounds_.size () && " Invalid sound index in getPlaybackTime()" );
195+ ASSERT_MSG (soundIndex < sounds_.size (), " Invalid sound index in getPlaybackTime()" );
197196 ma_uint64 cursor{}, total{};
198197 ma_sound_get_cursor_in_pcm_frames (sounds_[soundIndex].get (), &cursor);
199198 ma_sound_get_length_in_pcm_frames (sounds_[soundIndex].get (), &total);
@@ -204,7 +203,7 @@ class AudioEngine {
204203
205204 void seekTo (double seconds, size_t soundIndex = 0 ) {
206205 RECORD_FUNC_TO_BACKTRACE (" AudioEngine::seekTo" );
207- assert (soundIndex < sounds_.size () && " Invalid sound index in seekTo()" );
206+ ASSERT_MSG (soundIndex < sounds_.size (), " Invalid sound index in seekTo()" );
208207
209208 ma_uint64 frame = secondsToFrames (seconds);
210209
@@ -218,7 +217,7 @@ class AudioEngine {
218217
219218 void seekForward (double seconds, size_t soundIndex = 0 ) {
220219 RECORD_FUNC_TO_BACKTRACE (" AudioEngine::seekForward" );
221- assert (soundIndex < sounds_.size () && " Invalid sound index in seekForward()" );
220+ ASSERT_MSG (soundIndex < sounds_.size (), " Invalid sound index in seekForward()" );
222221
223222 ma_uint64 offsetFrames = secondsToFrames (seconds);
224223
@@ -234,7 +233,7 @@ class AudioEngine {
234233
235234 void seekBackward (double seconds, size_t soundIndex = 0 ) {
236235 RECORD_FUNC_TO_BACKTRACE (" AudioEngine::seekBackward" );
237- assert (soundIndex < sounds_.size () && " Invalid sound index in seekBackward()" );
236+ ASSERT_MSG (soundIndex < sounds_.size (), " Invalid sound index in seekBackward()" );
238237
239238 ma_uint64 offsetFrames = secondsToFrames (seconds);
240239
@@ -249,15 +248,15 @@ class AudioEngine {
249248
250249 void setVolume (float volume, size_t soundIndex = 0 ) {
251250 RECORD_FUNC_TO_BACKTRACE (" AudioEngine::setVolume" );
252- assert (soundIndex < sounds_.size () && " Invalid sound index in setVolume()" );
253- assert (volume >= 0 .0f && volume <= 1 .5f && " Volume out of safe range (0.0 - 1.5)" );
251+ ASSERT_MSG (soundIndex < sounds_.size (), " Invalid sound index in setVolume()" );
252+ ASSERT_MSG (volume >= 0 .0f && volume <= 1 .5f , " Volume out of safe range (0.0 - 1.5)" );
254253 LOG_INFO (" Setting volume of sound {} to {:.2f}" , soundIndex, volume);
255254 ma_sound_set_volume (sounds_[soundIndex].get (), volume);
256255 }
257256
258257 void printDeviceInfo (size_t deviceIndex = 0 ) const {
259258 RECORD_FUNC_TO_BACKTRACE (" AudioEngine::printDeviceInfo" );
260- assert (deviceIndex < devices_.size () && " Invalid device index in printDeviceInfo()" );
259+ ASSERT_MSG (deviceIndex < devices_.size (), " Invalid device index in printDeviceInfo()" );
261260 const auto & dev = *devices_[deviceIndex];
262261 LOG_INFO (" Device Info -> Name: {}, Channels: {}, SampleRate: {}" ,
263262 dev.playback .name , dev.playback .channels , dev.sampleRate );
@@ -281,7 +280,7 @@ class AudioEngine {
281280 sounds_.clear ();
282281
283282 for (auto & engine : engines_) {
284- assert (engine->pDevice != nullptr && " Engine has null device pointer during cleanup" );
283+ ASSERT_MSG (engine->pDevice != nullptr , " Engine has null device pointer during cleanup" );
285284 ma_engine_uninit (engine.get ());
286285 }
287286 engines_.clear ();
@@ -330,9 +329,9 @@ class AudioEngine {
330329
331330 static void dataCallback (ma_device* pDevice, void * pOutput, const void * pInput, ma_uint32 frameCount) {
332331 (void )pInput;
333- assert (pDevice != nullptr && " dataCallback got null device pointer" );
332+ ASSERT_MSG (pDevice != nullptr , " dataCallback got null device pointer" );
334333 auto * engine = recast<ma_engine*>(pDevice->pUserData );
335- assert (engine != nullptr && " dataCallback: pUserData is null!" );
334+ ASSERT_MSG (engine != nullptr , " dataCallback: pUserData is null!" );
336335 ma_engine_read_pcm_frames (engine, pOutput, frameCount, nullptr );
337336 }
338337
0 commit comments