| | 42 | <P> |
| | 43 | Add a function to retrieve a stream's time base expressed in seconds. |
| | 44 | It is unspecified what this timebase is relative to. |
| | 45 | </P> |
| | 46 | |
| | 47 | <PRE> |
| | 48 | typedef double PaTime; |
| | 49 | |
| | 50 | PaTime Pa_GetStreamTimeBase( PaStream *stream ); |
| | 51 | </PRE> |
| | 52 | |
| | 53 | <P> |
| | 54 | Remove the current outTime parameter from the audio callback, and |
| | 55 | replace it with a pointer to a PaCallbackTimeInfo structure which contains |
| | 56 | the time at which the first sample of the input buffer was received at the ADC input (inputBufferADCTime), |
| | 57 | the time at which the first sample of the output buffer will exit the DAC (outputBufferDACTime), |
| | 58 | and the time at which the callback was initiated (currentTime). These times are all expressed |
| | 59 | in seconds relative to the stream's time base returned by Pa_GetStreamTimeBase(). |
| | 60 | </P> |
| | 61 | |
| | 62 | <PRE> |
| | 63 | typedef struct PaCallbackTimeInfo{ |
| | 64 | PaTime inputBufferADCTime; |
| | 65 | PaTime currentTime; |
| | 66 | PaTime outputBufferDACTime, |
| | 67 | } PaCallbackTimeInfo; |
| | 68 | |
| | 69 | typedef int PortAudioCallback( |
| | 70 | void *inputBuffer, void *outputBuffer, |
| | 71 | unsigned long framesPerBuffer, PaCallbackTimeInfo *timeInfo, |
| | 72 | unsigned long flags, void *userData); |
| | 73 | </PRE> |
| | 74 | |
| | 75 | <H4>Discussion</H4> |
| | 76 | |
| | 77 | <P> |
| | 78 | The possibility of retaining Pa_StreamTime() for clients which simply need to display the current stream time was discussed. It was suggested that the functionality currently provided by Pa_StreamTime() could be implemented using the new timestamp parameters, and that doing so would be more robust. One reason is because it is difficult to define a single useful behavior of Pa_StreamTime() in the presence of buffer overruns and underruns. |
| | 79 | </P> |
| | 80 | |
| | 81 | <P> |
| | 82 | Originally it was planned to have a global PortAudio timebase returned by a function named Pa_GetTime(). However, different host APIs on the same platform may dictate that their timebases are relative to different time sources (timeGetTime() vs. QueryPerformanceCounter() on windows for example.) Trying to syncronise multiple independent time bases is a problematic task (due to potential clock drift), so it was concluded that a safer approach would be to provide separate time bases for each stream. |
| | 83 | </P> |