|
|
|
|
|
|
|
|
// we only get to this point when buffer[512] is empty |
|
|
// we only get to this point when buffer[512] is empty |
|
|
if (state != STATE_STOP && wavfile.available()) { |
|
|
if (state != STATE_STOP && wavfile.available()) { |
|
|
// we can read more data from the file... |
|
|
// we can read more data from the file... |
|
|
|
|
|
readagain: |
|
|
buffer_length = wavfile.read(buffer, 512); |
|
|
buffer_length = wavfile.read(buffer, 512); |
|
|
if (buffer_length == 0) goto end; |
|
|
if (buffer_length == 0) goto end; |
|
|
buffer_offset = 0; |
|
|
buffer_offset = 0; |
|
|
|
|
|
bool parsing = (state >= 8); |
|
|
bool txok = consume(buffer_length); |
|
|
bool txok = consume(buffer_length); |
|
|
if (txok) { |
|
|
if (txok) { |
|
|
if (state != STATE_STOP) return; |
|
|
if (state != STATE_STOP) return; |
|
|
} else { |
|
|
} else { |
|
|
if (state != STATE_STOP) goto cleanup; |
|
|
|
|
|
|
|
|
if (state != STATE_STOP) { |
|
|
|
|
|
if (parsing && state < 8) goto readagain; |
|
|
|
|
|
else goto cleanup; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
end: // end of file reached or other reason to stop |
|
|
end: // end of file reached or other reason to stop |
|
|
|
|
|
|
|
|
cleanup: |
|
|
cleanup: |
|
|
if (block_left) { |
|
|
if (block_left) { |
|
|
if (block_offset > 0) { |
|
|
if (block_offset > 0) { |
|
|
while (block_offset < AUDIO_BLOCK_SAMPLES) { |
|
|
|
|
|
block_left->data[block_offset++] = 0; |
|
|
|
|
|
|
|
|
for (uint32_t i=block_offset; i < AUDIO_BLOCK_SAMPLES; i++) { |
|
|
|
|
|
block_left->data[i] = 0; |
|
|
} |
|
|
} |
|
|
transmit(block_left, 0); |
|
|
transmit(block_left, 0); |
|
|
if (state < 8 && (state & 1) == 0) { |
|
|
if (state < 8 && (state & 1) == 0) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
if (block_right) { |
|
|
if (block_right) { |
|
|
if (block_offset > 0) { |
|
|
if (block_offset > 0) { |
|
|
while (block_offset < AUDIO_BLOCK_SAMPLES) { |
|
|
|
|
|
block_right->data[block_offset++] = 0; |
|
|
|
|
|
|
|
|
for (uint32_t i=block_offset; i < AUDIO_BLOCK_SAMPLES; i++) { |
|
|
|
|
|
block_right->data[i] = 0; |
|
|
} |
|
|
} |
|
|
transmit(block_right, 1); |
|
|
transmit(block_right, 1); |
|
|
} |
|
|
} |