alsa.audio: move handling of XRUN when writting to the slave task
[AROS.git] / workbench / devs / AHI / Drivers / Alsa / alsa-bridge / alsa.c
blob39e739fe26125ed8ecc16a95c576519fd993fff6
1 /*
2 Copyright © 2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "alsa.h"
7 #include "alsa_hostlib.h"
9 BOOL ALSA_Init()
11 return ALSA_HostLib_Init();
14 VOID ALSA_Cleanup()
16 ALSA_HostLib_Cleanup();
19 APTR ALSA_Open()
21 snd_pcm_t * handle = NULL;
24 if (ALSACALL(snd_pcm_open, &handle, "default",
25 SND_PCM_STREAM_PLAYBACK, 0) < 0)
26 return NULL;
28 return handle;
31 VOID ALSA_Close(APTR handle)
33 if (handle)
35 ALSACALL(snd_pcm_close, handle);
39 BOOL ALSA_SetHWParams(APTR handle, ULONG * rate)
41 snd_pcm_hw_params_t *hw_params;
42 LONG dir = 0; int r = 0;
44 ALSACALL(snd_pcm_hw_params_malloc, &hw_params);
45 ALSACALL(snd_pcm_hw_params_any, handle, hw_params);
46 ALSACALL(snd_pcm_hw_params_set_access, handle, hw_params,
47 SND_PCM_ACCESS_RW_INTERLEAVED);
48 ALSACALL(snd_pcm_hw_params_set_format, handle, hw_params,
49 SND_PCM_FORMAT_S16_LE);
50 ALSACALL(snd_pcm_hw_params_set_channels, handle, hw_params, 2);
51 r = ALSACALL(snd_pcm_hw_params_set_rate_near, handle, hw_params, rate, &dir);
52 ALSACALL(snd_pcm_hw_params_set_buffer_size, handle, hw_params, 4096);
54 ALSACALL(snd_pcm_hw_params, handle, hw_params);
55 ALSACALL(snd_pcm_hw_params_free, hw_params);
57 return (r >= 0);
60 LONG ALSA_Write(APTR handle, APTR buffer, ULONG size)
62 LONG rc = ALSACALL(snd_pcm_writei, handle, buffer, (snd_pcm_uframes_t)size);
64 if (rc == -EPIPE)
65 rc = ALSA_XRUN;
67 return rc;
70 VOID ALSA_Prepare(APTR handle)
72 ALSACALL(snd_pcm_prepare, handle);
75 LONG ALSA_Avail(APTR handle)
77 LONG rc = ALSACALL(snd_pcm_avail_update, handle);
78 if (rc == -EPIPE)
79 rc = ALSA_XRUN;
81 return rc;