diff --git a/features/unsupported/USBDevice/USBAudio/USBAudio.cpp b/features/unsupported/USBDevice/USBAudio/USBAudio.cpp index c8e07ba3b1..fba5ead9d6 100644 --- a/features/unsupported/USBDevice/USBAudio/USBAudio.cpp +++ b/features/unsupported/USBDevice/USBAudio/USBAudio.cpp @@ -113,9 +113,13 @@ bool USBAudio::write(uint8_t * buf) { return true; } -void USBAudio::writeSync(uint8_t *buf) +void USBAudio::writeSync(uint8_t *buf, AudioSampleCorrectType jitter_nb) { - USBDevice::writeNB(EPISO_IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT); + if ((jitter_nb != RemoveOneSample) && (jitter_nb != AddOneSample)) { + jitter_nb = NoCorrection; + } + /* each sample is 2 bytes */ + USBDevice::writeNB(EPISO_IN, buf, PACKET_SIZE_ISO_OUT + jitter_nb *(this->channel_nb_out*2), PACKET_SIZE_ISO_OUT+this->channel_nb_out*2); } uint32_t USBAudio::readSync(uint8_t *buf) @@ -195,7 +199,7 @@ bool USBAudio::USBCallback_setConfiguration(uint8_t configuration) { // Configure isochronous endpoint realiseEndpoint(EPISO_OUT, PACKET_SIZE_ISO_IN, ISOCHRONOUS); - realiseEndpoint(EPISO_IN, PACKET_SIZE_ISO_OUT, ISOCHRONOUS); + realiseEndpoint(EPISO_IN, PACKET_SIZE_ISO_OUT+this->channel_nb_out*2, ISOCHRONOUS); // activate readings on this endpoint readStart(EPISO_OUT, PACKET_SIZE_ISO_IN); @@ -597,8 +601,8 @@ uint8_t * USBAudio::configurationDesc() { ENDPOINT_DESCRIPTOR, // bDescriptorType PHY_TO_DESC(EPISO_IN), // bEndpointAddress E_ISOCHRONOUS, // bmAttributes - (uint8_t)(LSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize - (uint8_t)(MSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize + (uint8_t)(LSB(PACKET_SIZE_ISO_OUT+channel_nb_out*2)), // wMaxPacketSize + (uint8_t)(MSB(PACKET_SIZE_ISO_OUT+channel_nb_out*2)), // wMaxPacketSize 0x01, // bInterval 0x00, // bRefresh 0x00, // bSynchAddress diff --git a/features/unsupported/USBDevice/USBAudio/USBAudio.h b/features/unsupported/USBDevice/USBAudio/USBAudio.h index b1f9755918..14ee29125b 100644 --- a/features/unsupported/USBDevice/USBAudio/USBAudio.h +++ b/features/unsupported/USBDevice/USBAudio/USBAudio.h @@ -123,11 +123,18 @@ public: */ bool write(uint8_t * buf); + /** Audio Jitter value*/ + enum AudioSampleCorrectType { + RemoveOneSample = -1, + NoCorrection = 0, + AddOneSample = 1 + }; /** * Write packet in endpoint fifo. assuming tx fifo is empty * @param buf pointer on the audio packet which will be sent - */ - void writeSync(uint8_t *buf); + * @param jitter_nb : AudioSampleCorrecttype + **/ + void writeSync(uint8_t *buf, AudioSampleCorrectType jitter_nb = NoCorrection ); /** * Write and read an audio packet at the same time (on the same frame)