summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinhard Panhuber <[email protected]>2021-04-07 20:07:28 +0200
committerReinhard Panhuber <[email protected]>2021-04-07 20:07:28 +0200
commit8eacdffebdcc10a6fffdc248ef6086b223f3edf3 (patch)
tree9d6fa9ec83fa56ee671830b2ead8ceaea4c1eedd /src
parentd9a0cc9e9f328db15df6cc31b2a04532d4e8ad35 (diff)
Optimize encode/decode - refactor unnecessary repetitive division
Diffstat (limited to 'src')
-rw-r--r--src/class/audio/audio_device.c16
-rw-r--r--src/class/audio/audio_device.h3
2 files changed, 11 insertions, 8 deletions
diff --git a/src/class/audio/audio_device.c b/src/class/audio/audio_device.c
index a85dfddb8..2e9684cb9 100644
--- a/src/class/audio/audio_device.c
+++ b/src/class/audio/audio_device.c
@@ -310,6 +310,7 @@ typedef struct
audio_data_format_type_I_t format_type_I_rx;
uint8_t n_bytes_per_sampe_rx;
uint8_t n_channels_per_ff_rx;
+ uint8_t n_ff_used_rx;
#endif
#endif
@@ -322,6 +323,7 @@ typedef struct
audio_data_format_type_I_t format_type_I_tx;
uint8_t n_bytes_per_sampe_tx;
uint8_t n_channels_per_ff_tx;
+ uint8_t n_ff_used_tx;
#endif
#endif
@@ -625,10 +627,7 @@ static bool audiod_decode_type_I_pcm(uint8_t rhport, audiod_interface_t* audio,
(void) rhport;
// Determine amount of samples
- uint8_t const n_ff_used = audio->n_channels_rx / audio->n_channels_per_ff_rx;
-
- TU_ASSERT( n_ff_used <= audio->n_rx_supp_ff );
-
+ uint8_t const n_ff_used = audio->n_ff_used_rx;
uint16_t const nBytesToCopy = audio->n_channels_per_ff_rx * audio->n_bytes_per_sampe_rx;
uint16_t const nBytesPerFFToRead = n_bytes_received / n_ff_used;
uint8_t cnt_ff;
@@ -928,10 +927,7 @@ static uint16_t audiod_encode_type_I_pcm(uint8_t rhport, audiod_interface_t* aud
TU_VERIFY(!usbd_edpt_busy(rhport, audio->ep_in));
// Determine amount of samples
- uint8_t const n_ff_used = audio->n_channels_tx / audio->n_channels_per_ff_tx;
-
- TU_ASSERT( n_ff_used <= audio->n_tx_supp_ff );
-
+ uint8_t const n_ff_used = audio->n_ff_used_tx;
uint16_t const nBytesToCopy = audio->n_channels_per_ff_tx * audio->n_bytes_per_sampe_tx;
uint16_t const capPerFF = audio->ep_in_sz / n_ff_used; // Sample capacity per FIFO in bytes
uint16_t nBytesPerFFToSend = tu_fifo_count(&audio->tx_supp_ff[0]);
@@ -1551,6 +1547,8 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
{
tu_fifo_config(&audio->tx_supp_ff[cnt], audio->tx_supp_ff[cnt].buffer, active_fifo_depth, 1, true);
}
+ audio->n_ff_used_tx = audio->n_channels_tx / audio->n_channels_per_ff_tx;
+ TU_ASSERT( audio->n_ff_used_tx <= audio->n_tx_supp_ff );
#endif
#endif
@@ -1582,6 +1580,8 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
{
tu_fifo_config(&audio->rx_supp_ff[cnt], audio->rx_supp_ff[cnt].buffer, active_fifo_depth, 1, true);
}
+ audio->n_ff_used_rx = audio->n_channels_rx / audio->n_channels_per_ff_rx;
+ TU_ASSERT( audio->n_ff_used_rx <= audio->n_rx_supp_ff );
#endif
#endif
// Invoke callback
diff --git a/src/class/audio/audio_device.h b/src/class/audio/audio_device.h
index 81e0024d7..f91540b64 100644
--- a/src/class/audio/audio_device.h
+++ b/src/class/audio/audio_device.h
@@ -240,6 +240,9 @@
// Enable encoding/decodings - for these to work, support FIFOs need to be setup in appropriate numbers and size
// The actual coding parameters of active AS alternate interface is parsed from the descriptors
+// The item size of the FIFO is always fixed to one i.e. bytes! Furthermore, the actively used FIFO depth is reconfigured such that the depth is a multiple of the current sample size in order to avoid samples to get split up in case of a wrap in the FIFO ring buffer (depth = (max_depth / sampe_sz) * sampe_sz)!
+// This is important to remind in case you use DMAs! If the sample sizes changes, the DMA MUST BE RECONFIGURED just like the FIFOs for a different depth!!!
+
// For PCM encoding/decoding
#ifndef CFG_TUD_AUDIO_ENABLE_ENCODING