mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
Get printvideo audio working on Windows and MacOS
This commit is contained in:
parent
07fde68d52
commit
5d3b91d8b9
18 changed files with 93470 additions and 212 deletions
36
dsp/audio/cosmoaudio/test.c
Normal file
36
dsp/audio/cosmoaudio/test.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "cosmoaudio.h"
|
||||
|
||||
#ifndef M_PIf
|
||||
#define M_PIf 3.14159265358979323846f
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
|
||||
int hz = 44100;
|
||||
int channels = 2;
|
||||
struct CosmoAudio *ca;
|
||||
if (cosmoaudio_open(&ca, hz, channels) != COSMOAUDIO_SUCCESS) {
|
||||
fprintf(stderr, "%s: failed to open audio\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int n = 1000;
|
||||
int sample = 0;
|
||||
float *buf = (float *)malloc(sizeof(float) * channels * n);
|
||||
for (;;) {
|
||||
for (int i = 0; i < 128; i++) {
|
||||
float freq = 440;
|
||||
float t = (float)sample++ / hz;
|
||||
if (sample == hz)
|
||||
sample = 0;
|
||||
buf[i * channels] = sinf(freq * 2.f * M_PIf * t);
|
||||
buf[i * channels + 1] = sinf(freq * 2.f * M_PIf * t);
|
||||
}
|
||||
cosmoaudio_write(ca, buf, 128);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue