From 74ef742cf45ef015bf9f4dd7a7ffbabfd0c25f22 Mon Sep 17 00:00:00 2001 From: deadwood Date: Sat, 10 Oct 2015 19:34:48 +0000 Subject: [PATCH] alsa.audio: fill the complete free buffer before executing another audio loop git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@51140 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- workbench/devs/AHI/Drivers/Alsa/alsa-playslave.c | 32 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/workbench/devs/AHI/Drivers/Alsa/alsa-playslave.c b/workbench/devs/AHI/Drivers/Alsa/alsa-playslave.c index 82dd348db4..27c13c38fb 100644 --- a/workbench/devs/AHI/Drivers/Alsa/alsa-playslave.c +++ b/workbench/devs/AHI/Drivers/Alsa/alsa-playslave.c @@ -14,6 +14,8 @@ #define dd ((struct AlsaData*) AudioCtrl->ahiac_DriverData) +#define min(a,b) ( (a) < (b) ? (a) : (b) ) + /****************************************************************************** ** The slave process ********************************************************** ******************************************************************************/ @@ -42,6 +44,8 @@ Slave( struct ExecBase* SysBase ) struct AlsaBase* AlsaBase; BOOL running; ULONG signals; + LONG framesready = 0; + APTR framesptr = NULL; AudioCtrl = (struct AHIAudioCtrlDrv*) FindTask(NULL)->tc_UserData; AHIsubBase = (struct DriverBase*) dd->ahisubbase; @@ -68,21 +72,37 @@ Slave( struct ExecBase* SysBase ) } else { + LONG framesfree = 0; + while(TRUE) { - LONG avail = ALSA_Avail(dd->alsahandle); - if (avail > 1024) + framesfree = ALSA_Avail(dd->alsahandle); + if (framesfree > 1024) break; Delay(1); } + /* Loop until alsa buffer is filled */ + while (framesfree > 0) + { + LONG written; - CallHookPkt( AudioCtrl->ahiac_PlayerFunc, AudioCtrl, NULL ); - CallHookPkt( AudioCtrl->ahiac_MixerFunc, AudioCtrl, dd->mixbuffer ); + if (framesready == 0) + { + CallHookPkt(AudioCtrl->ahiac_PlayerFunc, AudioCtrl, NULL ); + CallHookPkt(AudioCtrl->ahiac_MixerFunc, AudioCtrl, dd->mixbuffer ); + framesready = AudioCtrl->ahiac_BuffSamples; + framesptr = dd->mixbuffer; + } - ALSA_Write(dd->alsahandle, dd->mixbuffer, AudioCtrl->ahiac_BuffSamples); + written = ALSA_Write(dd->alsahandle, framesptr, min(framesready, framesfree)); - CallHookA(AudioCtrl->ahiac_PostTimerFunc, (Object*) AudioCtrl, 0); + framesready -= written; + framesfree -= written; + framesptr += written * 4; + + CallHookA(AudioCtrl->ahiac_PostTimerFunc, (Object*) AudioCtrl, 0); + } } } } -- 2.11.4.GIT