Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::audio::AudioDevice Class Referenceabstract

#include <device.hpp>

Public Types

using WorkgroupChangeCallback = std::function<void(void* workgroup)>

Public Member Functions

virtual ~AudioDevice ()=default
virtual bool open (const DeviceConfig &config)=0
virtual void close ()=0
virtual bool start (AudioCallback callback)=0
virtual void stop ()=0
virtual bool is_open () const =0
virtual bool is_running () const =0
virtual DeviceInfo info () const =0
virtual double sample_rate () const =0
virtual int buffer_size () const =0
virtual void * callback_workgroup () const
 Opaque handle to the OS-supplied real-time workgroup associated with this device's I/O thread, or nullptr if the platform does not expose one.
virtual std::uint64_t xrun_count () const
 Cumulative xrun (overload/underrun) count since start() or the last reset_xrun_counter().
virtual void reset_xrun_counter ()
 Reset the xrun counter to 0. Safe from any thread.
virtual void set_workgroup_change_callback (WorkgroupChangeCallback callback)
 Atomically subscribe to callback_workgroup() changes and synchronously deliver the current value before returning.
virtual void quiesce_workgroup_changes ()
 Disable future workgroup-change notifications and serialize with any notification already in flight.

Member Typedef Documentation

◆ WorkgroupChangeCallback

using pulp::audio::AudioDevice::WorkgroupChangeCallback = std::function<void(void* workgroup)>

Constructor & Destructor Documentation

◆ ~AudioDevice()

virtual pulp::audio::AudioDevice::~AudioDevice ( )
virtualdefault

Member Function Documentation

◆ buffer_size()

virtual int pulp::audio::AudioDevice::buffer_size ( ) const
pure virtual

◆ callback_workgroup()

virtual void * pulp::audio::AudioDevice::callback_workgroup ( ) const
inlinevirtual

Opaque handle to the OS-supplied real-time workgroup associated with this device's I/O thread, or nullptr if the platform does not expose one.

On macOS 13+ / iOS 16+ this returns the os_workgroup_t queried via kAudioDevicePropertyIOThreadOSWorkgroup; on older Apple targets and on non-Apple platforms this returns nullptr and callers fall back to AudioWorkgroup::set_realtime_priority().

The returned pointer is owned by the device (CoreAudio owns a retained property-query reference). It remains valid until close or, for a live-retargeting backend, until the removal notification and auxiliary worker acknowledgment registered below have completed. Callers must not retain or free it. Pass it to AudioWorkgroup::set_workgroup(static_cast<os_workgroup_t>(...)) before joining from the audio thread.

Default returns nullptr so non-Apple backends inherit the best-effort priority fallback for free.

◆ close()

virtual void pulp::audio::AudioDevice::close ( )
pure virtual

◆ info()

virtual DeviceInfo pulp::audio::AudioDevice::info ( ) const
pure virtual

◆ is_open()

virtual bool pulp::audio::AudioDevice::is_open ( ) const
pure virtual

◆ is_running()

virtual bool pulp::audio::AudioDevice::is_running ( ) const
pure virtual

◆ open()

virtual bool pulp::audio::AudioDevice::open ( const DeviceConfig & config)
pure virtual

◆ quiesce_workgroup_changes()

virtual void pulp::audio::AudioDevice::quiesce_workgroup_changes ( )
inlinevirtual

Disable future workgroup-change notifications and serialize with any notification already in flight.

Live-retargeting backends must publish null and wait for its callback to return before this method returns. Called only off the render thread before close() invalidates the handle.

◆ reset_xrun_counter()

virtual void pulp::audio::AudioDevice::reset_xrun_counter ( )
inlinevirtual

Reset the xrun counter to 0. Safe from any thread.

◆ sample_rate()

virtual double pulp::audio::AudioDevice::sample_rate ( ) const
pure virtual

◆ set_workgroup_change_callback()

virtual void pulp::audio::AudioDevice::set_workgroup_change_callback ( WorkgroupChangeCallback callback)
inlinevirtual

Atomically subscribe to callback_workgroup() changes and synchronously deliver the current value before returning.

Live-retargeting backends must serialize callback installation + initial delivery with changes, so callers cannot publish a stale snapshot after a concurrent switch. The callback may execute inside that serialization boundary and must not re-enter the device.

Apple devices which follow the system default output call this off the render thread after stopping the old callback and before invalidating its borrowed handle, then again with the replacement handle before rendering resumes. Other backends deliver their stable snapshot through the default implementation and never send a later change.

◆ start()

virtual bool pulp::audio::AudioDevice::start ( AudioCallback callback)
pure virtual

◆ stop()

virtual void pulp::audio::AudioDevice::stop ( )
pure virtual

◆ xrun_count()

virtual std::uint64_t pulp::audio::AudioDevice::xrun_count ( ) const
inlinevirtual

Cumulative xrun (overload/underrun) count since start() or the last reset_xrun_counter().

CoreAudio devices increment on every kAudioDeviceProcessorOverload notification; backends that do not surface overload events stay at 0.


The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/audio/include/pulp/audio/device.hpp