|
arduino-audio-tools
|
Role-independent front end shared by USB Audio devices (USBAudioDeviceBase, aliased as USBAudioStream) and USB Audio hosts (USBAudioHostBase, aliased as USBAudioHostStream). More...
#include <USBAudioStreamBase.h>
Public Member Functions | |
| virtual void | addNotifyAudioChange (AudioInfoSupport &bi) |
| Adds target to be notified about audio changes. | |
| virtual AudioInfo | audioInfo () override |
| provides the actual input AudioInfo | |
| virtual AudioInfo | audioInfoOut () |
| int | available () override |
| Bytes of received audio waiting in the RX buffer. | |
| int | availableForWrite () override |
| Bytes of free space in the TX buffer. | |
| virtual bool | begin () |
| virtual BaseBuffer< uint8_t > & | bufferRx ()=0 |
| Returns the RX audio buffer. Must be overridden by subclasses. | |
| virtual BaseBuffer< uint8_t > & | bufferTx ()=0 |
| Returns the TX audio buffer. Must be overridden by subclasses. | |
| virtual void | clearNotifyAudioChange () |
| Deletes all change notify subscriptions. | |
| const USBAudioConfig & | config () const |
| Provides the active configuration. | |
| virtual void | end () |
| virtual void | flush () override |
| virtual int | getActualCore () const |
| Returns the actual core on which the call is running (for RP2040) | |
| bool | isEpInEnabled () const |
| Returns true if the IN endpoint is enabled. | |
| bool | isEpOutEnabled () const |
| Returns true if the OUT endpoint is enabled. | |
| bool | isMute (uint8_t channel=0) const |
| Returns the current mute state for the given channel. | |
| bool | isNotifyActive () |
| Checks if the automatic AudioInfo update is active. | |
| bool | isStreamingActive () const |
| Returns true if either the TX or RX stream is open. | |
| virtual bool | isStreamingActiveRx () const =0 |
| Returns true if the stream used by readBytes() is open. | |
| virtual bool | isStreamingActiveTx () const =0 |
| Returns true if the stream used by write() is open. | |
| virtual bool | mounted ()=0 |
| Returns true if the USB connection is established (device: enumerated by the host; host: an audio device is attached). | |
| operator bool () override | |
| size_t | readBytes (uint8_t *buffer, size_t bufsize) |
| Receive audio data from the USB peer. Until bufferRx() has filled past config.rx_start_fill_percent at least once after begin(), no data is returned. This is a one-shot startup prime only – once reached, readBytes() keeps draining normally for the rest of the session and is not gated again by later underruns. | |
| virtual size_t | readSilence (uint8_t *buffer, size_t length) |
| Source to generate silence: just sets the buffer to 0. | |
| virtual bool | removeNotifyAudioChange (AudioInfoSupport &bi) |
| Removes a target in order not to be notified about audio changes. | |
| virtual void | serviceUSB ()=0 |
| Process pending USB events on platforms where the application drives the stack. No-op where a dedicated task runs the stack. | |
| virtual void | setAudioInfo (AudioInfo newInfo) override |
| Defines the input AudioInfo. | |
| bool | setMute (bool m, uint8_t channel=0) |
| Set the mute state for a channel and notify the USB peer. | |
| void | setMuteCallback (std::function< void(bool, uint8_t)> cb) |
| Register a callback invoked when the mute state changes. | |
| void | setNotifyActive (bool flag) |
| Deactivate/Reactivate automatic AudioInfo updates: (default is active) | |
| void | setSampleRateCallback (std::function< void(uint32_t)> cb) |
| Register a callback invoked when the sample rate changes. | |
| void | setStreamingStateCallback (std::function< void(bool, bool)> cb) |
| Register a callback invoked when the streaming state changes (a streaming interface was opened or closed). | |
| bool | setVolume (float vol, uint8_t channel) |
| Set the volume for a channel and notify the USB peer. | |
| bool | setVolume (float volume) override |
| sets the volume for the master channel (channel 0) | |
| void | setVolumeCallback (std::function< void(float, uint8_t)> cb) |
| Register a callback invoked when the volume changes. | |
| void | setWriteBufferSize (int size) |
| float | volume () override |
| gets the volume for the master channel (channel 0) | |
| float | volume (uint8_t channel) |
| Returns the current volume for the given channel. | |
| size_t | write (const uint8_t *data, size_t len) |
| Send audio data to the USB peer. Silently discards data while the TX stream is not open so StreamCopy doesn't report write errors before streaming starts. | |
| virtual size_t | write (uint8_t ch) override |
| virtual void | writeSilence (size_t len) |
| Writes len bytes of silence (=0). | |
Protected Member Functions | |
| virtual bool | beginUSB ()=0 |
| Override in platform subclasses to start the USB stack. | |
| bool | configChanged (const USBAudioConfig &n) |
| float | getVolumeExt (uint8_t channel) const |
| Returns the effective volume for a per-channel index (1-based). Combines master volume (index 0) with per-channel volume and mute. | |
| virtual int | not_supported (int out, const char *msg="") |
| void | notifyAudioChange (AudioInfo info) |
| void | notifyStreamingState () |
| virtual void | onMuteChanged (uint8_t) |
| virtual void | onVolumeChanged (uint8_t) |
| template<typename T > | |
| void | processVolume (T *data, size_t sample_count) |
| void | processVolume (uint8_t *data, size_t len) |
| Process audio data for volume control. | |
| void | refillReadBuffer () |
| Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read() | |
| virtual void | resizeBuffers ()=0 |
| Resize the platform audio buffers. | |
| void | setConfig (const USBAudioConfig &cfg) |
| Set the USB audio configuration (use begin(cfg) instead). | |
| void | setupVolumeState () |
| (Re)sizes the volume and mute state: master (index 0) + one per channel | |
Static Protected Member Functions | |
| static int16_t | floatToUac2 (float vol) |
| Convert linear volume (0.0–1.0) to UAC2 int16 (1/256 dB). Linear mapping: 0.0 → -100 dB (min), 1.0 → 0 dB (max). | |
| static bool | isValidBitsPerSample (uint8_t bps) |
| static float | uac2ToFloat (int16_t v) |
| Convert UAC2 int16 (1/256 dB) to linear volume (0.0–1.0). Linear mapping within the -100..0 dB range reported by GET_RANGE. | |
Protected Attributes | |
| int | _timeout = 10 |
| USBAudioConfig | config_ |
| int | core = -1 |
| AudioInfo | info |
| bool | is_active_ = false |
| bool | is_notify_active = true |
| bool | is_started_ = false |
| std::vector< bool > | mute_ |
| std::function< void(bool, uint8_t)> | mute_cb_ |
| Vector< AudioInfoSupport * > | notify_vector |
| bool | rx_primed_ = false |
| std::function< void(uint32_t)> | sample_rate_cb_ |
| std::function< void(bool, bool)> | streaming_state_cb_ |
| RingBuffer< uint8_t > | tmp_in {0} |
| RingBuffer< uint8_t > | tmp_out {0} |
| bool | usb_task_active_ = false |
| std::vector< float > | volume_ |
| std::function< void(float, uint8_t)> | volume_cb_ |
| float | volume_value = 1.0f |
| int | write_buffer_size = MAX_SINGLE_CHARS |
Static Protected Attributes | |
| static constexpr int16_t | kVolumeMinDb256 = -25600 |
| Convert AudioTools volume (0.0–1.0) to UAC2 int16 (1/256 dB). 0.0 maps to 0x8000 (silence), 1.0 maps to 0 (0 dB). | |
Role-independent front end shared by USB Audio devices (USBAudioDeviceBase, aliased as USBAudioStream) and USB Audio hosts (USBAudioHostBase, aliased as USBAudioHostStream).
It provides the identical public Arduino stream API for both roles: write() sends audio to the USB peer, readBytes() receives audio from it, plus volume/mute state, callbacks and the one-shot RX startup prime. The USB stack specific parts are provided by the subclasses via the pure virtual methods.
|
inlinevirtualinherited |
Adds target to be notified about audio changes.
Reimplemented in CodecNOP, EncodedAudioOutput, EncodedAudioStream, AACDecoderFDK, DecoderBasic, CodecChain, MP3DecoderHelix, MP3DecoderMAD, OggContainerDecoder, RTSPClient< TcpClient, UdpSocket >, Pipeline, and Pipeline::ModifyingStreamAdapter.
|
inlineoverridevirtualinherited |
provides the actual input AudioInfo
Implements AudioInfoSupport.
Reimplemented in JupyterAudioT< T >, MozziStream, TimerCallbackAudioStream, EncodedAudioStream, PureDataStream, AdapterAudioOutputToAudioStream, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, and InputMerge< T >.
|
inlinevirtualinherited |
provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
Reimplemented in MP3EncoderShine, PureDataStream, PWMAudioOutput< PWMDriverT >, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, Pipeline, ResampleStream, ResampleStreamT< TInterpolator >, and SupportedRatesStream.
|
inlineoverridevirtual |
Bytes of received audio waiting in the RX buffer.
Reimplemented from BaseStream.
|
inlineoverridevirtual |
Bytes of free space in the TX buffer.
Reimplemented from BaseStream.
|
inlinevirtualinherited |
Reimplemented in AudioOutputWithCallback, AudioMP34DT05, I2SCodecStream, MozziStream, PureDataStream, SPDIFOutput, VS1053Stream, WM8960Stream, AdaptiveResamplingStream, AudioLoRa, ESPNowStream, USBAudioDeviceBase, USBAudioHostBase, VBANStream, FrequencyDetectorAutoCorrelation, GoertzelStream, AudioEffectStreamT< T >, AudioEffectStream, Equalizer3BandsT< T >, Equalizer3BandsPerChannelT< T >, I2SStream, AudioTimeSourceStream, AudioStreamWrapper, TimerCallbackAudioStream, ResampleStreamT< TInterpolator >, FileLoopT< FileType >, FileLoopT< File >, EncodedAudioStream, AudioBoardStream, AudioKitStream, MiniAudioStream, PortAudioStream, StdioStream, HLSStreamT< URLStream >, NRF24Stream, AutomaticGainControlStream, MeasuringStream, QualityAnalysisStream, VolumeStream, AnalogAudioStream, AdapterAudioOutputToAudioStream, TimedStream, MemoryStream, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, ProgressStream, Throttle, InputMerge< T >, CallbackStream, FilteredStream< T, TF >, FilteredStream< int16_t, int16_t >, VolumeMeter, AudioInputMonitor, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, CatStream, QueueStream< T >, QueueStream< uint8_t >, DynamicMemoryStream, Pipeline, Pipeline::ModifyingStreamAdapter, ResampleStream, SupportedRatesStream, AudioFFTBase, and EqualizerNBands< SampleT, AccT, NUM_TAPS, NUM_BANDS >.
|
protectedpure virtual |
Override in platform subclasses to start the USB stack.
Implemented in USBAudioDeviceESP32, USBAudioDeviceRenesas, USBAudioDeviceTinyUSB, USBAudioDeviceTinyUSBFreeRTOS, USBAudioHostBase, USBAudioHostESP32, and USBAudioHostTinyUSBFreeRTOS.
|
pure virtual |
Returns the RX audio buffer. Must be overridden by subclasses.
Implemented in USBAudioDeviceESP32, USBAudioDeviceRenesas, USBAudioDeviceTinyUSB, USBAudioDeviceTinyUSBFreeRTOS, USBAudioHostESP32, USBAudioHostTinyUSB, and USBAudioHostTinyUSBFreeRTOS.
|
pure virtual |
Returns the TX audio buffer. Must be overridden by subclasses.
Implemented in USBAudioDeviceESP32, USBAudioDeviceRenesas, USBAudioDeviceTinyUSB, USBAudioDeviceTinyUSBFreeRTOS, USBAudioHostESP32, USBAudioHostTinyUSB, and USBAudioHostTinyUSBFreeRTOS.
|
inlinevirtualinherited |
Deletes all change notify subscriptions.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inline |
Provides the active configuration.
|
inlineprotected |
|
inlinevirtualinherited |
Reimplemented in FaustStream< DSP >, AudioMP34DT05, I2SCodecStream, MozziStream, PureDataStream, SPDIFOutput, VS1053Stream, WM8960Stream, AdaptiveResamplingStream, AudioLoRa, ESPNowStream, BufferedTaskStream, URLStreamBufferedT< T >, URLStreamBufferedT< ICYStream >, USBAudioDeviceBase, USBAudioHostBase, GoertzelStream, Equalizer3BandsT< T >, I2SStream, AudioStreamWrapper, TimerCallbackAudioStream, FormatConverterStream, FileLoopT< FileType >, FileLoopT< File >, EqualizerNBands< SampleT, AccT, NUM_TAPS, NUM_BANDS >, EncodedAudioStream, AudioKitStream, MiniAudioStream, PortAudioStream, StdioStream, A2DPStream, HLSStreamT< URLStream >, HttpRequest, ICYStreamT< T >, URLStream, URLStreamESP32, NRF24Stream, SPIAudioSlave, AutomaticGainControlStream, VolumeStream, AnalogAudioStream, AudioEffectStreamT< T >, AudioEffectStream, Equalizer3BandsPerChannelT< T >, ReformatBaseStream, AdapterAudioOutputToAudioStream, MemoryStream, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, InputMixer< T, SumT >, InputMerge< T >, CallbackStream, FilteredStream< T, TF >, FilteredStream< int16_t, int16_t >, ChannelFormatConverterStream, NumberFormatConverterStream, CatStream, QueueStream< T >, QueueStream< uint8_t >, DynamicMemoryStream, Pipeline, Pipeline::ModifyingStreamAdapter, SupportedRatesStream, AudioFFTBase, AudioBLEClient, AudioBLEClient, AudioBLEServer, AudioBLEServer, AbstractURLStream, and AudioBLEStream.
|
inlinestaticprotected |
Convert linear volume (0.0–1.0) to UAC2 int16 (1/256 dB). Linear mapping: 0.0 → -100 dB (min), 1.0 → 0 dB (max).
|
inlineoverridevirtualinherited |
Reimplemented from Print.
Reimplemented in PureDataStream, URLStreamBufferedT< T >, URLStreamBufferedT< ICYStream >, ReformatBaseStream, AudioStreamWrapper, ResampleStream, EncodedAudioStream, URLStream, BufferedTaskStream, AutomaticGainControlStream, MeasuringStream, QualityAnalysisStream, VolumeStream, AudioEffectStreamT< T >, AudioEffectStream, Equalizer3BandsT< T >, Equalizer3BandsPerChannelT< T >, I2SStream, TimedStream, MemoryStream, RingBufferStream, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, BufferedStream, FilteredStream< T, TF >, FilteredStream< int16_t, int16_t >, QueueStream< T >, QueueStream< uint8_t >, FadeStream, Pipeline::ModifyingStreamAdapter, SupportedRatesStream, and EqualizerNBands< SampleT, AccT, NUM_TAPS, NUM_BANDS >.
|
inlinevirtual |
Returns the actual core on which the call is running (for RP2040)
Reimplemented in USBAudioDeviceBase, USBAudioDeviceESP32, USBAudioDeviceTinyUSB, and USBAudioHostESP32.
|
inlineprotected |
Returns the effective volume for a per-channel index (1-based). Combines master volume (index 0) with per-channel volume and mute.
|
inline |
Returns true if the IN endpoint is enabled.
|
inline |
Returns true if the OUT endpoint is enabled.
|
inline |
Returns the current mute state for the given channel.
| channel | 0 = master, 1..N = per-channel. |
|
inlineinherited |
Checks if the automatic AudioInfo update is active.
|
inline |
Returns true if either the TX or RX stream is open.
|
pure virtual |
Returns true if the stream used by readBytes() is open.
Implemented in USBAudioDeviceBase, and USBAudioHostBase.
|
pure virtual |
Returns true if the stream used by write() is open.
Implemented in USBAudioDeviceBase, and USBAudioHostBase.
|
inlinestaticprotected |
|
pure virtual |
Returns true if the USB connection is established (device: enumerated by the host; host: an audio device is attached).
Implemented in USBAudioDeviceBase, and USBAudioHostBase.
|
inlineprotectedvirtualinherited |
|
inlineprotectedinherited |
|
inlineprotected |
|
inlineprotectedvirtual |
Called by setMute() after the state was updated: propagate the change to the USB peer.
Reimplemented in USBAudioDeviceBase, and USBAudioHostBase.
|
inlineprotectedvirtual |
Called by setVolume() after the state was updated: propagate the change to the USB peer.
Reimplemented in USBAudioDeviceBase, and USBAudioHostBase.
|
inlineoverridevirtual |
Returns true when begin() has been called and the USB connection is established.
Reimplemented from AudioStream.
|
inlineprotected |
|
inlineprotected |
Process audio data for volume control.
|
inlinevirtual |
Receive audio data from the USB peer. Until bufferRx() has filled past config.rx_start_fill_percent at least once after begin(), no data is returned. This is a one-shot startup prime only – once reached, readBytes() keeps draining normally for the rest of the session and is not gated again by later underruns.
Reimplemented from AudioStream.
|
inlinevirtualinherited |
Source to generate silence: just sets the buffer to 0.
|
inlineprotectedinherited |
Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()
|
inlinevirtualinherited |
Removes a target in order not to be notified about audio changes.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
protectedpure virtual |
Resize the platform audio buffers.
Implemented in USBAudioDeviceESP32, USBAudioDeviceRenesas, USBAudioDeviceTinyUSB, USBAudioDeviceTinyUSBFreeRTOS, USBAudioHostESP32, USBAudioHostTinyUSB, and USBAudioHostTinyUSBFreeRTOS.
|
pure virtual |
Process pending USB events on platforms where the application drives the stack. No-op where a dedicated task runs the stack.
Implemented in USBAudioDeviceESP32, USBAudioDeviceRenesas, USBAudioDeviceTinyUSB, USBAudioHostESP32, USBAudioHostTinyUSB, and USBAudioDeviceBase.
|
inlineoverridevirtualinherited |
Defines the input AudioInfo.
Implements AudioInfoSupport.
Reimplemented in VS1053Stream, WM8960Stream, AutomaticGainControlStream, VolumeStream, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, MiniAudioStream, PortAudioStream, I2SCodecStream, MozziStream, SPDIFOutput, AudioLoRa, AnalogAudioStream, I2SStream, TimerCallbackAudioStream, AudioBLEStream, MDFEchoCancellationStream< T, SampleType >, AudioKitStream, NRF24Stream, SPIAudioSlave, USBAudioDeviceBase, USBAudioHostBase, VBANStream, GoertzelStream, MeasuringStream, QualityAnalysisStream, Equalizer3BandsT< T >, Equalizer3BandsPerChannelT< T >, AdapterAudioOutputToAudioStream, TimedStream, ProgressStream, CallbackStream, VolumeMeter, AudioInputMonitor, FormatConverterStream, FadeStream, Pipeline::ModifyingStreamAdapter, AudioFFTBase, EncodedAudioStream, PureDataStream, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, Pipeline, ResampleStream, ResampleStreamT< TInterpolator >, and SupportedRatesStream.
|
inlineprotected |
Set the USB audio configuration (use begin(cfg) instead).
|
inline |
Set the mute state for a channel and notify the USB peer.
| m | true = muted, false = unmuted. |
| channel | 0 = master, 1..N = per-channel. |
|
inline |
Register a callback invoked when the mute state changes.
| cb | Callback receiving (bool muted, uint8_t channel). |
|
inlineinherited |
Deactivate/Reactivate automatic AudioInfo updates: (default is active)
|
inline |
Register a callback invoked when the sample rate changes.
| cb | Callback receiving the new rate in Hz. |
|
inline |
Register a callback invoked when the streaming state changes (a streaming interface was opened or closed).
| cb | Callback receiving (bool active_tx, bool active_rx). |
|
inlineprotected |
(Re)sizes the volume and mute state: master (index 0) + one per channel
|
inline |
Set the volume for a channel and notify the USB peer.
| vol | Volume as a float 0.0 (silence) to 1.0 (0 dB). |
| channel | 0 = master, 1..N = per-channel. |
|
inlineoverridevirtual |
sets the volume for the master channel (channel 0)
Reimplemented from VolumeSupport.
|
inline |
Register a callback invoked when the volume changes.
| cb | Callback receiving (float volume, uint8_t channel). |
|
inlineinherited |
|
inlinestaticprotected |
Convert UAC2 int16 (1/256 dB) to linear volume (0.0–1.0). Linear mapping within the -100..0 dB range reported by GET_RANGE.
|
inlineoverridevirtual |
gets the volume for the master channel (channel 0)
Reimplemented from VolumeSupport.
|
inline |
Returns the current volume for the given channel.
| channel | 0 = master, 1..N = per-channel. |
|
inlinevirtual |
Send audio data to the USB peer. Silently discards data while the TX stream is not open so StreamCopy doesn't report write errors before streaming starts.
Reimplemented from AudioStream.
|
inlineoverridevirtualinherited |
Reimplemented in MemoryStream, AudioStreamWrapper, BufferedTaskStream, RingBufferStream, BufferedStream, and URLStream.
|
inlinevirtualinherited |
Writes len bytes of silence (=0).
|
protectedinherited |
|
protected |
|
protected |
|
protectedinherited |
|
protected |
|
protectedinherited |
|
protected |
|
staticconstexprprotected |
Convert AudioTools volume (0.0–1.0) to UAC2 int16 (1/256 dB). 0.0 maps to 0x8000 (silence), 1.0 maps to 0 (0 dB).
|
protected |
|
protected |
|
protectedinherited |
|
protected |
|
protected |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protected |
|
protected |
|
protected |
|
protectedinherited |
|
protectedinherited |