AudioStream example fails to compile

Status
Not open for further replies.

Demolishun

Well-known member
I am trying to compile the simple class definition described on this page:
https://www.pjrc.com/teensy/td_libs_AudioNewObjects.html

It will not compile. I get this (verbose turned on):
Code:
C:\Arduino-1.0.5\hardware\tools\arm-none-eabi\bin\arm-none-eabi-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mcpu=cortex-m4 -DF_CPU=96000000 -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -mthumb -nostdlib -D__MK20DX256__ -DTEENSYDUINO=118 -fno-rtti -felide-constructors -std=gnu++0x -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Arduino-1.0.5\hardware\teensy\cores\teensy3 C:\Users\DEMOLI~1\AppData\Local\Temp\build4180167903440885784.tmp\teensystim1.cpp -o C:\Users\DEMOLI~1\AppData\Local\Temp\build4180167903440885784.tmp\teensystim1.cpp.o 
teensystim1.ino: In constructor 'AudioOutputPFM::AudioOutputPFM()':
teensystim1:20: error: expected '{' at end of input

One thing I do not understand is IF I should download the audio library from Github or WHERE to install that library if I do. I did update the cores files for Teensy3.1 though. So all of those files should be the latest, but I get the same error. I look at the AudioStream file and I don't see any obvious syntax errors. The arm compiler and the like might be a bit older like a couple/three months old.

Edit:
Sorry, I am attempting this:
Code:
#include "AudioStream.h"

class AudioEffectTemplate : public AudioStream
{
public:
        AudioEffectTemplate() : AudioStream(1, inputQueueArray);
        virtual void update(void);
private:
        audio_block_t *inputQueueArray[1];
};
Mine looks like this:
Code:
#include "AudioStream.h"
class AudioOutputPFM : public AudioStream
{
  private:
    audio_block_t *inputQueueArray[1];
    
  public:
    AudioOutputPFM() : AudioStream(1, inputQueueArray);
    virtual void update(void);
};
 
Last edited:
You need to download the Audio Library from somewhere (best place is Paul's github) and put it in your ./arduino-1.0.5-r2/libraries folder - once you do that (and you completely close all instances of Arduino, then re-open at least one) your code has a better chance of compiling but as you have only shown snippets (or at least, what you posted does not complete an object) I cannot make any firm statement as to whether I think it will completely compile or still might contain un-compilable errors.
 
Code:
/* 
Purpose: Convert audio input to PFM to drive transformer.
Platform: Teensy 3.1
*/
#include "AudioStream.h"

const int leftOutPin =  3;
const int rightOutPin =  5;
const int leftInPin =  14;
const int rightInPin =  15;

// audio objects
class AudioOutputPFM : public AudioStream
{
  private:
    audio_block_t *inputQueueArray[1];
    
  public:
    AudioOutputPFM() : AudioStream(1, inputQueueArray);
    virtual void update(void);
};

void AudioOutputPFM::update(void) {
}

void setup()   {  
  
}

void loop()                     
{
  
}

I downloaded the Audio library and placed it in the "C:\Users\demolishun\Documents\Arduino\libraries" location. I then explicitly tried to include the file and it gave me an SD.h include missing error. This told me two things: AudioStream.h does not include Audio.h, and I need another library for Audio.h. However, the example on the page I linked to originally never required to include Audio.h. So that brings me back to square one. Why will it not compile?

I have compiled the "blink" example and ran it. So I think the compiler is setup okay. Also, I just downloaded the 1.1.9 version of the addon for 1.0.5 of the Arduino software. I am getting the same error.
 
Here is the revised code:
Code:
/* 
Purpose: Convert audio input to PFM to drive transformer.
Platform: Teensy 3.1
*/
#include <SD.h>
#include <Audio.h>
#include "AudioStream.h"

const int leftOutPin =  3;
const int rightOutPin =  5;
const int leftInPin =  14;
const int rightInPin =  15;

// audio objects 
class AudioOutputPFM : public AudioStream
{
  private:
    audio_block_t *inputQueueArray[1];
    
  public:
    AudioOutputPFM() : AudioStream(1, inputQueueArray);
    virtual void update(void);
};

void AudioOutputPFM::update(void) {
}

void setup()   {  
  
}

void loop()                     
{
  
}

I found the SD library at Adafruit:
https://github.com/adafruit/SD

It is not not throwing errors for the compilation of Audio.h, but it still has the original error.

This is the Audio lib I added as well:
https://github.com/PaulStoffregen/Audio

Just so there is no confusion as to what I trying to use.
 
Okay, I added the code braces in the initializer definition:
Code:
AudioOutputPFM() : AudioStream(1, inputQueueArray);

This allows me to go further, but now I am getting this strange error:
Code:
C:\Arduino-1.0.5\hardware\teensy\cores\teensy3\yield.cpp: In function 'void yield()':
C:\Arduino-1.0.5\hardware\teensy\cores\teensy3\yield.cpp:43:38: error: 'serialEvent' was not declared in this scope
C:\Arduino-1.0.5\hardware\teensy\cores\teensy3\yield.cpp:44:40: error: 'serialEvent1' was not declared in this scope
C:\Arduino-1.0.5\hardware\teensy\cores\teensy3\yield.cpp:45:40: error: 'serialEvent2' was not declared in this scope
C:\Arduino-1.0.5\hardware\teensy\cores\teensy3\yield.cpp:46:40: error: 'serialEvent3' was not declared in this scope

Which I now get for my blink example as well. So I need to regress to 1.1.8. Be back...
 
if you get a 'vanilla' copy of arduino-1.0.5-r2 unpacked somewhere on your hard drive, run the latest teensyduino installer using that as the target, and put the Audio Library in place the examples for the Audio Library (File->Examples->Audio->*) should all compile and for this reason I do not know why you grabbed the adafruit SD library.

Once those audio examples in the library are compiling on your PC and the resultant code does what it should on Teensy 3.x you will get to see if your object compiles and if your tester sketch compiles; any errors left over should be your own but I cannot guarantee that.
 
I just removed the Adafruit SD.h and tried compiling with the #include <SD.h> and it worked that far. I didn't understand before that the libraries don't seem to find the libraries without explicit #include in the main file. Usually the files are found according to an include path.

Right now I am fighting installing 1.1.9 as I think it has produced the new errors with Yield. I tried going back to 1.1.8, but that did not regress the change. So I am downloading the unzippable version of 1.0.5 r2 even though I had r2 installed already. However, Arduino is stupid and tries to require me to uninstall my 1.5.x version that I need for my Yun. So I am going to install 1.0.5 r2 and install the 1.1.8 version of the Teensy 3.1 stuff. Again, my Blink program worked before until I messed with the installed version of Teensy 3.1 libraries. Compiling that gives me that yield error on compile.

Also, for the original problem I should not be trying to mess with Audio.h as it is not a dependency of AudioStream.h which is part of main distribution and is not in the audio lib.
 
I have not experienced any trouble with having multiple copies of Arduino in a single system, they even run (just like some text on https://www.pjrc.com/teensy/td_download.html says they will) simultaneously without interfering with each other so I do not know why your copy of Arduino is behaving differently from mine - are you making shortcuts/soft-links to the main binary/executable in (each of) the arduino-1.0.5-r2 folder(s) ?

When you say 1.1.9 and 1.1.8 I assume you mean Teensyduino 1.18 and 1.19 - 1.19 should be all improvement over 1.18 so if you've found something that isn't an improvement and you can prove it so you would be doing Paul (and us) a favour by pointing out how it fails with a relevant thread inclusive of an example sketch which highlights the failure.

To use AudioStream as you seem to want to I am going to suggest that you have a good look at how the Audio Library uses it.
 
The windows exe installer versions seem to want to grab onto the last version installed and tell you that you cannot install a new version until that one is removed. So I am downloading the zipped version. I tried unzipping the installer, but it does not contain the proper files to run when I do that. It is the lame Windows installer that is the issue. Right now I have 3 versions installed, plus a version for Uno32. I ran into this issue with installing 1.5.x of the Arduino software. Last time the fix was the rename the directory and tell it to remove it from the uninstall program.

Anyway, there is no issue to having multiple versions except for the stupid Windows installer itself. They are not interfering except with the installer making assumptions.

Yes, i mean 1.18 and 1.19. I am going to install two new copies of 1.0.5 r2 and put 1.18 on one and 1.19 on the other and test. When I finish I will post my results.
 
Test code:
Code:
/* 
Purpose: Convert audio input to PFM to drive transformer.
Platform: Teensy 3.1
*/
#include <SD.h>
#include <Wire.h>
#include <Audio.h>
#include "AudioStream.h"

const int leftOutPin =  3;
const int rightOutPin =  5;
const int leftInPin =  14;
const int rightInPin =  15;

// audio objects 
class AudioOutputPFM : public AudioStream
{
  private:
    audio_block_t *inputQueueArray[1];
    
  public:
    AudioOutputPFM() : AudioStream(1, inputQueueArray){};
    virtual void update(void);
};

void AudioOutputPFM::update(void) {
}


void setup()   {  
  
}

void loop()                     
{
  
}

Attempt: Installation of Arduino 1.0.5 r2 with 1.18.
Result: Compiles code and finishes compile.

Attempt: Installation of Arduino 1.0.5 r2 with 1.19.
Result: Compiles code and finishes compile.

Attempt: Next I looked at the original installation (Arduino 1.0.5 r2) and deleted the \Arduino-1.0.5\hardware\teensy directory. Then installed 1.19.
Result: Compiles code and finishes compile.

What I learned:
1. Do not install a version of the Teensy code over another version of Teensy code. Example: Do not install 1.19 over 1.18.
2. When a library is missing a lib then specifying the lib explicitly in the .ino file will help it find that header/lib. This is so different from VC++ and gcc under Linux it just messes with my head! LOL
3. The example object on the https://www.pjrc.com/teensy/td_libs_AudioNewObjects.html page is missing two braces at the end of the constructor statement for the object.
Code:
AudioOutputPFM() : AudioStream(1, inputQueueArray);
Should be:
AudioOutputPFM() : AudioStream(1, inputQueueArray){};

robsoles,
Thank you for helping me figure this out. It just seemed like error on top of errors as I compounded the issue. With your help I was able to install the Audio.h lib and get it running and troubleshoot my installation. Killed a bunch of birds in this thread. Thanks!

Cheers!
 
Even though this thread talks only about versions 1.18 and 1.19, those serialEvent errors suggest version 1.20-rc1 must have been introduced into the mix at some point. 1.18 and 1.19 simply don't have the serialEvent stuff.

I generally build the installers so you can "install on top" to upgrade a from prior version. In other words, if you have 1.0.5 with Teensyduino 1.19, you can run the 1.20-rc1 installer to upgrade it to 1.20-rc1.

However, downgrading is never a good idea. My guess is your copy of Arduino had 1.20-rc1 at some point, then you ran the 1.18 or 1.19 installer to downgrade it back to 1.18 or 1.19. The installers simply aren't designed for downgrading. I believe I had to add a new file in 1.20-rc1 for the yield & serialEvent stuff, which the 1.18 and 1.19 installers do not know needs to be deleted, so your copy of Arduino probably has an inconsistent mix of 1.19 and 1.20-rc1 code, which results in that error. The 1.18 and 1.19 installers don't know how to remove new files that later installers may add, so running an older installer on a copy of Arduino with a newer version can leave you with a broken install. I'm pretty sure that's what's happened here.

To downgrade, extract the Arduino 1.0.5 zip file, so you have a fresh copy of Arduino, and of course make a reliable mental note of its location, so you can choose the right copy while running the installer. Then run the Teensyduino installer you want. You can have as many copies of Arduino as you like (hard drive space permitting). They all share the same preferences and sketchbook folder, but each is a separate copy. The Teensyduino installer only modifies the copy you select.

Once you get a good copy of Arduino with Teensyduino 1.19, you'll need the audio library. You can install it in Documents\Arduino\libraries to make it available to all copies of Arduino (they all share this sketchbook folder), or you can extract it within the "libraries" folder of Arduino, to make it available to only that 1 copy. Doing both is not a good idea and likely to lead to a lot of confusion.

AudioStream in the core library isn't meant to be used without the audio library. Of course, you can, but it's really only useful for building an audio library. You could use it to build your own library which interacts with the audio library objects. In fact, that's the reason it's in the core library. Someday USB audio will added to the core library, so the stuff which is needed to be shared, so objects entirely in the USB stack in the core library will be able to interoperate with the audio library, because they're able to share the AudioStream base class.

Even if this is your intention, I'd highly recommend getting a stable copy of Arduino. First make sure you can at least compile and upload simple stuff, like the LED blink. Before digging into AudioStream, at least try some of the audio library examples like PlayFromSketch. Admittedly, some examples in the Audio library are broken or in need of updates, so don't expect everything to work flawlessly (it's still considered "beta" for a reason).
 
Yeah, I had LED blinking originally. Before I started messing with stuff.

I think you are right. I forgot that I had downloaded the core files off Github and copied them over the installed core files for 1.18. Doh! I think that is where things got weird. Thanks for pointing that out.

Yep I understood that AudioStream was not stand alone, I was just lost as to why it would not compile. My C++ is rusty and I did not catch the constructor error.
 
Status
Not open for further replies.
Back
Top