From d3a29ffe90c63d508e49a6c89ccdf636cc9c453d Mon Sep 17 00:00:00 2001 From: pp Date: Wed, 12 Mar 2008 15:16:54 +0000 Subject: - add PortAudio sound backend - audio format argument removed from lingot_audio_new(), as it was specific to OSS backend - DIE macro, so on Windows error message will be displayed in a dialog box instead of being lost git-svn-id: https://lampka.siedziba.pl:790/svn/repos/lingot-win32@292 455248ca-bdda-0310-9134-f4ebb693071a --- src/lingot-audio.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'src/lingot-audio.c') diff --git a/src/lingot-audio.c b/src/lingot-audio.c index a0776f6..92d4f2c 100644 --- a/src/lingot-audio.c +++ b/src/lingot-audio.c @@ -23,21 +23,43 @@ #include #include + +#ifdef PORTAUDIO +#else #include #include #include +#endif + #include #include "lingot-defs.h" #include "lingot-audio.h" +#ifdef __WIN32__ +#include "windows.h" +char _die_err[100]; +#define DIE(...) \ +do { snprintf(_die_err, sizeof(_die_err), __VA_ARGS__); \ + MessageBox(NULL, _die_err, "Fatal error", MB_OK | MB_ICONEXCLAMATION); \ + exit(1); } \ +while (0) +#else +#define DIE(...) do { fprintf(stderr, __VA_ARGS__); exit(1); } while (0) +#endif + LingotAudio * -lingot_audio_new (int channels, int rate, int format, char *fdsp) +lingot_audio_new (int channels, int rate, char *fdsp) { LingotAudio *audio; #ifdef ALSA snd_pcm_hw_params_t *hw_params; int err; +#elif defined PORTAUDIO + PaError err; + +#else + int format = AFMT_S16_LE; #endif audio = malloc (sizeof (LingotAudio)); @@ -116,6 +138,26 @@ lingot_audio_new (int channels, int rate, int format, char *fdsp) exit (1); } +#elif defined PORTAUDIO + + if ((err = Pa_Initialize()) != paNoError) + { + DIE ("PortAudio error: %s\n", Pa_GetErrorText( err ) ); + } + if ((err = Pa_OpenDefaultStream( &audio->stream, channels, 0, paInt16, rate, + paFramesPerBufferUnspecified, NULL, + NULL)) != paNoError) + { + DIE ("PortAudio error: %s\n", Pa_GetErrorText( err ) ); + } + + if ((err = Pa_StartStream(audio->stream)) != paNoError) + { + DIE ("PortAudio error: %s\n", Pa_GetErrorText( err ) ); + } + + audio->framesize = Pa_GetSampleSize( paInt16 ) * channels; + #else audio->dsp = open (fdsp, O_RDONLY); @@ -202,6 +244,8 @@ lingot_audio_destroy (LingotAudio * audio) { #ifdef ALSA snd_pcm_close (audio->capture_handle); +#elif defined PORTAUDIO + Pa_Terminate(); #else close (audio->dsp); free (audio); @@ -213,6 +257,13 @@ lingot_audio_read (LingotAudio * audio, void *buffer, int size) { #ifdef ALSA return snd_pcm_readi (audio->capture_handle, buffer, size); +#elif defined PORTAUDIO + PaError err; + if (((err = Pa_ReadStream(audio->stream, buffer, size / audio->framesize)) != paNoError) && (err != paInputOverflowed)) + { + DIE ("PortAudio error: %s\n", Pa_GetErrorText( err ) ); + } + return size; #else return read (audio->dsp, buffer, size); #endif -- cgit v1.2.3