33 lines
741 B
C++
33 lines
741 B
C++
#include "pipemini/pipemini.h"
|
|
#include <math.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
int main() {
|
|
const int sample_rate = 48000;
|
|
const float freq = 440.0f;
|
|
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;
|
|
}
|
|
|
|
printf("playing 440 Hz sine for 5 seconds...\n");
|
|
sleep(5);
|
|
|
|
return 0;
|
|
}
|