#include "pke-at-common.hpp" #include "pke-at-settings.hpp" #include "pke/audio-types.hpp" void pke_at_bpm_reset(uint8_t bpm) { g_at.bpm.last = bpm; g_at.bpm.target = bpm; g_at.bpm.current = bpm; g_at.bpm.lerp_delta = 0.f; g_at.bpm.lerp_delta_duration = 0.f; g_at.bpm.delta_per_beat = 60.f / (double)bpm; g_at.bpm.delta_since_last_beat = 0.f; g_at.mtrnm.beat = 0; g_at.mtrnm.beats_per_bar = 4; } AssetHandle pke_at_audio_get_or_generate_sawtooth(double pitch_freq, double duration) { uint32_t u; uint32_t len; float *bytes; float phase; float phase_increment; pke_asset_details details{}; AssetHandle handle; AssetKey key; snprintf(key, AssetKeyLength, "saw%.5u;%.2f", (uint32_t)pitch_freq, duration); fprintf(stdout, "sawtooth: %s%c\n", key, '\0'); handle = AM_GetHandle(key); if (handle != AssetHandle_MAX) { return handle; } len = std::ceil(PKE_AUDIO_BITRATE * duration); bytes = pk_new_arr(len, g_at.mem.bkt_transient); if (bytes == nullptr) { throw "[pke_at_audio_get_or_generate_sawtooth] failed to alloc"; } phase = 0.0f; phase_increment = pitch_freq / float(PKE_AUDIO_BITRATE); for (u = 0; u < len; ++u) { bytes[u] = 2.f * (phase - floor(phase + 0.5f)); phase += phase_increment; if (phase >= 1.f) phase -= 1.f; } // TODO // details.audio. handle = AM_Register(key, PKE_ASSET_TYPE_AUDIO, bytes, len, 64, &details); return handle; }