aboutsummaryrefslogtreecommitdiff
path: root/plugins/dfsound/alsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/dfsound/alsa.c')
-rw-r--r--plugins/dfsound/alsa.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/plugins/dfsound/alsa.c b/plugins/dfsound/alsa.c
index c67943a..58900cc 100644
--- a/plugins/dfsound/alsa.c
+++ b/plugins/dfsound/alsa.c
@@ -15,21 +15,17 @@
* *
***************************************************************************/
-#include "stdafx.h"
-
-#define _IN_OSS
-
-#include "externals.h"
-
+#include <stdio.h>
#define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API
#include <alsa/asoundlib.h>
+#include "out.h"
static snd_pcm_t *handle = NULL;
static snd_pcm_uframes_t buffer_size;
// SETUP SOUND
-void SetupSound(void)
+static int alsa_init(void)
{
snd_pcm_hw_params_t *hwparams;
snd_pcm_status_t *status;
@@ -49,13 +45,13 @@ void SetupSound(void)
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) < 0)
{
printf("Audio open error: %s\n", snd_strerror(err));
- return;
+ return -1;
}
if((err = snd_pcm_nonblock(handle, 0))<0)
{
printf("Can't set blocking moded: %s\n", snd_strerror(err));
- return;
+ return -1;
}
snd_pcm_hw_params_alloca(&hwparams);
@@ -63,63 +59,64 @@ void SetupSound(void)
if((err=snd_pcm_hw_params_any(handle, hwparams))<0)
{
printf("Broken configuration for this PCM: %s\n", snd_strerror(err));
- return;
+ return -1;
}
if((err=snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED))<0)
{
printf("Access type not available: %s\n", snd_strerror(err));
- return;
+ return -1;
}
if((err=snd_pcm_hw_params_set_format(handle, hwparams, format))<0)
{
printf("Sample format not available: %s\n", snd_strerror(err));
- return;
+ return -1;
}
if((err=snd_pcm_hw_params_set_channels(handle, hwparams, pchannels))<0)
{
printf("Channels count not available: %s\n", snd_strerror(err));
- return;
+ return -1;
}
if((err=snd_pcm_hw_params_set_rate_near(handle, hwparams, &pspeed, 0))<0)
{
printf("Rate not available: %s\n", snd_strerror(err));
- return;
+ return -1;
}
if((err=snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, 0))<0)
{
printf("Buffer time error: %s\n", snd_strerror(err));
- return;
+ return -1;
}
if((err=snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, 0))<0)
{
printf("Period time error: %s\n", snd_strerror(err));
- return;
+ return -1;
}
if((err=snd_pcm_hw_params(handle, hwparams))<0)
{
printf("Unable to install hw params: %s\n", snd_strerror(err));
- return;
+ return -1;
}
snd_pcm_status_alloca(&status);
if((err=snd_pcm_status(handle, status))<0)
{
printf("Unable to get status: %s\n", snd_strerror(err));
- return;
+ return -1;
}
buffer_size = snd_pcm_status_get_avail(status);
+ return 0;
}
// REMOVE SOUND
-void RemoveSound(void)
+static void alsa_finish(void)
{
if(handle != NULL)
{
@@ -130,9 +127,9 @@ void RemoveSound(void)
}
// GET BYTES BUFFERED
-unsigned long SoundGetBytesBuffered(void)
+static int alsa_busy(void)
{
- unsigned long l;
+ int l;
if (handle == NULL) // failed to open?
return 1;
@@ -146,7 +143,7 @@ unsigned long SoundGetBytesBuffered(void)
}
// FEED SOUND DATA
-void SoundFeedStreamData(unsigned char* pSound,long lBytes)
+static void alsa_feed(void *pSound, int lBytes)
{
if (handle == NULL) return;
@@ -154,3 +151,12 @@ void SoundFeedStreamData(unsigned char* pSound,long lBytes)
snd_pcm_prepare(handle);
snd_pcm_writei(handle,pSound, lBytes / 4);
}
+
+void out_register_alsa(struct out_driver *drv)
+{
+ drv->name = "alsa";
+ drv->init = alsa_init;
+ drv->finish = alsa_finish;
+ drv->busy = alsa_busy;
+ drv->feed = alsa_feed;
+}