summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinhard Panhuber <[email protected]>2021-02-18 19:25:08 +0100
committerReinhard Panhuber <[email protected]>2021-02-18 19:25:08 +0100
commitc098da9803a091c4b2402057ece370975850ef53 (patch)
tree22b41cf1e80255af565da60a0b86f883b642187e /src
parent681cfd0bf21cc0e977cb3e5294c7a1edbb4f0928 (diff)
Implement left and right justifications for 24 to 32 bit PCM encoding
Diffstat (limited to 'src')
-rw-r--r--src/class/audio/audio_device.c10
-rw-r--r--src/class/audio/audio_device.h12
2 files changed, 20 insertions, 2 deletions
diff --git a/src/class/audio/audio_device.c b/src/class/audio/audio_device.c
index 527aecc0d..c71ad6b8e 100644
--- a/src/class/audio/audio_device.c
+++ b/src/class/audio/audio_device.c
@@ -366,11 +366,15 @@ static bool audiod_decode_type_I_pcm(uint8_t rhport, audiod_interface_t* audio)
// If this aborts then the target buffer is full
TU_VERIFY(tu_fifo_read_n_into_other_fifo(&audio->ep_out_ff, &audio->rx_ff[cntChannel], 0, CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_RX));
#else
- // TODO: Implement a left and right justified 24 to 32 and vice versa copy process from FIFO to FIFO
uint32_t sample = 0;
// Get sample from buffer
TU_VERIFY(tu_fifo_read_n(&audio->ep_out_ff, &sample, CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_RX));
+
+#if CFG_TUD_AUDIO_JUSTIFICATION_RX == CFG_TUD_AUDIO_LEFT_JUSTIFIED
+ sample = sample << 8;
+#endif
+
TU_VERIFY(tu_fifo_write_n(&audio->rx_ff[cntChannel], &sample, CFG_TUD_AUDIO_RX_ITEMSIZE));
#endif
}
@@ -584,12 +588,14 @@ static bool audiod_encode_type_I_pcm(uint8_t rhport, audiod_interface_t* audio)
#if CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX == CFG_TUD_AUDIO_TX_ITEMSIZE
tu_fifo_read_n_into_other_fifo(&audio->tx_ff[cntChannel], &audio->ep_in_ff, 0, CFG_TUD_AUDIO_TX_ITEMSIZE);
#else
- // TODO: Implement a left and right justified 24 to 32 and vice versa copy process from FIFO to FIFO
uint32_t sample = 0;
// Get sample from buffer
tu_fifo_read_n(&audio->tx_ff[cntChannel], &sample, CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX);
+#if CFG_TUD_AUDIO_JUSTIFICATION_TX == CFG_TUD_AUDIO_LEFT_JUSTIFIED
+ sample = sample << 8;
+#endif
tu_fifo_write_n(&audio->ep_in_ff, &sample, CFG_TUD_AUDIO_TX_ITEMSIZE);
#endif
}
diff --git a/src/class/audio/audio_device.h b/src/class/audio/audio_device.h
index d1d1157eb..38495f72d 100644
--- a/src/class/audio/audio_device.h
+++ b/src/class/audio/audio_device.h
@@ -203,6 +203,18 @@
#endif
+// In case PCM encoding/decoding of 24 into 32 bits, the adjustment needs to be defined
+#define CFG_TUD_AUDIO_LEFT_JUSTIFIED
+#define CFG_TUD_AUDIO_RIGHT_JUSTIFIED
+
+#ifndef CFG_TUD_AUDIO_JUSTIFICATION_RX
+#define CFG_TUD_AUDIO_JUSTIFICATION_RX CFG_TUD_AUDIO_LEFT_JUSTIFIED
+#endif
+
+#ifndef CFG_TUD_AUDIO_JUSTIFICATION_TX
+#define CFG_TUD_AUDIO_JUSTIFICATION_TX CFG_TUD_AUDIO_LEFT_JUSTIFIED
+#endif
+
//static_assert(sizeof(tud_audio_desc_lengths) != CFG_TUD_AUDIO, "Supply audio function descriptor pack length!");
// Supported types of this driver: