mirror of
https://github.com/zserge/fenster.git
synced 2025-07-18 17:56:11 +03:00
formatting
This commit is contained in:
@ -20,25 +20,26 @@ static int run() {
|
|||||||
.height = H,
|
.height = H,
|
||||||
.buf = buf,
|
.buf = buf,
|
||||||
};
|
};
|
||||||
struct fenster_audio fa = {0};
|
struct fenster_audio fa = {0};
|
||||||
fenster_open(&f);
|
fenster_open(&f);
|
||||||
fenster_audio_open(&fa);
|
fenster_audio_open(&fa);
|
||||||
uint32_t t, u = 0;
|
uint32_t t, u = 0;
|
||||||
float audio[FENSTER_AUDIO_BUFSZ];
|
float audio[FENSTER_AUDIO_BUFSZ];
|
||||||
int64_t now = fenster_time();
|
int64_t now = fenster_time();
|
||||||
while (fenster_loop(&f) == 0) {
|
while (fenster_loop(&f) == 0) {
|
||||||
t++;
|
t++;
|
||||||
int n = fenster_audio_available(&fa);
|
int n = fenster_audio_available(&fa);
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
u++;
|
u++;
|
||||||
/*audio[i] = (rand() & 0xff)/256.f;*/
|
/*audio[i] = (rand() & 0xff)/256.f;*/
|
||||||
int x = u * 80/441;
|
int x = u * 80 / 441;
|
||||||
audio[i] = ((((x >> 10) & 42) * x)&0xff)/256.f;
|
audio[i] = ((((x >> 10) & 42) * x) & 0xff) / 256.f;
|
||||||
}
|
}
|
||||||
fenster_audio_write(&fa, audio, n);
|
fenster_audio_write(&fa, audio, n);
|
||||||
}
|
}
|
||||||
if (f.keys[27]) break;
|
if (f.keys[27])
|
||||||
|
break;
|
||||||
|
|
||||||
for (int i = 0; i < 320; i++) {
|
for (int i = 0; i < 320; i++) {
|
||||||
for (int j = 0; j < 240; j++) {
|
for (int j = 0; j < 240; j++) {
|
||||||
@ -54,11 +55,11 @@ static int run() {
|
|||||||
}
|
}
|
||||||
int64_t time = fenster_time();
|
int64_t time = fenster_time();
|
||||||
if (time - now < 1000 / 60) {
|
if (time - now < 1000 / 60) {
|
||||||
fenster_sleep(time - now);
|
fenster_sleep(time - now);
|
||||||
}
|
}
|
||||||
now = time;
|
now = time;
|
||||||
}
|
}
|
||||||
fenster_audio_close(&fa);
|
fenster_audio_close(&fa);
|
||||||
fenster_close(&f);
|
fenster_close(&f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -100,21 +100,26 @@ int snd_pcm_writei(void *, const void *, unsigned long);
|
|||||||
int snd_pcm_recover(void *, int, int);
|
int snd_pcm_recover(void *, int, int);
|
||||||
int snd_pcm_close(void *);
|
int snd_pcm_close(void *);
|
||||||
FENSTER_API int fenster_audio_open(struct fenster_audio *fa) {
|
FENSTER_API int fenster_audio_open(struct fenster_audio *fa) {
|
||||||
if (snd_pcm_open(&fa->pcm, "default", 0, 0)) return -1;
|
if (snd_pcm_open(&fa->pcm, "default", 0, 0))
|
||||||
int fmt = (*(unsigned char *)(&(uint16_t){1}))?14:15;
|
return -1;
|
||||||
|
int fmt = (*(unsigned char *)(&(uint16_t){1})) ? 14 : 15;
|
||||||
return snd_pcm_set_params(fa->pcm, fmt, 3, 1, FENSTER_SAMPLE_RATE, 1, 100000);
|
return snd_pcm_set_params(fa->pcm, fmt, 3, 1, FENSTER_SAMPLE_RATE, 1, 100000);
|
||||||
}
|
}
|
||||||
FENSTER_API int fenster_audio_available(struct fenster_audio *fa) {
|
FENSTER_API int fenster_audio_available(struct fenster_audio *fa) {
|
||||||
int n = snd_pcm_avail(fa->pcm);
|
int n = snd_pcm_avail(fa->pcm);
|
||||||
if (n < 0) snd_pcm_recover(fa->pcm, n, 0);
|
if (n < 0)
|
||||||
|
snd_pcm_recover(fa->pcm, n, 0);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
FENSTER_API void fenster_audio_write(struct fenster_audio *fa, float *buf,
|
FENSTER_API void fenster_audio_write(struct fenster_audio *fa, float *buf,
|
||||||
size_t n) {
|
size_t n) {
|
||||||
int r = snd_pcm_writei(fa->pcm, buf, n);
|
int r = snd_pcm_writei(fa->pcm, buf, n);
|
||||||
if (r < 0) snd_pcm_recover(fa->pcm, r, 0);
|
if (r < 0)
|
||||||
|
snd_pcm_recover(fa->pcm, r, 0);
|
||||||
|
}
|
||||||
|
FENSTER_API void fenster_audio_close(struct fenster_audio *fa) {
|
||||||
|
snd_pcm_close(fa->pcm);
|
||||||
}
|
}
|
||||||
FENSTER_API void fenster_audio_close(struct fenster_audio *fa) { snd_pcm_close(fa->pcm); }
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* FENSTER_HEADER */
|
#endif /* FENSTER_HEADER */
|
||||||
|
Reference in New Issue
Block a user