Audio Library Tutorial ?

Status
Not open for further replies.

heliboy

Active member
I have been attempting to use the Audio Library. It looks very powerful but I have been unable to use it. The link off the website opens a design window and I can pick and place objects but there is no way to connect them that I can figure out ? The offline tool is apparently in the audio.zip distribution but I cannot find it. Are there any instructions available of how to use the audio library ? Also, does the tone() function work on the teensy 3.1 on the DAC output ?

Any help appreciated. I have the audio shield but I really would prefer to use the teensy 3.1 ADC and DAC alone.
 
You connect the objects by clicking on the output of one and dragging to the input of another. Also, whenever you select an object, documentation for it appears over on the right hand side. Take the time to read it and scroll down to read more. There are also tooltips on the objects.

The offline tool is in gui/index.html but some strange security restrictions with file:/// urls mean that it does not work offline in chrome or internet explorer. It works offline in firefox, and works online in all browsers.

There isn't a step by step tutorial. Your best bet is to study the examples. Unfortunately its not possible to import examples into the gui and modify them, which would probably be a useful feature.

tone() is a separate thing, you can't integrate it into the audio library. But nor is it needed, because the waveform object does the same thing.

You can use the gui to make sketches that only use the onboard adc and dac objects.
 
I cannot connect anything to anything in IE online. All I get is a cross hair and I can move the objects all around to no avail.
 
Make sure the window of the editing field is not completely scrolled to the top.
I have the same, when the scrollbar is all the way to the top the contents disappears. Just one pixel below that (or more) everything is fine.
I am on OpenSuse 13.2 Firefox 34.0.5
Edit: The problem is not present in Chrome 28.0.1500.45
Edit 2: I had a look at the gui source code. At first glance the scrollbar/scaling code seems ok, so maybe a bug in firefox?
 
Last edited:
For whatever reason it works on another computer. Thanks for help. Last issue - how do you delete a connection or an element ? How do you clear the whole thing ?
 
So I tested it at my work computer:
Opensuse 13.1, Firefox 35.0 Works, When downgrading to 34.0.5, it fails. So definitely a firefox bug.
 
Delete a connection or an object by selecting it, then using the delete key. Drag-selecting a bunch of items hilights them, but delete does not delete them, oddly.
 
No> Does not work for me. Cannot seem to get this to work for me. Really frustrated with the audio library and 3.1 in general. I can't even get the example SamplePlayer to work anymore. I get a message Error Communicating with Teensy loader - SamplePlayer.cpp not found. What gives ? I can upload Blink fine so the 3.1 is working and the connection is working. Redownloaded the library - No difference.

I have bought over 100 teensy 2.0 and I use them in a commercial application. Love them. But for this poject I heeded better audio and FFT but just cannot get the 3.1 to work reliably. I think I will have to give up on this.
 
Is this a Windows machine? Sounds like things are really messed up. Maybe try on a different computer?

Teensy Loader has a Help > Verbose Info window, which can show you much more detail on what it's doing... as least from its point of view. But if the Windows machine has some sort of malware or other junk interfering with your browser and other stuff, there may not be much Teensy Loader or anything else can do.
 
Thanks. I will check - but it uploads other porgrams on the audio library distribution fine. For example - ToneSweep works OK - I get sound out of the headphone jack. Same with pulseWidth. Sound out of headphone jack and lineout. But no joy with uploading SamplePlayer. Same error as before - Error Communicating with Teensy loader - SamplePlayer.cpp not found- . Weird. Same PC - same 3.1, all three programs compiled from the audio library and uploaded within 2 minutes.
 
SamplePlayer.cpp needs buttons connected to the right pins in order to work... if you dont have buttons,you could re-write it to trigger the sounds in a loop by replacing the void loop with

Code:
void loop() {

     sound0.play(AudioSampleSnare);
     delay(1000);
     sound1.play(AudioSampleTomtom);
     delay(1000);
     sound2.play(AudioSampleHihat);
     delay(1000);
     sound3.play(AudioSampleKick);
     delay(1000);
     sound4.play(AudioSampleGong);
     delay(1000);
     sound5.play(AudioSampleCashregister);

}

this is a pretty cool loop actually :D kind of pink floyd's money with a GONGGG
 
I may be one of the few other folks on Windows - and I've had various issues - but uploading to my Teensy 3.1's has not been one of them.

I've spent days trying to compile AUDIO code [Arduino barfing on my Sketchbook placement] so this is a great thing. I just opened and uploaded the SamplePlayer sketch with no issues to a bare Teensy. Very boring though with no blink and no USB output with no Audio hardware or buttons.

I just made the FFT sample more compelling and informative (to me). I vary the sinewave frequency so you can see the shift through the FFT buckets, and the sample transition changes as well. To see more I threw away the float ("0.") and went to integers showing the hundredths value measured. View attachment T_FFT_SINEWAVE.ino

FFT: 6 7 8 15 23 23 15 6 3 2 2 1 1 1 1 - - - - - - - - - - - - - - - - - - - - -
FFT: - - - 5 37 45 12 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FFT: - - - 5 37 45 12 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FFT: - - - 5 37 45 12 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FFT: - - - 5 37 45 12 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FFT: - - - 5 37 45 12 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FFT: 2 3 4 11 21 25 21 15 21 25 20 10 3 2 1 1 1 - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - 1 14 46 34 3 - - - - - - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - 1 14 46 34 3 - - - - - - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - 1 14 46 34 3 - - - - - - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - 1 14 46 34 3 - - - - - - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - 1 14 46 34 3 - - - - - - - - - - - - - - - - - - - - - - - -
FFT: - - - - 1 1 2 5 14 23 25 18 17 24 24 16 7 2 2 1 1 - - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - 27 48 21 - - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - 27 48 21 - - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - 27 48 21 - - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - 27 48 21 - - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - 27 48 21 - - - - - - - - - - - - - - - - - - - -
FFT: - - - - - - - 1 1 1 2 3 8 18 24 23 16 19 25 22 13 5 2 1 1 1 - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - 1 6 39 43 10 1 - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - 1 6 39 43 10 1 - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - 1 6 39 43 10 1 - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - 1 6 39 43 10 1 - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - 1 6 39 43 10 1 - - - - - - - - - - - - - -
FFT: - - - - - - - - - - - - - 1 1 2 4 11 21 25 20 15 22 25 19 9 3 2 1 1 - - - - - -
FFT: - - - - - - - - - - - - - - - - - - - - - 1 17 47 32 2 - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - - - - - - 1 16 47 32 2 - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - - - - - - 1 17 47 32 2 - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - - - - - - 1 17 47 32 2 - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - - - - - - 1 16 47 32 2 - - - - - - - - - -
FFT: - - - - - - - - - - - - - - - - - 1 1 2 2 6 15 23 24 17 17 24 24 16 6 2 2 1 1 -
 
Thanks to all the help on this. From everyones input I had to believe it was some dumb Windows problem. So I got a good nights sleep - took the PC down - removed power, batteries, scrubbed with spybot and voila - sampleplayer runs again. Now onto figuring out the audio library tool. I need to process an analog signal to band pass between 1 and 10 Hz. Then FFT to get the two dominant frequencies. One should be about 0.25Hz, the other around 1.25 Hz. I guess I could forego the FFT and just figure out the periods by timing the peaks of these slow waves. I am using the DAC to an oscilloscope to see the filtered signal, but is there a PC program that can be used to capture data from the serial output for visualization ?
 
Hey, is it possible to get a signal as an input to the audio library that does not come from the audio shield chip line_in or I2S ? Can I use a variable in my program as the input feed into the audio library ?
 
Hey, is it possible to get a signal as an input to the audio library that does not come from the audio shield chip line_in or I2S ?

Sure. The audio library currently has 2 working input objects. The other one uses the on-chip ADC.

Can I use a variable in my program as the input feed into the audio library ?

There must be at least 1 hardware input or output. The library doesn't run unless at least 1 of those hardware objects is present.

You could use the DAC output or PWM output, and simply not connect anything to those pins. That will let the library run.

There are several synth objects that create signals mathematically. Maybe the DC object will be close to "use a variable in my program as the input feed"?

http://www.pjrc.com/teensy/gui/?info=AudioSynthWaveformDc
 
Yes, how for sure I can't say. Web Doc page is here: Teensy Audio Library it links to here: Audio System Design Tool

Using T_FFT_SINEWAVE.ino sample above (the included analyze/fft.ino) you'll see the SINEWAVE as input to a patch cord.

From the Design tool you drag and drop lay out to what you want (items on left and notes on right) and it generates the init code like this from Export in the browser:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

// GUItool: begin automatically generated code
AudioInputAnalog         adc1;           //xy=143,73.99998474121094
AudioAnalyzeFFT1024      fft1024_1;      //xy=311.79998779296875,73.19999694824219
AudioConnection          patchCord1(adc1, fft1024_1);
// GUItool: end automatically generated code

Given this I assume you just adjust the patch cord setting in the FFT sample to specify a PIN ( "adc1" ) and that will sample from that point. This is my next step with my analog mic.

I'm still using the FFT_SINEWAVE.ino as my basis and have done some edits to see the time taken and merged in the MemoryAndCpuUsage.ino so I can see CPU and RAM usage in this sample and then recompiling for 512 and 1024 FFT's.

QUESTION:
> Is this the common/best/intended process?
> After Setup can I changed the processing type in loop()? i.e. Stop 1024 and Start 512?
> I looked for an .end() function and didn't see it.
> Will it quit if I just stop doing .read()? What about the resources?
> Similarly can I cycle through the FFT Methods while in loop() or do I need to restart?
> I'm not even sure what I don't know yet, but from the sample I found CPU higher on 1024, but 512 takes twice as long at 25% of CPU usage?
> Can I record/capture the Sample 'analog mic' data and create a way to feed it in statically like the Sine wave

My status info on my 120 sample loop:
// CPU%, Mem Use, cum loop() pass count sample Ready and Not, Samples per loop, Per sample time, and time for Samples
// fft1024=52,52 all=53.31,53.92 Memory: 4,8 Ready:240 Not:967795 # Samples:120 Time per sample:11 Sample Time:1393
// fft256=12,12 all=13.84,14.34 Memory: 1,2 Ready:240 Not:2160366 # Samples:120 Time per sample:23 Sample Time:2785
 
Last edited:
From Paul's note - re my last question:
It seems I could do a sketch to get an interrupt set of samples for data I like on my source and store that data. Then for testing I could push that stored data out the DAC wired to an Analog input with another interrupt driven write while the FFT is running and it should see some similar version of what I recorded coming back in that pin?

I don't have an audio board - but it seems like it might be useful for my development in cases like this for 'component' testing?

My initial hope was maybe there was a way to have the FFT sample ask me [if I could trigger an interrupt to it] for the next value rather than actually read it from an input. If it could do that and I had the actual sample set from the FFT code for a good sample I could bypass my sampling and the DAC output simulation - and feed in a direct set of prior sample data without sample/conversion rate issues altering the 'testing'.
 
Last edited:
Actually, the hardware interrupt triggers a second software-only interrupt, which then runs the update functions on all audio objects.

This structure is used so the hardware interrupt can run at normal interrupt priority, but the lengthy updates can run at a much lower priority, allowing the nested priority interrupt controller to service other hardware interrupts while the audio library updates do all the computational work.
 
Still wondering about the other questions above

Ok, but quickly....


I'm still using the FFT_SINEWAVE.ino as my basis and have done some edits to see the time taken and merged in the MemoryAndCpuUsage.ino so I can see CPU and RAM usage in this sample and then recompiling for 512 and 1024 FFT's.

QUESTION:
> Is this the common/best/intended process?

yes/probably/yes

> After Setup can I changed the processing type in loop()? i.e. Stop 1024 and Start 512?
> I looked for an .end() function and didn't see it.

The audio library is designed to continuously stream and process audio. There's not .end() or stop feature.


> Will it quit if I just stop doing .read()? What about the resources?
> Similarly can I cycle through the FFT Methods while in loop() or do I need to restart?

The buffer only holds the most recent FFT analysis.

If you stop checking FFT.available(), the FFT analysis will go on and on, overwriting the old data with each new update.


> Can I record/capture the Sample 'analog mic' data and create a way to feed it in statically like the Sine wave

Sure. The two "queue" objects let you get access to the 128 sample blocks from your sketch. You can grab the blocks and store them to a file on a SD card, for example. In fact, the Recorder example does exactly that.

You can also inject blocks into the library using the play queue object. See the web design tool for documentation.

Those objects are called "queue" because they will queue up data, of course within the limit of how much memory you gave to the audio library. That lets you put more than 1 block at a time into the play queue, which is handy if you read a 512 byte sector from the SD card or receive data some other way. Likewise, the record queue will buffer up data arriving from the library, which really helps if the SD card or something else occasionally takes longer. As long as you maintain the overall data rate, those queue help relieve your responsibility to always have very low latency in your code.
 
Paul: regarding PlayQueue Feeding to fft256, int16_t, I found the Freescale_Demo_3.ino that plays from a queue.
int16_t *p = audio.getBuffer();
// ...
audio.playBuffer();

Do I understand this assigns me a buffer I fill and then never see again, that fft will return to the pool?

I plan to set up an ADC Lib read of my own data and fill the buffer to forward. Or according to post #23 above I could play back saved buffers.

The design tool gave me this:
AudioPlayQueue queue1; //xy=230,152
AudioAnalyzeFFT256 fft256_1; //xy=401,152
AudioConnection patchCord1(queue1, fft256_1);

Is this interaction missing a hardware link - or will queue1.playBuffer(); excite the needed software?

Giving me a fft256_1.available() when it gets buffer data for the 256 data points?

Note: Need quick FFT and response to sounds (ideally <.01 sec) and min CPU burn here for main tasks
Note: Using ADC to sample near 8kHz captures needed audio range, and narrows freq/bin in 4kHz
Note: Perhaps preloading last 128 samples as start of next set of 256 so FFT's finish faster
Note: Perhaps monitor peak (100db+) sounds as I get ADC data and not even bother with FFT
 
Status
Not open for further replies.
Back
Top