diff options
| author | pp <pp@455248ca-bdda-0310-9134-f4ebb693071a> | 2008-03-12 15:16:54 +0000 |
|---|---|---|
| committer | pp <pp@455248ca-bdda-0310-9134-f4ebb693071a> | 2008-03-12 15:16:54 +0000 |
| commit | d3a29ffe90c63d508e49a6c89ccdf636cc9c453d (patch) | |
| tree | c3f75d67de38054dea8bf448f14e2c8ff0757954 /src/lingot-audio.c | |
| parent | 4a2b70d02706c2343fdb31e8c6f50fa20b422b88 (diff) | |
- 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
Diffstat (limited to 'src/lingot-audio.c')
| -rw-r--r-- | src/lingot-audio.c | 53 |
1 files changed, 52 insertions, 1 deletions
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 <stdio.h> #include <unistd.h> + +#ifdef PORTAUDIO +#else #include <sys/ioctl.h> #include <fcntl.h> #include <sys/soundcard.h> +#endif + #include <stdlib.h> #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 |
