Skip to content

Commit 067fe9b

Browse files
authored
Merge pull request #3848 from jamike/USBAUDIO_JITTER
USBAudio: writesync with 1 sample jitter capability.
2 parents b9bc2c0 + 5913cf3 commit 067fe9b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

features/unsupported/USBDevice/USBAudio/USBAudio.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,13 @@ bool USBAudio::write(uint8_t * buf) {
113113
return true;
114114
}
115115

116-
void USBAudio::writeSync(uint8_t *buf)
116+
void USBAudio::writeSync(uint8_t *buf, AudioSampleCorrectType jitter_nb)
117117
{
118-
USBDevice::writeNB(EPISO_IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
118+
if ((jitter_nb != RemoveOneSample) && (jitter_nb != AddOneSample)) {
119+
jitter_nb = NoCorrection;
120+
}
121+
/* each sample is 2 bytes */
122+
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);
119123
}
120124

121125
uint32_t USBAudio::readSync(uint8_t *buf)
@@ -195,7 +199,7 @@ bool USBAudio::USBCallback_setConfiguration(uint8_t configuration) {
195199

196200
// Configure isochronous endpoint
197201
realiseEndpoint(EPISO_OUT, PACKET_SIZE_ISO_IN, ISOCHRONOUS);
198-
realiseEndpoint(EPISO_IN, PACKET_SIZE_ISO_OUT, ISOCHRONOUS);
202+
realiseEndpoint(EPISO_IN, PACKET_SIZE_ISO_OUT+this->channel_nb_out*2, ISOCHRONOUS);
199203

200204
// activate readings on this endpoint
201205
readStart(EPISO_OUT, PACKET_SIZE_ISO_IN);
@@ -597,8 +601,8 @@ uint8_t * USBAudio::configurationDesc() {
597601
ENDPOINT_DESCRIPTOR, // bDescriptorType
598602
PHY_TO_DESC(EPISO_IN), // bEndpointAddress
599603
E_ISOCHRONOUS, // bmAttributes
600-
(uint8_t)(LSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize
601-
(uint8_t)(MSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize
604+
(uint8_t)(LSB(PACKET_SIZE_ISO_OUT+channel_nb_out*2)), // wMaxPacketSize
605+
(uint8_t)(MSB(PACKET_SIZE_ISO_OUT+channel_nb_out*2)), // wMaxPacketSize
602606
0x01, // bInterval
603607
0x00, // bRefresh
604608
0x00, // bSynchAddress

features/unsupported/USBDevice/USBAudio/USBAudio.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,18 @@ class USBAudio: public USBDevice {
123123
*/
124124
bool write(uint8_t * buf);
125125

126+
/** Audio Jitter value*/
127+
enum AudioSampleCorrectType {
128+
RemoveOneSample = -1,
129+
NoCorrection = 0,
130+
AddOneSample = 1
131+
};
126132
/**
127133
* Write packet in endpoint fifo. assuming tx fifo is empty
128134
* @param buf pointer on the audio packet which will be sent
129-
*/
130-
void writeSync(uint8_t *buf);
135+
* @param jitter_nb : AudioSampleCorrecttype
136+
**/
137+
void writeSync(uint8_t *buf, AudioSampleCorrectType jitter_nb = NoCorrection );
131138

132139
/**
133140
* Write and read an audio packet at the same time (on the same frame)

0 commit comments

Comments
 (0)