diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-07-04 07:06:45 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-07-04 07:06:45 -0400 |
| commit | 34863f5b702c0dbb00d8db5c00efd43d895fcd4c (patch) | |
| tree | 09e0249e16e937c22ec0c04cfa1bc4b0e4de337e /tests | |
| parent | 1c87a0e431d30aaf19195f8a45c7607add21018a (diff) | |
pke: audio: first-pass actually play an asset
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/pke-test-audio.cpp | 93 | ||||
| -rw-r--r-- | tests/pke-test-audio.h | 16 | ||||
| -rw-r--r-- | tests/pke-test.cpp | 1 |
3 files changed, 110 insertions, 0 deletions
diff --git a/tests/pke-test-audio.cpp b/tests/pke-test-audio.cpp new file mode 100644 index 0000000..2c1ac97 --- /dev/null +++ b/tests/pke-test-audio.cpp @@ -0,0 +1,93 @@ + +#include "./pke-test-audio.h" + +#include "game-settings.hpp" +#include "pk.h" + +#include "audio-types.hpp" +#include "audio.hpp" +#include "asset-manager.hpp" +#include "thread-pool.hpp" +#include "window.hpp" + +#include <chrono> +#include <thread> +#include <threads.h> + +pk_membucket *bkt = nullptr; + +void pke_test_audio_spinup() { + // pk_funcinstr_init(); + pkeSettings.isSimulationPaused = true; + PkeThreads_Init(); + AM_Init(); + pke_audio_init(); + // pk_funcinstr_teardown(); +}; + +void pke_test_audio_teardown() { + // pk_funcinstr_init(); + pke_audio_teardown(); + AM_Teardown(); + PkeThreads_Teardown(); + bkt = nullptr; + // pk_funcinstr_teardown(); +}; + + +int pke_test_audio_001() { + uint32_t i; + try { + bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE); + + UBO.model = glm::translate(glm::mat4(1.f), glm::vec3(0, 0, 0)); + + float *zip_bop_bytes = pk_new<float>(48000, bkt); + float phase = 0.0f; + float phase_increment = 440.f / 48000.f; + for (i = 0; i < 48000; ++i) { + zip_bop_bytes[i] = 2.f * (phase - floor(phase + 0.5f)); + phase += phase_increment; + if (phase >= 1.f) phase -= 1.f; + } + const AssetKey ak_sawtooth {"sawthooth"}; + AssetHandle ah_sawtooth = AM_Register(ak_sawtooth, PKE_ASSET_TYPE_AUDIO, zip_bop_bytes, sizeof(float) * 48000, 64); + pk_delete<float>(zip_bop_bytes, 48000, bkt); + + pke_audio_play(ah_sawtooth, pke_audio_source_music, glm::vec3(0), pke_audio_flag_none); + + while (pke_audio_mstr.playing_objects.next > 0) { + pke_audio_tick(0.001f); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + + AM_Release(ah_sawtooth); + + } catch (const std::exception &ex) { + pk_mem_bucket_destroy(bkt); + throw; + } + pk_mem_bucket_destroy(bkt); + return 0; +} + +struct pke_test_group *pke_test_audio_get_group() { + static const uint64_t test_count = 1; + static struct pke_test tests[test_count] = { + { + .title = "test 001", + .func = pke_test_audio_001, + .expected_result = 0, + }, + }; + static struct pke_test_group group = {}; + group.title = "audio"; + group.group_setup = nullptr; + group.group_teardown = nullptr; + group.test_setup = pke_test_audio_spinup; + group.test_teardown = pke_test_audio_teardown; + group.n_tests = test_count; + group.tests = &tests[0]; + + return &group; +} diff --git a/tests/pke-test-audio.h b/tests/pke-test-audio.h new file mode 100644 index 0000000..851c695 --- /dev/null +++ b/tests/pke-test-audio.h @@ -0,0 +1,16 @@ +#ifndef PKE_PKE_TEST_AUDIO_H +#define PKE_PKE_TEST_AUDIO_H + +#include "pke-test-types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct pke_test_group *pke_test_audio_get_group(); + +#ifdef __cplusplus +} +#endif + +#endif /* PKE_PKE_TEST_AUDIO_H */ diff --git a/tests/pke-test.cpp b/tests/pke-test.cpp index 473327e..d695aa8 100644 --- a/tests/pke-test.cpp +++ b/tests/pke-test.cpp @@ -1,6 +1,7 @@ #include "./pke-test-types.h" +#include "./pke-test-audio.h" #include "./pke-test-asset-manager.h" #include "./pke-test-dummy.h" #include "./pke-test-serialization.h" |
