Skip to content

Commit

Permalink
More robust audio input handling code in Teensy.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Nov 9, 2020
1 parent 37a741d commit cbfe606
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
15 changes: 10 additions & 5 deletions architecture/faust/audio/teensy-dsp.h
Expand Up @@ -27,6 +27,7 @@

#include <set>
#include <utility>
#include <string.h> // for memset

#include "faust/dsp/dsp.h"

Expand Down Expand Up @@ -68,13 +69,17 @@ class teensyaudio : public AudioStream, public audio {
{
if (INPUTS > 0) {
audio_block_t* inBlock[INPUTS];
for(int channel = 0; channel < INPUTS; channel++) {
for (int channel = 0; channel < INPUTS; channel++) {
inBlock[channel] = receiveReadOnly(channel);
for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
int32_t val = inBlock[channel]->data[i] << 16;
fInChannel[channel][i] = val*DIV_16;
if (inBlock) {
for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
int32_t val = inBlock[channel]->data[i] << 16;
fInChannel[channel][i] = val*DIV_16;
}
release(inBlock[channel]);
} else {
memset(fInChannel[channel], 0, AUDIO_BLOCK_SAMPLES * sizeof(float));
}
release(inBlock[channel]);
}
}

Expand Down
14 changes: 10 additions & 4 deletions architecture/teensy/teensy.cpp
Expand Up @@ -33,6 +33,8 @@
************************************************************************
************************************************************************/

#include <string.h> // for memset

#include "teensy.h"

// IMPORTANT: in order for MapUI to work, the teensy linker must be g++
Expand Down Expand Up @@ -172,11 +174,15 @@ void AudioFaust::updateImp(void)
audio_block_t* inBlock[INPUTS];
for (int channel = 0; channel < INPUTS; channel++) {
inBlock[channel] = receiveReadOnly(channel);
for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
int32_t val = inBlock[channel]->data[i] << 16;
fInChannel[channel][i] = val*DIV_16;
if (inBlock) {
for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
int32_t val = inBlock[channel]->data[i] << 16;
fInChannel[channel][i] = val*DIV_16;
}
release(inBlock[channel]);
} else {
memset(fInChannel[channel], 0, AUDIO_BLOCK_SAMPLES * sizeof(float));
}
release(inBlock[channel]);
}
}

Expand Down

0 comments on commit cbfe606

Please sign in to comment.