|
| | 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).
|
| |
|
| 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.
|
| |
| void | serviceTinyUSB () |
| | Process pending USB events on platforms where the application drives the stack (RP2040). No-op on ESP32 where a dedicated FreeRTOS task calls tud_task() continuously.
|
| |
| 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) |
| |
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.
- Author
- Phil Schatzmann
- Copyright
- GPLv3