Creating a Library-Object

Status
Not open for further replies.

rootgordon

New member
Hello everyone,

I've been digging into the Audio-Library to create my own object to use with a teensy3.2 + Audio-Shield.

Naturally I'm running into problems, so I've gotten to the point where I've reduced my update function to the bare minimum:

AudioEffectDummy.cpp:
Code:
#include "AudioStream.h"
#include "AudioEffectDummy.h"
#include "spi_interrupt.h"

void AudioEffectDummy::update(void) {
audio_block_t *inBlock ;
inBlock = receiveReadOnly() ;
transmit(inBlock, 0) ;
release(inBlock) ;
}

AudioEffectDummy.h:
Code:
#include "AudioStream.h"

class AudioEffectDummy : public Audiostream{
public:
AudioEffectDummy() : AudioStream(3, inputQueueArray) ;
virtual void update (void) ;
private:
audio_block_t *inputQueueArray[3] ;
}
as a test-setup i'm running audio from my pc into line-in left, which should be played back on line-out left:

Code:
#include <Audio.h>
#include <wire.h>
#include <SPI.h>
#include <AudioEffectDummy.h>

AudioInputI2S linein ;
AudioOutputI2S lineout ;
AudioEffectDummy dummy ;

AudioConnection patchCord1(linein, 0, dummy, 0) ;
AudioConnection patchCord2(dummy, 0, lineout, 0) ;

AudioControlSGTL5000 audioShield ;
...

There's absolute silence on the output. As far as I can tell the teensy freezes (as there's no output at all on the serial console if I insert some Serial.prints. there's nothing wrong with the sketch since it's running fine if I exclude the audio-connections).

The shield works fine and is playing audio from example-projects.

I feel like there's a fundamental misunderstanding on my part on how the audio-library works.
 
Your AudioEffectDummy.cpp neglects to check whether inBlock is NULL. You *must* check this. You will sometimes get NULL, especially at startup. You will memory fault the CPU if you use a NULL pointer with transmit().

While I can't see your program's setup() function, another common mistake is forgetting to actually allocate any memory with AudioMemory(). If you've done that, then inBlock will *always* be NULL while the audio library tries to run without any memory to actually do anything.
 
Thank you! With
Code:
if ( inBlock ) {
transmit(inBlock, 0) ;
}

the sketch is running now, although the line-out remains silent. Here's my setup-function:
Code:
void setup() {
Serial.begin(9600);
AudioMemory(10);
audioShield.enable();
audioShield.volume(0.7);
audioShield.inputSelect(AUDIO_INPUT_LINEIN);
}

I've double-checked my wiring with the stereo-passthrough example to make sure the line-in is not the problem. What else am I missing?

Appreciate the help!
 
I feel mighty stupid. But I'll gladly share my stupidity. The sketch I'm working on runs on another tty, so copying everything manually to the forums I left out what I commented out over time. The essential thing I missed (while commenting stuff out) was I set the LED on pin 13 high, out of habit (as a "lifesign"). Pin 13 is of course used by the Audio-Shield, thus it didn't work.

My apologies, I'll be more thorough next time. And thanks again still, could've taken me quite some time longer to find this one.
 
Status
Not open for further replies.
Back
Top