Audacity  3.0.3
Public Member Functions | List of all members
AudioThread Class Reference

Defined different on Mac and other platforms (on Mac it does not use wxWidgets wxThread), this class sits in a thread loop reading and writing audio. More...

Inheritance diagram for AudioThread:
[legend]
Collaboration diagram for AudioThread:
[legend]

Public Member Functions

 AudioThread ()
 
ExitCode Entry () override
 

Detailed Description

Defined different on Mac and other platforms (on Mac it does not use wxWidgets wxThread), this class sits in a thread loop reading and writing audio.

Definition at line 223 of file AudioIO.cpp.

Constructor & Destructor Documentation

◆ AudioThread()

AudioThread::AudioThread ( )
inline

Definition at line 225 of file AudioIO.cpp.

225 :wxThread(wxTHREAD_JOINABLE) {}

Member Function Documentation

◆ Entry()

AudioThread::ExitCode AudioThread::Entry ( )
override

Definition at line 1717 of file AudioIO.cpp.

1718 {
1719  AudioIO *gAudioIO;
1720  while( !TestDestroy() &&
1721  nullptr != ( gAudioIO = AudioIO::Get() ) )
1722  {
1723  using Clock = std::chrono::steady_clock;
1724  auto loopPassStart = Clock::now();
1725  auto &schedule = gAudioIO->mPlaybackSchedule;
1726  const auto interval = schedule.GetPolicy().SleepInterval(schedule);
1727 
1728  // Set LoopActive outside the tests to avoid race condition
1731  {
1732  gAudioIO->TrackBufferExchange();
1734  }
1735  else if( gAudioIO->mAudioThreadTrackBufferExchangeLoopRunning )
1736  {
1737  gAudioIO->TrackBufferExchange();
1738  }
1740 
1741  std::this_thread::sleep_until( loopPassStart + interval );
1742  }
1743 
1744  return 0;
1745 }

References AudioIO::Get(), PlaybackSchedule::GetPolicy(), AudioIoCallback::mAudioThreadShouldCallTrackBufferExchangeOnce, AudioIoCallback::mAudioThreadTrackBufferExchangeLoopActive, AudioIoCallback::mAudioThreadTrackBufferExchangeLoopRunning, AudioIoCallback::mPlaybackSchedule, PlaybackPolicy::SleepInterval(), and AudioIO::TrackBufferExchange().

Here is the call graph for this function:

The documentation for this class was generated from the following file:
AudioIO::TrackBufferExchange
void TrackBufferExchange()
Definition: AudioIO.cpp:1780
PlaybackSchedule::GetPolicy
PlaybackPolicy & GetPolicy()
Definition: PlaybackSchedule.cpp:136
AudioIoCallback::mAudioThreadShouldCallTrackBufferExchangeOnce
volatile bool mAudioThreadShouldCallTrackBufferExchangeOnce
Definition: AudioIO.h:284
AudioIoCallback::mAudioThreadTrackBufferExchangeLoopRunning
volatile bool mAudioThreadTrackBufferExchangeLoopRunning
Definition: AudioIO.h:285
PlaybackPolicy::SleepInterval
virtual std::chrono::milliseconds SleepInterval(PlaybackSchedule &schedule)
How long to wait between calls to AudioIO::TrackBufferExchange.
Definition: PlaybackSchedule.cpp:67
AudioIoCallback::mAudioThreadTrackBufferExchangeLoopActive
volatile bool mAudioThreadTrackBufferExchangeLoopActive
Definition: AudioIO.h:286
AudioIoCallback::mPlaybackSchedule
PlaybackSchedule mPlaybackSchedule
Definition: AudioIO.h:341
AudioIO
AudioIO uses the PortAudio library to play and record sound.
Definition: AudioIO.h:356
AudioIO::Get
static AudioIO * Get()
Definition: AudioIO.cpp:141
Clock
std::chrono::system_clock Clock
Definition: UpdateManager.cpp:37