Without this, if HAVE_GETTIMEOFDAY is defined getStreamTime() can return
a wrong value in the following case:
- start stream
- stop stream
- start stream
- call getStreamTime() immediately
In this case tickStreamTime() will not have been called since the
stream was restarted, hence lastTickTimestamp will refer to the
previous run of the stream. getStreamTime() will therefore extrapolate
wrongly from stream._streamTime. This patch only uses lastTickTimestamp
when it is valid.
struct timeval then;
struct timeval now;
struct timeval then;
struct timeval now;
- if ( stream_.state != STREAM_RUNNING || stream_.streamTime == 0.0 )
+ if ( stream_.state != STREAM_RUNNING || (stream_.lastTickTimestamp.tv_sec == 0 && stream_.lastTickTimestamp.tv_usec == 0) )
return stream_.streamTime;
gettimeofday( &now, NULL );
return stream_.streamTime;
gettimeofday( &now, NULL );
return stream_.sampleRate;
}
return stream_.sampleRate;
}
+void RtApi :: startStream( void )
+{
+#if defined( HAVE_GETTIMEOFDAY )
+ stream_.lastTickTimestamp.tv_sec = 0;
+ stream_.lastTickTimestamp.tv_usec = 0;
+#endif
+}
+
// *************************************************** //
//
// *************************************************** //
//
void RtApiCore :: startStream( void )
{
verifyStream();
void RtApiCore :: startStream( void )
{
verifyStream();
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiCore::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiCore::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
void RtApiJack :: startStream( void )
{
verifyStream();
void RtApiJack :: startStream( void )
{
verifyStream();
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiJack::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiJack::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
void RtApiAsio :: startStream()
{
verifyStream();
void RtApiAsio :: startStream()
{
verifyStream();
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiAsio::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiAsio::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
void RtApiWasapi::startStream( void )
{
verifyStream();
void RtApiWasapi::startStream( void )
{
verifyStream();
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiWasapi::startStream: The stream is already running.";
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiWasapi::startStream: The stream is already running.";
void RtApiDs :: startStream()
{
verifyStream();
void RtApiDs :: startStream()
{
verifyStream();
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiDs::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiDs::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
void RtApiDs :: stopStream()
{
verifyStream();
void RtApiDs :: stopStream()
{
verifyStream();
if ( stream_.state == STREAM_STOPPED ) {
errorText_ = "RtApiDs::stopStream(): the stream is already stopped!";
error( RtAudioError::WARNING );
if ( stream_.state == STREAM_STOPPED ) {
errorText_ = "RtApiDs::stopStream(): the stream is already stopped!";
error( RtAudioError::WARNING );
// This method calls snd_pcm_prepare if the device isn't already in that state.
verifyStream();
// This method calls snd_pcm_prepare if the device isn't already in that state.
verifyStream();
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiAlsa::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiAlsa::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
void RtApiPulse::startStream( void )
{
void RtApiPulse::startStream( void )
{
PulseAudioHandle *pah = static_cast<PulseAudioHandle *>( stream_.apiHandle );
if ( stream_.state == STREAM_CLOSED ) {
PulseAudioHandle *pah = static_cast<PulseAudioHandle *>( stream_.apiHandle );
if ( stream_.state == STREAM_CLOSED ) {
void RtApiOss :: startStream()
{
verifyStream();
void RtApiOss :: startStream()
{
verifyStream();
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiOss::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
if ( stream_.state == STREAM_RUNNING ) {
errorText_ = "RtApiOss::startStream(): the stream is already running!";
error( RtAudioError::WARNING );
double streamTime; // Number of elapsed seconds since the stream started.
#if defined(HAVE_GETTIMEOFDAY)
double streamTime; // Number of elapsed seconds since the stream started.
#if defined(HAVE_GETTIMEOFDAY)
+ // The gettimeofday() when tickStreamTime was last called, or both
+ // fields at 0 if tickStreamTime has not been called since the last
+ // startStream().
struct timeval lastTickTimestamp;
#endif
struct timeval lastTickTimestamp;
#endif