Преглед на файлове

Improve usb audio transmit startup, fixes Mac issues

teensy4-core
PaulStoffregen преди 8 години
родител
ревизия
98fdbc89ae
променени са 3 файла, в които са добавени 17 реда и са изтрити 35 реда
  1. +6
    -33
      teensy3/usb_audio.cpp
  2. +0
    -2
      teensy3/usb_audio.h
  3. +11
    -0
      teensy3/usb_dev.c

+ 6
- 33
teensy3/usb_audio.cpp Целия файл

@@ -203,13 +203,11 @@ void AudioInputUSB::update(void)


bool AudioOutputUSB::update_responsibility;
bool AudioOutputUSB::transmitting;
audio_block_t * AudioOutputUSB::left_1st;
audio_block_t * AudioOutputUSB::left_2nd;
audio_block_t * AudioOutputUSB::right_1st;
audio_block_t * AudioOutputUSB::right_2nd;
uint16_t AudioOutputUSB::offset_1st;
uint16_t AudioOutputUSB::outgoing_count;


uint16_t usb_audio_transmit_buffer[AUDIO_TX_SIZE/2] DMABUFATTR;
@@ -218,7 +216,6 @@ uint8_t usb_audio_transmit_setting=0;
void AudioOutputUSB::begin(void)
{
update_responsibility = false;
transmitting = false;
left_1st = NULL;
right_1st = NULL;
}
@@ -241,14 +238,11 @@ void AudioOutputUSB::update(void)
if (usb_audio_transmit_setting == 0) {
if (left) release(left);
if (right) release(right);
if (outgoing_count) {
if (left_1st) release(left_1st);
if (left_2nd) release(left_2nd);
if (right_1st) release(right_1st);
if (right_2nd) release(right_2nd);
outgoing_count = 0;
offset_1st = 0;
}
if (left_1st) release(left_1st);
if (left_2nd) release(left_2nd);
if (right_1st) release(right_1st);
if (right_2nd) release(right_2nd);
offset_1st = 0;
return;
}
if (left == NULL) {
@@ -260,27 +254,13 @@ void AudioOutputUSB::update(void)
right = left;
}
__disable_irq();
if (!transmitting) {
copy_from_buffers((uint32_t *)usb_audio_transmit_buffer,
left->data, right->data, 44);
left_1st = left;
right_1st = right;
left_2nd = NULL;
right_2nd = NULL;
offset_1st = 44;
outgoing_count = AUDIO_BLOCK_SAMPLES - 44;
usb_tx_isochronous(AUDIO_TX_ENDPOINT, usb_audio_transmit_buffer, 176);
transmitting = 1;
//serial_print("t");
} else if (left_1st == NULL) {
if (left_1st == NULL) {
left_1st = left;
right_1st = right;
offset_1st = 0;
outgoing_count = AUDIO_BLOCK_SAMPLES;
} else if (left_2nd == NULL) {
left_2nd = left;
right_2nd = right;
outgoing_count += AUDIO_BLOCK_SAMPLES;
} else {
// buffer overrun - PC is consuming too slowly
audio_block_t *discard1 = left_1st;
@@ -290,7 +270,6 @@ void AudioOutputUSB::update(void)
right_1st = right_2nd;
right_2nd = right;
offset_1st = 0; // TODO: discard part of this data?
outgoing_count = AUDIO_BLOCK_SAMPLES*2;
//serial_print("*");
release(discard1);
release(discard2);
@@ -309,12 +288,6 @@ unsigned int usb_audio_transmit_callback(void)
uint32_t avail, num, target, offset, len=0;
audio_block_t *left, *right;

if (usb_audio_transmit_setting == 0) {
AudioOutputUSB::transmitting = 0;
return 0;
}
//serial_print(".");

if (++count < 9) { // TODO: dynamic adjust to match USB rate
target = 44;
} else {

+ 0
- 2
teensy3/usb_audio.h Целия файл

@@ -44,14 +44,12 @@ public:
void begin(void);
friend unsigned int usb_audio_transmit_callback(void);
private:
static bool transmitting;
static bool update_responsibility;
static audio_block_t *left_1st;
static audio_block_t *left_2nd;
static audio_block_t *right_1st;
static audio_block_t *right_2nd;
static uint16_t offset_1st;
static uint16_t outgoing_count;
audio_block_t *inputQueueArray[2];
};


+ 11
- 0
teensy3/usb_dev.c Целия файл

@@ -385,6 +385,17 @@ static void usb_setup(void)
case 0x0B01: // SET_INTERFACE (alternate setting)
if (setup.wIndex == AUDIO_INTERFACE+1) {
usb_audio_transmit_setting = setup.wValue;
if (usb_audio_transmit_setting > 0) {
bdt_t *b = &table[index(AUDIO_TX_ENDPOINT, TX, EVEN)];
uint8_t state = tx_state[AUDIO_TX_ENDPOINT-1];
if (state) b++;
if (!(b->desc & BDT_OWN)) {
memset(usb_audio_transmit_buffer, 0, 176);
b->addr = usb_audio_transmit_buffer;
b->desc = (176 << 16) | BDT_OWN;
tx_state[AUDIO_TX_ENDPOINT-1] = state ^ 1;
}
}
} else if (setup.wIndex == AUDIO_INTERFACE+2) {
usb_audio_receive_setting = setup.wValue;
} else {

Loading…
Отказ
Запис