From b287d94fe88f4260e4047fd19edcf25cb9e91120 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 3 Jun 2020 21:25:57 +1000 Subject: [PATCH] Rename some functions for consistency. --- research/ma_engine.c | 23 +++++++++++++++++++++-- research/ma_engine.h | 18 +++++++++--------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/research/ma_engine.c b/research/ma_engine.c index ad56bcb9..52684c73 100644 --- a/research/ma_engine.c +++ b/research/ma_engine.c @@ -28,7 +28,7 @@ int main(int argc, char** argv) return -1; } - result = ma_engine_create_sound_from_file(&engine, argv[1], NULL, &sound); + result = ma_engine_sound_init_from_file(&engine, argv[1], NULL, &sound); if (result != MA_SUCCESS) { ma_engine_uninit(&engine); return -1; @@ -40,11 +40,30 @@ int main(int argc, char** argv) ma_engine_sound_start(&engine, &sound); + float pitch = 1; + float pitchStep = 0.01f; + float pitchMin = 0.125f; + float pitchMax = 8; + for (;;) { + pitch += pitchStep; + if (pitch < pitchMin) { + pitch = pitchMin; + pitchStep = -pitchStep; + } + if (pitch > pitchMax) { + pitch = pitchMax; + pitchStep = -pitchStep; + } + + ma_engine_sound_set_pitch(&engine, &sound, pitch); + + Sleep(1); + } printf("Press Enter to quit..."); getchar(); - ma_engine_delete_sound(&engine, &sound); + ma_engine_sound_uninit(&engine, &sound); ma_engine_uninit(&engine); return 0; diff --git a/research/ma_engine.h b/research/ma_engine.h index e460be26..0e969a48 100644 --- a/research/ma_engine.h +++ b/research/ma_engine.h @@ -309,10 +309,10 @@ MA_API ma_result ma_engine_set_volume(ma_engine* pEngine, float volume); MA_API ma_result ma_engine_set_gain_db(ma_engine* pEngine, float gainDB); #ifndef MA_NO_RESOURCE_MANAGER -MA_API ma_result ma_engine_create_sound_from_file(ma_engine* pEngine, const char* pFilePath, ma_sound_group* pGroup, ma_sound* pSound); +MA_API ma_result ma_engine_sound_init_from_file(ma_engine* pEngine, const char* pFilePath, ma_sound_group* pGroup, ma_sound* pSound); #endif -MA_API ma_result ma_engine_create_sound_from_data_source(ma_engine* pEngine, ma_data_source* pDataSource, ma_sound_group* pGroup, ma_sound* pSound); -MA_API void ma_engine_delete_sound(ma_engine* pEngine, ma_sound* pSound); +MA_API ma_result ma_engine_sound_init_from_data_source(ma_engine* pEngine, ma_data_source* pDataSource, ma_sound_group* pGroup, ma_sound* pSound); +MA_API void ma_engine_sound_uninit(ma_engine* pEngine, ma_sound* pSound); MA_API ma_result ma_engine_sound_start(ma_engine* pEngine, ma_sound* pSound); MA_API ma_result ma_engine_sound_stop(ma_engine* pEngine, ma_sound* pSound); MA_API ma_result ma_engine_sound_set_volume(ma_engine* pEngine, ma_sound* pSound, float volume); @@ -1089,7 +1089,7 @@ MA_API ma_result ma_engine_set_gain_db(ma_engine* pEngine, float gainDB) #ifndef MA_NO_RESOURCE_MANAGER -MA_API ma_result ma_engine_create_sound_from_file(ma_engine* pEngine, const char* pFilePath, ma_sound_group* pGroup, ma_sound* pSound) +MA_API ma_result ma_engine_sound_init_from_file(ma_engine* pEngine, const char* pFilePath, ma_sound_group* pGroup, ma_sound* pSound) { ma_result result; ma_data_source* pDataSource; @@ -1111,7 +1111,7 @@ MA_API ma_result ma_engine_create_sound_from_file(ma_engine* pEngine, const char } /* Now that we have our data source we can create the sound using our generic function. */ - result = ma_engine_create_sound_from_data_source(pEngine, pDataSource, pGroup, pSound); + result = ma_engine_sound_init_from_data_source(pEngine, pDataSource, pGroup, pSound); if (result != MA_SUCCESS) { return result; } @@ -1526,7 +1526,7 @@ static ma_result ma_engine_effect_reinit(ma_engine* pEngine, ma_engine_effect* p return ma_engine_effect_init(pEngine, pEffect); } -MA_API ma_result ma_engine_create_sound_from_data_source(ma_engine* pEngine, ma_data_source* pDataSource, ma_sound_group* pGroup, ma_sound* pSound) +MA_API ma_result ma_engine_sound_init_from_data_source(ma_engine* pEngine, ma_data_source* pDataSource, ma_sound_group* pGroup, ma_sound* pSound) { ma_result result; @@ -1561,7 +1561,7 @@ MA_API ma_result ma_engine_create_sound_from_data_source(ma_engine* pEngine, ma_ return MA_SUCCESS; } -MA_API void ma_engine_delete_sound(ma_engine* pEngine, ma_sound* pSound) +MA_API void ma_engine_sound_uninit(ma_engine* pEngine, ma_sound* pSound) { ma_result result; @@ -1798,7 +1798,7 @@ MA_API ma_result ma_engine_play_sound(ma_engine* pEngine, const char* pFilePath, result = ma_engine_effect_reinit(pEngine, &pSound->effect); if (result != MA_SUCCESS) { /* We failed to reinitialize the effect. The sound is currently in a bad state and we need to delete it and return an error. Should never happen. */ - ma_engine_delete_sound(pEngine, pSound); + ma_engine_sound_uninit(pEngine, pSound); return result; } @@ -1811,7 +1811,7 @@ MA_API ma_result ma_engine_play_sound(ma_engine* pEngine, const char* pFilePath, return MA_OUT_OF_MEMORY; } - result = ma_engine_create_sound_from_file(pEngine, pFilePath, pGroup, pSound); + result = ma_engine_sound_init_from_file(pEngine, pFilePath, pGroup, pSound); if (result != MA_SUCCESS) { ma__free_from_callbacks(pEngine, &pEngine->allocationCallbacks); return result;