mirror of
https://github.com/zserge/fenster.git
synced 2025-07-19 10:16:14 +03:00
add audio for winmm (8bit for now)
This commit is contained in:
@ -19,7 +19,14 @@ struct fenster_audio {
|
||||
dispatch_semaphore_t full;
|
||||
};
|
||||
#elif defined(_WIN32)
|
||||
struct fenster_audio {};
|
||||
#include <mmsystem.h>
|
||||
#include <windows.h>
|
||||
struct fenster_audio {
|
||||
WAVEHDR header;
|
||||
HWAVEOUT wo;
|
||||
WAVEHDR hdr[2];
|
||||
char buf[2][FENSTER_AUDIO_BUFSZ];
|
||||
};
|
||||
#elif defined(__linux__)
|
||||
struct fenster_audio {
|
||||
void *pcm;
|
||||
@ -87,11 +94,39 @@ FENSTER_API void fenster_audio_write(struct fenster_audio *fa, float *buf,
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
/* TODO */
|
||||
FENSTER_API int fenster_audio_open(struct fenster_audio *f) { return -1; }
|
||||
FENSTER_API int fenster_audio_available(struct fenster_audio *f) { return -1; }
|
||||
FENSTER_API void fenster_audio_write(struct fenster_audio *f, float *buf,
|
||||
size_t n) {}
|
||||
FENSTER_API void fenster_audio_close(struct fenster_audio *f) {}
|
||||
FENSTER_API int fenster_audio_open(struct fenster_audio *fa) {
|
||||
WAVEFORMATEX wfx = {
|
||||
WAVE_FORMAT_PCM, 1, FENSTER_SAMPLE_RATE, FENSTER_SAMPLE_RATE, 1, 8, 0};
|
||||
waveOutOpen(&fa->wo, WAVE_MAPPER, &wfx, 0, 0, CALLBACK_NULL);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
fa->hdr[i].lpData = fa->buf[i];
|
||||
fa->hdr[i].dwBufferLength = FENSTER_AUDIO_BUFSZ;
|
||||
waveOutPrepareHeader(fa->wo, &fa->hdr[i], sizeof(WAVEHDR));
|
||||
waveOutWrite(fa->wo, &fa->hdr[i], sizeof(WAVEHDR));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
FENSTER_API int fenster_audio_available(struct fenster_audio *fa) {
|
||||
for (int i = 0; i < 2; i++)
|
||||
if (fa->hdr[i].dwFlags & WHDR_DONE)
|
||||
return FENSTER_AUDIO_BUFSZ;
|
||||
return 0;
|
||||
}
|
||||
FENSTER_API void fenster_audio_write(struct fenster_audio *fa, float *buf,
|
||||
size_t n) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (fa->hdr[i].dwFlags & WHDR_DONE) {
|
||||
for (unsigned j = 0; j < n; j++) {
|
||||
fa->buf[i][j] = (uint8_t)(buf[j] * 256);
|
||||
}
|
||||
waveOutWrite(fa->wo, &fa->hdr[i], sizeof(WAVEHDR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
FENSTER_API void fenster_audio_close(struct fenster_audio *fa) {
|
||||
waveOutClose(fa->wo);
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
int snd_pcm_open(void **, const char *, int, int);
|
||||
int snd_pcm_set_params(void *, int, int, int, int, int, int);
|
||||
|
Reference in New Issue
Block a user