2026-07-24 01:12:37 -07:00
|
|
|
#include "pipemini/pipemini.h"
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2026-07-24 01:35:42 -07:00
|
|
|
#include "oscillator.cpp"
|
|
|
|
|
|
2026-07-24 01:12:37 -07:00
|
|
|
int main() {
|
|
|
|
|
const int sample_rate = 48000;
|
2026-07-24 01:35:42 -07:00
|
|
|
const float freq = 600.0f;
|
2026-07-24 01:12:37 -07:00
|
|
|
float phase = 0.0f;
|
2026-07-24 01:32:09 -07:00
|
|
|
int duration = 1;
|
2026-07-24 01:12:37 -07:00
|
|
|
|
|
|
|
|
PipeMini audio;
|
|
|
|
|
|
|
|
|
|
bool ok = audio.start([&](int16_t* left, int16_t* right) {
|
|
|
|
|
float s = sinf(phase) * 0.25f; // quiet sine
|
|
|
|
|
int16_t v = (int16_t)(s * 32767.0f);
|
|
|
|
|
*left = v;
|
|
|
|
|
*right = v;
|
|
|
|
|
|
|
|
|
|
phase += 2.0f * 3.14159265f * freq / sample_rate;
|
|
|
|
|
if (phase > 2.0f * 3.14159265f) phase -= 2.0f * 3.14159265f;
|
|
|
|
|
}, sample_rate);
|
|
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
fprintf(stderr, "failed to start audio\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-24 01:32:09 -07:00
|
|
|
printf("playing %f Hz sine for %d seconds...\n", freq, duration);
|
|
|
|
|
sleep(duration);
|
2026-07-24 01:12:37 -07:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|