summaryrefslogtreecommitdiff
path: root/tests/pke-test-audio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/pke-test-audio.cpp')
-rw-r--r--tests/pke-test-audio.cpp93
1 files changed, 93 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;
+}