|
arduino-audio-tools
|
USB Audio Device class for audio streaming over USB. More...
#include <USBAudioDeviceBase.h>
Public Member Functions | |
| USBAudioDeviceBase () | |
| Default Constructor. | |
| USBAudioDeviceBase (USBAudioConfig cfg) | |
| Constructor which provides configuration at construction time. | |
| 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 () |
| uint16_t | audioPacketSize () const |
| One isochronous USB packet size in bytes (same formula as the descriptor builder). | |
| int | available () override |
| Bytes of received audio waiting in the RX buffer. | |
| int | availableForWrite () override |
| Bytes of free space in the TX buffer. | |
| bool | begin () |
| (Re-)start the USB audio device with the current config. | |
| bool | begin (const USBAudioConfig &cfg) |
| Apply a config and start the USB audio device. | |
| virtual void | clearNotifyAudioChange () |
| Deletes all change notify subscriptions. | |
| USBAudioConfig | defaultConfig (RxTxMode mode=RXTX_MODE) |
| Returns a default configuration pre-filled for the requested direction (RX_MODE, TX_MODE, or RXTX_MODE). Use TX if you write and rx if you want to read audio data. RXTX is for full duplex. | |
| void | end () |
| Stop audio streaming and clear FIFOs. Does not disconnect USB. | |
| virtual void | flush () override |
| uint8_t | getAudioCount () const |
| Returns the number of audio functions (always 1). | |
| usbd_class_driver_t const * | getClassDriver (uint8_t *count) |
| Get the USB device class driver for TinyUSB integration. | |
| uint16_t | getDescriptor (uint8_t *desc) |
| Returns the audio-function descriptor block for use in tud_descriptor_configuration_cb(). | |
| uint32_t | getRxTotalBytes () const |
| Total bytes received from host via OUT endpoint. | |
| uint32_t | getRxXferCount () const |
| Number of times audiod_xfer_cb fired for the OUT endpoint. | |
| uint8_t | getTxBytesPerSample () const |
| TX bytes per sample parsed from the descriptor. | |
| uint8_t | getTxChannels () const |
| TX channel count parsed from the descriptor. | |
| uint32_t | getTxFifoReadTotal () const |
| uint16_t | getTxFrameBytesLast () const |
| uint8_t | getTxInterval () const |
| TX isochronous interval (bInterval) parsed from the descriptor. | |
| uint32_t | getTxSampleRate () const |
| TX sample rate parsed from the descriptor (must be non-zero for flow control). | |
| uint32_t | getTxXferCount () const |
| Number of times audiod_xfer_cb fired for the IN endpoint. | |
| uint32_t | getTxXferredLast () const |
| bool | isEpInEnabled () const |
| Returns true if the IN endpoint is enabled. | |
| bool | isEpInFlowControlEnabled () const |
| Returns true if IN endpoint flow control is enabled. When on, the per-frame isochronous packet size is varied so non-integer sample-per- frame rates (e.g. 44100 Hz) are delivered at the exact average rate. | |
| bool | isEpOutEnabled () const |
| Returns true if the OUT endpoint is enabled. | |
| bool | isFeedbackEpEnabled () const |
| Returns true if the feedback endpoint is enabled. Only meaningful in pure RX (OUT-only) mode: with an IN endpoint present the host uses the TX stream as implicit feedback instead. | |
| bool | isFifoMutexEnabled () const |
| Returns true if FIFO mutex is enabled. | |
| bool | isInterruptEpEnabled () const |
| Returns true if the interrupt 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 IN or OUT streaming endpoint is open. | |
| bool | isStreamingActiveRx () const |
| Returns true if the host has opened the OUT (playback) stream. | |
| bool | isStreamingActiveTx () const |
| Returns true if the host has opened the IN (capture) stream. | |
| bool | isTxXferArmed () const |
| True if the initial isochronous IN transfer was armed successfully. | |
| bool | mounted () const |
| Returns true if the device is mounted by the USB host. | |
| uint8_t | numInterfaces () const |
| Total number of USB interfaces claimed by the audio function (1 AC + 1 or 2 AS), for use in the bNumInterfaces field of the configuration descriptor. | |
| operator bool () override | |
| Returns true when begin() has been called and the USB host has mounted the device. | |
| size_t | readBytes (uint8_t *buffer, size_t bufsize) |
| Receive audio data from the host (host → device, speaker/playback). | |
| 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. | |
| void | setAudioFeedbackFormatCorrectionCallback (std::function< bool(USBAudioDeviceBase *, uint8_t)> cb) |
| Register a callback for audio feedback format correction events. | |
| void | setAudioFeedbackParamsCallback (std::function< void(USBAudioDeviceBase *, uint8_t, uint8_t, audio_feedback_params_t *)> cb) |
| Register a callback for audio feedback parameter events. | |
| void | setAudioInfo (AudioInfo info) override |
| Change the sample rate and notify the host. | |
| void | setFbDoneCallback (std::function< void(USBAudioDeviceBase *, uint8_t)> cb) |
| Register a callback for feedback done events. | |
| void | setGetReqEpCallback (std::function< bool(USBAudioDeviceBase *, uint8_t, tusb_control_request_t const *)> cb) |
| Register a callback for GET requests on an endpoint. | |
| void | setGetReqItfCallback (std::function< bool(USBAudioDeviceBase *, uint8_t, tusb_control_request_t const *)> cb) |
| Register a callback for GET requests on the interface. | |
| void | setIntDoneCallback (std::function< void(USBAudioDeviceBase *, uint8_t)> cb) |
| Register a callback for interrupt done events. | |
| void | setItfCloseEpCallback (std::function< bool(USBAudioDeviceBase *, uint8_t, tusb_control_request_t const *)> cb) |
| Register a callback for interface close endpoint events. | |
| bool | setMute (bool m, uint8_t channel=0) |
| Set the mute state for a channel and notify the host. | |
| void | setMuteCallback (std::function< void(bool, uint8_t)> cb) |
| Register a callback invoked when the host (or device) changes the mute state. | |
| void | setNotifyActive (bool flag) |
| Deactivate/Reactivate automatic AudioInfo updates: (default is active) | |
| void | setReqEntityCallback (std::function< bool(USBAudioDeviceBase *, uint8_t)> cb) |
| Register a callback for entity requests. | |
| void | setReqEntityCallback (std::function< bool(USBAudioDeviceBase *, uint8_t, tusb_control_request_t const *, uint8_t *)> cb) |
| Register a callback for entity set requests. | |
| void | setReqEpCallback (std::function< bool(USBAudioDeviceBase *, uint8_t, tusb_control_request_t const *, uint8_t *)> cb) |
| Register a callback for endpoint set requests. | |
| void | setReqItfCallback (std::function< bool(USBAudioDeviceBase *, uint8_t, tusb_control_request_t const *, uint8_t *)> cb) |
| Register a callback for interface set requests. | |
| void | setRxDoneCallback (std::function< bool(USBAudioDeviceBase *, uint8_t, audiod_function_t *, uint16_t)> cb) |
| Register a callback for RX done events. | |
| void | setSampleRateCallback (std::function< void(uint32_t)> cb) |
| Register a callback invoked when the host (or device) changes the sample rate. | |
| void | setStreamingStateCallback (std::function< void(bool, bool)> cb) |
| Register a callback invoked when the streaming state changes. Fires when the host opens or closes a streaming interface (SET_INTERFACE alt=1 / alt=0). | |
| void | setTudAudioSetItfCallback (std::function< bool(USBAudioDeviceBase *, uint8_t, tusb_control_request_t const *)> cb) |
| Register a callback for interface set requests. | |
| void | setTxDoneCallback (std::function< bool(USBAudioDeviceBase *, uint8_t, audiod_function_t *)> cb) |
| Register a callback for TX done events. | |
| bool | setVolume (float vol, uint8_t channel) |
| Set the volume for a channel and notify the host. | |
| 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 host (or device) changes the volume. | |
| 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 host (device → host, microphone/capture). Silently discards data when the host has not opened the capture device (alt=0) so StreamCopy doesn't report write errors before recording. | |
| virtual size_t | write (uint8_t ch) override |
| virtual void | writeSilence (size_t len) |
| Writes len bytes of silence (=0). | |
Static Public Member Functions | |
| static USBAudioDeviceBase & | activeInstance () |
| Returns the most-recently-constructed instance (base or subclass). | |
Protected Member Functions | |
| bool | activateEndpoint (uint8_t rhport, tusb_desc_endpoint_t const *desc_ep, uint8_t dir=TUSB_DIR_IN) |
| void | alloc_mutex () |
| bool | audiod_calc_tx_packet_sz (audiod_function_t *audio) |
| bool | audiod_control_complete (uint8_t rhport, tusb_control_request_t const *p_request) |
| bool | audiod_control_request (uint8_t rhport, tusb_control_request_t const *p_request) |
| bool | audiod_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) |
| bool | audiod_deinit (void) |
| bool | audiod_fb_send (audiod_function_t *audio) |
| bool | audiod_get_AS_interface_index (uint8_t itf, audiod_function_t *audio, uint8_t *idxItf, uint8_t const **pp_desc_int) |
| bool | audiod_get_AS_interface_index_global (uint8_t itf, uint8_t *func_id, uint8_t *idxItf, uint8_t const **pp_desc_int) |
| bool | audiod_get_interface (uint8_t rhport, tusb_control_request_t const *p_request) |
| void | audiod_init (void) |
| uint16_t | audiod_open (uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) |
| void | audiod_parse_flow_control_params (audiod_function_t *audio, uint8_t const *p_desc) |
| void | audiod_reset (uint8_t rhport) |
| bool | audiod_set_fb_params_freq (audiod_function_t *audio, uint32_t sample_freq, uint32_t mclk_freq) |
| bool | audiod_set_interface (uint8_t rhport, tusb_control_request_t const *p_request) |
| TU_ATTR_FAST_FUNC void | audiod_sof_isr (uint8_t rhport, uint32_t frame_count) |
| uint16_t | audiod_tx_packet_size_fc (audiod_function_t *audio) |
| bool | audiod_verify_entity_exists (uint8_t itf, uint8_t entityID, uint8_t *func_id) |
| bool | audiod_verify_ep_exists (uint8_t ep, uint8_t *func_id) |
| bool | audiod_verify_itf_exists (uint8_t itf, uint8_t *func_id) |
| bool | audiod_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) |
| TODO refactor control request handling to separate function and reduce nesting. | |
| virtual bool | beginUSB ()=0 |
| Override in platform subclasses to register descriptors and start the USB host-controller stack (e.g. USB.begin() on ESP32). Called at the end of begin(cfg, info). The base no-op is correct for RP2040 where TinyUSB is started by the system before setup(). | |
| 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. | |
| void | closeEpIn (uint8_t rhport, audiod_function_t *audio, uint8_t itf, tusb_control_request_t const *p_request) |
| void | closeEpOut (uint8_t rhport, audiod_function_t *audio, uint8_t itf, tusb_control_request_t const *p_request) |
| bool | configChanged (const USBAudioConfig &n) |
| uint16_t | fifoSize () const |
| uint16_t | getCtrlBufSz (uint8_t fn) const |
| uint16_t | getDescLen (uint8_t fn) const |
| uint16_t | getEpInSwBufSz (uint8_t fn) const |
| uint16_t | getEpOutSwBufSz (uint8_t fn) const |
| 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. | |
| bool | handleClockSourceGet (uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *cb) |
| bool | handleEndpointRequest (uint8_t rhport, tusb_control_request_t const *p_request) |
| bool | handleEntityRequest (uint8_t rhport, tusb_control_request_t const *p_request, uint8_t entityID) |
| bool | handleFeatureUnitGet (uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *cb) |
| bool | handleInterfaceRequest (uint8_t rhport, tusb_control_request_t const *p_request) |
| bool | isFeatureUnit (uint8_t id) const |
| Returns true if the given entity ID is a Feature Unit (FU1 or FU2). | |
| bool | isUseLinearBufferRx () const |
| bool | isUseLinearBufferTx () const |
| virtual int | not_supported (int out, const char *msg="") |
| void | notifyAudioChange (AudioInfo info) |
| void | notifyStreamingState () |
| bool | openEndpointsForAltSetting (uint8_t rhport, audiod_function_t *audio, uint8_t func_id, uint8_t itf, uint8_t alt) |
| void | openEpFeedback (audiod_function_t *audio, tusb_desc_endpoint_t const *desc_ep) |
| void | openEpIn (uint8_t rhport, audiod_function_t *audio, uint8_t itf, tusb_desc_endpoint_t const *desc_ep, uint8_t const *p_desc_for_params) |
| void | openEpOut (uint8_t rhport, audiod_function_t *audio, uint8_t itf, tusb_desc_endpoint_t const *desc_ep) |
| uint16_t | packetSize () const |
| 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. Both platforms use NBuffer-style block pools: block size = max USB packet, block count = fifo_packets. ESP32: SynchronizedNBufferRTOS (FreeRTOS queues, cross-core safe). RP2040: NBuffer (single-core, no synchronization needed). | |
| void | sendInterruptNotification (uint8_t ctrlSel, uint8_t channel, uint8_t entityID) |
| Send a UAC2 status/change notification via the AC interrupt EP. | |
| virtual void | serviceTinyUSB () |
| Process pending USB events on platforms where the application drives the stack (RP2040, STM32, ...). Skipped when a dedicated FreeRTOS task already calls tud_task() continuously (see usb_task_active_) - tud_task() is not re-entrant; calling it from two contexts concurrently corrupts TinyUSB's internal event queue and causes random hangs. | |
| void | setConfig (const USBAudioConfig &cfg) |
| Set the USB audio configuration (use begin(cfg) instead). | |
| void | setSampleRate (uint32_t rate) |
| Device-initiated sample rate change. | |
| void | setupFeedback (audiod_function_t *audio, uint8_t func_id, uint8_t alt) |
| void | tud_audio_feedback_interval_isr (uint8_t func_id, uint32_t, uint8_t frame_shift) |
| uint16_t | tud_audio_n_available (uint8_t func_id) |
| uint16_t | tud_audio_n_read (uint8_t func_id, void *buffer, uint16_t bufsize) |
| uint16_t | tud_audio_n_write (uint8_t func_id, const void *data, uint16_t len) |
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 constexpr size_t | getResetSize () |
| 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 | active_config_ |
| std::vector< audiod_function_t > | audiod_fct_ |
| USBAudioConfig | config_ |
| std::vector< uint16_t > | ctrl_buf_sz_ |
| std::vector< uint16_t > | desc_len_ |
| USBAudio2DescriptorBuilder | descr_builder {config_} |
| std::vector< uint16_t > | ep_in_sw_buf_sz_ |
| std::vector< osal_mutex_def_t > | ep_out_ff_mutex_rd_ |
| std::vector< uint16_t > | ep_out_sw_buf_sz_ |
| std::function< void(USBAudioDeviceBase *, uint8_t func_id)> | fb_done_cb_ |
| std::function< bool(USBAudioDeviceBase *, uint8_t rhport, tusb_control_request_t const *)> | get_req_ep_cb_ |
| std::function< bool(USBAudioDeviceBase *, uint8_t rhport, tusb_control_request_t const *)> | get_req_itf_cb_ |
| AudioInfo | info |
| std::function< void(USBAudioDeviceBase *, uint8_t rhport)> | int_done_cb_ |
| uint8_t | int_notify_buf_ [6] = {} |
| 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 |
| std::function< bool(USBAudioDeviceBase *, uint8_t func_id)> | req_entity_cb_ |
| std::function< bool(USBAudioDeviceBase *, uint8_t rhport, audiod_function_t *, uint16_t xferred_bytes)> | rx_done_cb_ |
| volatile uint32_t | rx_total_bytes_ = 0 |
| 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} |
| std::function< bool(USBAudioDeviceBase *, uint8_t func_id)> | tud_audio_feedback_format_correction_cb_ |
| std::function< void(USBAudioDeviceBase *, uint8_t func_id, uint8_t alt_itf, audio_feedback_params_t *feedback_param)> | tud_audio_feedback_params_cb_ |
| std::function< bool(USBAudioDeviceBase *, uint8_t rhport, tusb_control_request_t const *p_request)> | tud_audio_set_itf_cb_ |
| std::function< bool(USBAudioDeviceBase *, uint8_t rhport, tusb_control_request_t const *p_request)> | tud_audio_set_itf_close_EP_cb_ |
| std::function< bool(USBAudioDeviceBase *, uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff)> | tud_audio_set_req_entity_cb_ |
| std::function< bool(USBAudioDeviceBase *, uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff)> | tud_audio_set_req_ep_cb_ |
| std::function< bool(USBAudioDeviceBase *, uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff)> | tud_audio_set_req_itf_cb_ |
| std::function< bool(USBAudioDeviceBase *, uint8_t rhport, audiod_function_t *)> | tx_done_cb_ |
| volatile uint32_t | tx_fifo_read_total_ = 0 |
| volatile uint16_t | tx_frame_bytes_last_ = 0 |
| bool | tx_xfer_armed_ = false |
| volatile uint32_t | tx_xferred_last_ = 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 |
| volatile uint32_t | xfer_cb_rx_count_ = 0 |
| volatile uint32_t | xfer_cb_tx_count_ = 0 |
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). | |
| static USBAudioDeviceBase * | s_active_ = nullptr |
USB Audio Device class for audio streaming over USB.
This class implements a USB audio device, providing configuration, descriptor management, endpoint setup, and control request handling for audio streaming over USB. It supports multiple audio formats, feedback methods, and endpoint configurations, and is designed for use with TinyUSB or native USB on supported MCUs.
|
inline |
Default Constructor.
|
inline |
Constructor which provides configuration at construction time.
|
inlineprotected |
|
inlinestatic |
Returns the most-recently-constructed instance (base or subclass).
Set in the constructor via s_active_, so usbd_app_driver_get_cb() and the static process() trampoline can reach the right object without a singleton.
|
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.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
TODO refactor control request handling to separate function and reduce nesting.
|
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, and ResampleStreamT< TInterpolator >.
|
inline |
One isochronous USB packet size in bytes (same formula as the descriptor builder).
|
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.
|
inlinevirtual |
(Re-)start the USB audio device with the current config.
Safe to call more than once: descriptor building, FIFO allocation, and USB stack startup only run on the first call. Subsequent calls just push the current volume/mute/sample-rate state to the host.
Reimplemented from BaseStream.
|
inline |
Apply a config and start the USB audio device.
Before the first begin() all fields may be changed freely. Once started, only the sample rate can change at runtime (via setSampleRate()); descriptor-level fields like channels, bit depth, and endpoint addresses are fixed by the USB enumeration.
| cfg | Audio configuration. |
|
protectedpure virtual |
Override in platform subclasses to register descriptors and start the USB host-controller stack (e.g. USB.begin() on ESP32). Called at the end of begin(cfg, info). The base no-op is correct for RP2040 where TinyUSB is started by the system before setup().
Implemented in USBAudioDeviceESP32, USBAudioDeviceTinyUSB, and USBAudioDeviceTinyUSBFreeRTOS.
|
protectedpure virtual |
Returns the RX audio buffer. Must be overridden by subclasses.
Implemented in USBAudioDeviceESP32, USBAudioDeviceTinyUSB, and USBAudioDeviceTinyUSBFreeRTOS.
|
protectedpure virtual |
Returns the TX audio buffer. Must be overridden by subclasses.
Implemented in USBAudioDeviceESP32, USBAudioDeviceTinyUSB, and USBAudioDeviceTinyUSBFreeRTOS.
|
inlinevirtualinherited |
Deletes all change notify subscriptions.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inline |
Returns a default configuration pre-filled for the requested direction (RX_MODE, TX_MODE, or RXTX_MODE). Use TX if you write and rx if you want to read audio data. RXTX is for full duplex.
| mode | Audio direction. |
|
inlinevirtual |
Stop audio streaming and clear FIFOs. Does not disconnect USB.
Reimplemented from BaseStream.
|
inlineprotected |
|
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, I2SStream, MemoryStream, RingBufferStream, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, and BufferedStream.
|
inline |
Returns the number of audio functions (always 1).
|
inline |
Get the USB device class driver for TinyUSB integration.
| count | Pointer to store the number of drivers (always 1). |
|
inlineprotected |
|
inlineprotected |
|
inline |
Returns the audio-function descriptor block for use in tud_descriptor_configuration_cb().
Call begin() first so that the config is known. The returned pointer points to an internal static buffer that is valid for the lifetime of the program; copy it into your configuration descriptor buffer.
| [out] | len | Total byte count of the returned block. |
|
inlineprotected |
|
inlineprotected |
|
inlinestaticconstexprprotected |
|
inline |
Total bytes received from host via OUT endpoint.
|
inline |
Number of times audiod_xfer_cb fired for the OUT endpoint.
|
inline |
TX bytes per sample parsed from the descriptor.
|
inline |
TX channel count parsed from the descriptor.
|
inline |
Total bytes read from ep_in_ff by xfer_cb (should grow at ~176KB/s for 44100Hz stereo 16-bit).
|
inline |
Last frame_bytes computed by flow control (should be ~176-180 for 44100Hz).
|
inline |
TX isochronous interval (bInterval) parsed from the descriptor.
|
inline |
TX sample rate parsed from the descriptor (must be non-zero for flow control).
|
inline |
Number of times audiod_xfer_cb fired for the IN endpoint.
|
inline |
xferred_bytes from the previous completed transfer (what the DCD actually sent).
|
inlineprotected |
Returns the effective volume for a per-channel index (1-based). Combines master volume (index 0) with per-channel volume and mute.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inline |
Returns true if the IN endpoint is enabled.
|
inline |
Returns true if IN endpoint flow control is enabled. When on, the per-frame isochronous packet size is varied so non-integer sample-per- frame rates (e.g. 44100 Hz) are delivered at the exact average rate.
|
inline |
Returns true if the OUT endpoint is enabled.
|
inlineprotected |
Returns true if the given entity ID is a Feature Unit (FU1 or FU2).
|
inline |
Returns true if the feedback endpoint is enabled. Only meaningful in pure RX (OUT-only) mode: with an IN endpoint present the host uses the TX stream as implicit feedback instead.
|
inline |
Returns true if FIFO mutex is enabled.
|
inline |
Returns true if the interrupt 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 IN or OUT streaming endpoint is open.
|
inline |
Returns true if the host has opened the OUT (playback) stream.
|
inline |
Returns true if the host has opened the IN (capture) stream.
|
inline |
True if the initial isochronous IN transfer was armed successfully.
|
inlineprotected |
|
inlineprotected |
|
inlinestaticprotected |
|
inline |
Returns true if the device is mounted by the USB host.
|
inlineprotectedvirtualinherited |
|
inlineprotectedinherited |
|
inlineprotected |
|
inline |
Total number of USB interfaces claimed by the audio function (1 AC + 1 or 2 AS), for use in the bNumInterfaces field of the configuration descriptor.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineoverridevirtual |
Returns true when begin() has been called and the USB host has mounted the device.
Reimplemented from AudioStream.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
Process audio data for volume control.
|
inlinevirtual |
Receive audio data from the host (host → device, speaker/playback).
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. Both platforms use NBuffer-style block pools: block size = max USB packet, block count = fifo_packets. ESP32: SynchronizedNBufferRTOS (FreeRTOS queues, cross-core safe). RP2040: NBuffer (single-core, no synchronization needed).
Implemented in USBAudioDeviceESP32, USBAudioDeviceTinyUSB, and USBAudioDeviceTinyUSBFreeRTOS.
|
inlineprotected |
Send a UAC2 status/change notification via the AC interrupt EP.
6-byte message: bInfo(1) bAttribute(1) wValue(2) wIndex(2). The host will re-query the affected control with GET_CUR.
| ctrlSel | Control selector (e.g. AUDIO_FU_CTRL_VOLUME). |
| channel | Channel number (0 = master). |
| entityID | Target entity (Feature Unit or Clock Source). |
|
inlineprotectedvirtual |
Process pending USB events on platforms where the application drives the stack (RP2040, STM32, ...). Skipped when a dedicated FreeRTOS task already calls tud_task() continuously (see usb_task_active_) - tud_task() is not re-entrant; calling it from two contexts concurrently corrupts TinyUSB's internal event queue and causes random hangs.
ESP32 (see USBAudioDeviceESP32) overrides this to an empty no-op, since its own FreeRTOS task already calls tud_task() continuously.
Reimplemented in USBAudioDeviceESP32.
|
inline |
Register a callback for audio feedback format correction events.
| cb | Callback function. |
|
inline |
Register a callback for audio feedback parameter events.
| cb | Callback function. |
|
inlineoverridevirtual |
Change the sample rate and notify the host.
Reimplemented from AudioStream.
|
inlineprotected |
Set the USB audio configuration (use begin(cfg) instead).
|
inline |
Register a callback for feedback done events.
| cb | Callback function. |
|
inline |
Register a callback for GET requests on an endpoint.
| cb | Callback function. |
|
inline |
Register a callback for GET requests on the interface.
| cb | Callback function. |
|
inline |
Register a callback for interrupt done events.
| cb | Callback function. |
|
inline |
Register a callback for interface close endpoint events.
| cb | Callback function. |
|
inline |
Set the mute state for a channel and notify the host.
| m | true = muted, false = unmuted. |
| channel | 0 = master, 1..N = per-channel. |
|
inline |
Register a callback invoked when the host (or device) changes the mute state.
| cb | Callback receiving (bool muted, uint8_t channel). |
|
inlineinherited |
Deactivate/Reactivate automatic AudioInfo updates: (default is active)
|
inline |
Register a callback for entity requests.
| cb | Callback function. |
|
inline |
Register a callback for entity set requests.
| cb | Callback function. |
|
inline |
Register a callback for endpoint set requests.
| cb | Callback function. |
|
inline |
Register a callback for interface set requests.
| cb | Callback function. |
|
inline |
Register a callback for RX done events.
| cb | Callback function. |
|
inlineprotected |
Device-initiated sample rate change.
Updates the internal config, fires the sample-rate callback, and notifies the host via the AC interrupt endpoint (Clock Source SAM_FREQ CUR). The host will typically re-issue SET_INTERFACE to restart streaming at the new rate.
| rate | New sample rate in Hz (should be one of the 14 rates advertised in the Clock Source GET_RANGE response). |
|
inline |
Register a callback invoked when the host (or device) changes the sample rate.
| cb | Callback receiving the new rate in Hz. |
|
inline |
Register a callback invoked when the streaming state changes. Fires when the host opens or closes a streaming interface (SET_INTERFACE alt=1 / alt=0).
| cb | Callback receiving (bool active_tx, bool active_rx). |
|
inline |
Register a callback for interface set requests.
| cb | Callback function. |
|
inline |
Register a callback for TX done events.
| cb | Callback function. |
|
inlineprotected |
|
inline |
Set the volume for a channel and notify the host.
| 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 host (or device) changes the volume.
| cb | Callback receiving (float volume, uint8_t channel). |
|
inlineinherited |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
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 host (device → host, microphone/capture). Silently discards data when the host has not opened the capture device (alt=0) so StreamCopy doesn't report write errors before recording.
Reimplemented from AudioStream.
|
inlineoverridevirtualinherited |
Reimplemented in MemoryStream, AudioStreamWrapper, BufferedTaskStream, RingBufferStream, BufferedStream, and URLStream.
|
inlinevirtualinherited |
Writes len bytes of silence (=0).
|
protectedinherited |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protectedinherited |
|
protected |
|
protected |
|
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 |
|
inlinestaticprotected |
|
protected |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protected |
|
protected |