Audaspace: Fix Core Audio sound playback

This commit is contained in:
Sebastian Parborg
2025-05-06 14:57:04 +02:00
committed by Sebastian Parborg
parent 898877e8b3
commit df733ea3a7
2 changed files with 21 additions and 4 deletions

View File

@@ -65,20 +65,35 @@ OSStatus CoreAudioDevice::CoreAudio_mix(void* data, AudioUnitRenderActionFlags*
return noErr;
}
void CoreAudioDevice::preMixingWork(bool playing)
{
if(!playing)
{
if((getRingBuffer().getReadSize() == 0) && m_active)
{
AudioOutputUnitStop(m_audio_unit);
m_active = false;
}
}
}
void CoreAudioDevice::playing(bool playing)
{
MixingThreadDevice::playing(playing);
if(m_playback != playing)
{
if(playing)
{
AudioOutputUnitStart(m_audio_unit);
else
AudioOutputUnitStop(m_audio_unit);
m_active = true;
}
}
m_playback = playing;
}
CoreAudioDevice::CoreAudioDevice(DeviceSpecs specs, int buffersize) : m_buffersize(uint32_t(buffersize)), m_playback(false), m_audio_unit(nullptr), m_audio_clock_ready(false)
CoreAudioDevice::CoreAudioDevice(DeviceSpecs specs, int buffersize) : m_buffersize(uint32_t(buffersize)), m_playback(false), m_audio_unit(nullptr)
{
if(specs.channels == CHANNELS_INVALID)
specs.channels = CHANNELS_STEREO;

View File

@@ -53,10 +53,11 @@ private:
* The CoreAudio AudioUnit.
*/
AudioUnit m_audio_unit;
bool m_active{false};
/// The CoreAudio clock referene.
CAClockRef m_clock_ref;
bool m_audio_clock_ready;
bool m_audio_clock_ready{false};
double m_synchronizerStartTime{0};
/**
@@ -74,6 +75,7 @@ private:
CoreAudioDevice(const CoreAudioDevice&) = delete;
CoreAudioDevice& operator=(const CoreAudioDevice&) = delete;
AUD_LOCAL void preMixingWork(bool playing) override;
void playing(bool playing) override;
public: