static int sgi_bufferspace(void)
{
    int i;
    /* ALgetfillable returns space in samples. */
    i = ALgetfillable(sgi_audioport);
    return i;
}
Exemple #2
0
/*---------------------------------------------------------------------------------------------------*/
static PaError Pa_SgiAudioProcess(internalPortAudioStream *past) /* Spawned by PaHost_StartEngine(). */
{
    PaError                 result = paNoError;
    PaHostSoundControl      *pahsc;
    
    if (!past)
        return paBadStreamPtr;
    pahsc = (PaHostSoundControl*)past->past_DeviceData;
	if (!pahsc)
        return paInternalError;
	past->past_IsActive = 1;            /* Wasn't this already done by the calling parent?!   */
    DBUG(("entering thread.\n"));

    while (!past->past_StopSoon)        /* OR-ing StopSoon and StopNow here gives problems! */
        {
        /*---------------------------------------- INPUT: ------------------------------------*/
        if (pahsc->pahsc_NativeInputBuffer)     /* Then pahsc_ALportIN should also be there!  */
            {
            while (ALgetfilled(pahsc->pahsc_ALportIN) < pahsc->pahsc_SamplesPerInputBuffer)
                {
                /* Trying sginap(1); and usleep(); here... things get blocked under IRIX6.2. */
                if (past->past_StopNow)    /* Don't let ALreadsamps() block */
                    goto done;
                }
            if (ALreadsamps(pahsc->pahsc_ALportIN, (void*)pahsc->pahsc_NativeInputBuffer,
                            pahsc->pahsc_SamplesPerInputBuffer))    /* Number of samples instead  */
                {                                                   /* of number of frames.       */
                ERR_RPT(("ALreadsamps() failed.\n"));
                result =  paInternalError;
                goto done;
                }
            }
        /*---------------------------------------------------- USER CALLBACK ROUTINE: ----------*/
        /* DBUG(("Calling Pa_CallConvertInt16()...\n")); */
        Pa_StartUsageCalculation(past);                     /* Convert 16 bit native data to    */
	    result = Pa_CallConvertInt16(past,                  /* user data and call user routine. */
				                 pahsc->pahsc_NativeInputBuffer, pahsc->pahsc_NativeOutputBuffer);
	    Pa_EndUsageCalculation(past);
	    if (result) 
		    {
			DBUG(("Pa_CallConvertInt16() returned %d, stopping...\n", result));
            goto done;                      /* This is apparently NOT an error!       */
		    }                               /* Just letting the userCallBack stop us. */
        /*---------------------------------------- OUTPUT: ------------------------------------*/
        if (pahsc->pahsc_NativeOutputBuffer)    /* Then pahsc_ALportOUT should also be there!  */
            {
            while (ALgetfillable(pahsc->pahsc_ALportOUT) < pahsc->pahsc_SamplesPerOutputBuffer)
                {
                /* Trying sginap(1); and usleep(); here... things get blocked under IRIX6.2. */
                if (past->past_StopNow)    /* Don't let ALwritesamps() block */
                    goto done;
                }
            if (ALwritesamps(pahsc->pahsc_ALportOUT, (void*)pahsc->pahsc_NativeOutputBuffer,
                             pahsc->pahsc_SamplesPerOutputBuffer))
                {
                ERR_RPT(("ALwritesamps() failed.\n"));
                result = paInternalError;
                goto done;
                }
            }
        /*-------------------------------------------------------------------------------------*/
        }
done:
    /* pahsc->pahsc_ThreadPID = -1;   Hu? doesn't help!! (added by Pieter) */
    past->past_IsActive = 0;
    DBUG(("leaving thread.\n"));
    return result;
}