Files
femtosynth/main.cpp
T

33 lines
745 B
C++
Raw Normal View History

2026-07-24 01:12:37 -07:00
#include "pipemini/pipemini.h"
#include <math.h>
#include <stdio.h>
#include <unistd.h>
int main() {
const int sample_rate = 48000;
2026-07-24 01:28:14 -07:00
const float freq = 50.0f;
2026-07-24 01:12:37 -07:00
float phase = 0.0f;
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:28:14 -07:00
printf("playing %f Hz sine for 5 seconds...\n", freq);
sleep(1);
2026-07-24 01:12:37 -07:00
return 0;
}