summaryrefslogtreecommitdiffhomepage
path: root/src/lingot-audio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lingot-audio.c')
-rw-r--r--src/lingot-audio.c53
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