Audio Library

Status
Not open for further replies.
First attempt using RC6

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.5 (Windows 7), Board: "Teensy 3.1"
In file included from display_FFT.ino:1:0:
C:\Program Files\Arduino\libraries\Audio/Audio.h:52:32: fatal error: analyze_peakdetect.h: No such file or directory
compilation terminated.
 
You must have an old copy of Audio.h.

Please try running the installer again. Make sure Audio is checked on the library installation page. That should install the latest audio library.
 
Code:
 * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
 */* Audio Library for Teensy 3.X
 * Development of this audio library was funded by PJRC.COM, LLC by sales of
 * Teensy and Audio Adaptor boards.  Please support PJRC's efforts to develop
 * open source software by purchasing Teensy or other PJRC products.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice, development funding notice, and this permission
 * notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef Audio_h_
#define Audio_h_

// When changing multiple audio object settings that must update at
// the same time, these functions allow the audio library interrupt
// to be disabled.  For example, you may wish to begin playing a note
// in response to reading an analog sensor.  If you have "velocity"
// information, you might start the sample playing and also adjust
// the gain of a mixer channel.  Use AudioNoInterrupts() first, then
// make both changes to the 2 separate objects.  Then allow the audio
// library to update with AudioInterrupts().  Both changes will happen
// at the same time, because AudioNoInterrupts() prevents any updates
// while you make changes.
//
#define AudioNoInterrupts() (NVIC_DISABLE_IRQ(IRQ_SOFTWARE))
#define AudioInterrupts()   (NVIC_ENABLE_IRQ(IRQ_SOFTWARE))


// include all the library headers, so a sketch can use a single
// #include <Audio.h> to get the whole library
//
#include "analyze_fft256.h"
#include "analyze_fft1024.h"
#include "analyze_print.h"
#include "analyze_tonedetect.h"
#include "analyze_peakdetect.h"
#include "control_sgtl5000.h"
#include "control_wm8731.h"
#include "effect_chorus.h"
#include "effect_fade.h"
#include "effect_flange.h"
#include "filter_biquad.h"
#include "filter_fir.h"
#include "input_adc.h"
#include "input_i2s.h"
#include "mixer.h"
#include "output_dac.h"
#include "output_i2s.h"
#include "output_pwm.h"
#include "play_memory.h"
#include "play_queue.h"
#include "play_sd_raw.h"
#include "play_sd_wav.h"
#include "synth_tonesweep.h"
#include "synth_sine.h"
#include "synth_waveform.h"
#include "analyze_freq.h"


// TODO: more audio processing objects....
//  sine wave with frequency modulation (phase)
//  waveforms with bandwidth limited tables for synth
//  envelope: attack-decay-sustain-release, maybe other more complex?

#endif

This file in program files/arduino/libraries/audio

Installed RC6 with libraries checked. Will delete the audio library and reinstall RC6.
 
That's absolutely not the same Audio.h from the 1.20-rc6 installer.

Can you look at the modification time on the file? Is it older than when you just ran the installer?


Edit: when you run the installer, can you double check the directory where it's going to write. Is it really the same location? A common problem, especially on Windows, involves 2 or more copies of Arduino, where the installer writes to one of them, but when you use Arduino, Windows actually runs the other one.
 
Very odd the installer seems to be pulling in a audio.h that I had modified ( analyze_freq.h) where it is finding it I have no idea as it has been deleted from documents/ardino/libraries. Will close all programs, reboot, and re-install.
 
Searched for and deleted every occurrence of audio.h on my hard drive. Found one very odd occurrence at ..../apps/virtualstore/......./arduino/libraries/..... that seemed to be the culprit. Deleted that file and re-installed RC6, now the example files compile.
 
The audio library and the ILI9341 library are still not playing well together. At least not the FFT.
 
Searched for and deleted every occurrence of audio.h on my hard drive. Found one very odd occurrence at ..../apps/virtualstore/......./arduino/libraries/..... that seemed to be the culprit. Deleted that file and re-installed RC6, now the example files compile.

http://www.sevenforums.com/general-discussion/222389-what-virtual-store-folder.html
http://answers.microsoft.com/en-us/...indows-7/55dce284-0dcd-46af-892e-d2b9cf5bcff6

This is what happens when a program tries to write to C:\Program Files etc and does not have permission. It gets written to some special aliasing place instead and then shhadowed in. Thus, what you see in file manager is different to what Windows sees. It is a total PITA.

Solution: do not use the Arduino installer, use the zip instead. Do not install to Windows special locations like Users/Documents or Program Files. Put it on a different partition if you have one.
 
Back in July... not last July, but in 2013, I submitted this tiny patch to Arduino. It sat unused until recently.

Still, today there are a lot of systems with Arduino 1.0.5... but eventually as 1.0.5 ages and gets replaced by 1.0.6 and newer, it'll become possible for the Teensyduino installer to figure out where every post-1.0.5 copy of Arduino is actually located on your computer. Well, at least all the ones you've run at least once.

Windows is a nightmare of trouble, and this is my long-term solution. I still haven't fully worked out how I'll build the GUI within the installer, but knowing the pathnames, versions, and system time it was most recently run should be plenty of info to present a troubled Windows system with some sort of list showing there are actually 2 multiple copies of Arduino.

Eventually I'm also going to figure out some way to make library conflicts (2 or more copies) highly visible.
 
The audio library and the ILI9341 library are still not playing well together. At least not the FFT.

I've updated the ILI9341 page with the required connections and sample code to get the display to work when the audio board is connected.

I tested with the ILI9431_t3 graphictest example, but so far I haven't written any code that displays FFT data. I'm pretty sure it'll work with the I2S objects and audio board active. Please let me know how it works for you.

Here's a photo of it working, at least graphicstest, with the audio board and those alternate connections. Hopefully this helps?

tftaudio.jpg
 
I just wrote a quick TFT spectrum display, showing the first 320 bins of the FFT (approx DC to 13.76 kHz).

Here it is, with my function generator sending a 1 kHz square wave:

tftspectrum.jpg
(click for full size)

Here's the complete source code, using the Audio and ILI9341_t3 libraries.

Code:
// Color TFT 320x240 (ILI9341) Audio Spectrum Analyzer Display
// 
//
// This example code is in the public domain.


#include <ILI9341_t3.h>
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>

// Audio library objects
// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=119,77
AudioMixer4              mixer1;         //xy=283,78
AudioAnalyzeFFT1024      fft1024;        //xy=444,73
AudioConnection          patchCord1(i2s1, 0, mixer1, 0);
AudioConnection          patchCord2(i2s1, 1, mixer1, 1);
AudioConnection          patchCord3(mixer1, fft1024);
AudioControlSGTL5000     audioShield;    //xy=360,150
// GUItool: end automatically generated code

const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

#define TFT_SDI  7
#define TFT_SDO 12
#define TFT_SCK 14
#define TFT_DC  20
#define TFT_CS  21
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);

// Run setup once
void setup() {
  // set up the TFT screen
  SPI.setMOSI(TFT_SDI);
  SPI.setSCK(TFT_SCK);
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);

  // start the audio library
  AudioMemory(12);
  audioShield.enable();
  audioShield.inputSelect(myInput);
}

unsigned int line[320];
unsigned int previous[320];


// Run repetitively
void loop() {
  unsigned int y;

  if (fft1024.available()) {
    // first, grab the first 320 frequency bins
    for (y=0; y < 320; y++) {
      line[y] = fft1024.read(y) * 240.0;
      if (line[y] > 240) line[y] = 240;
    }

    // draw horizontal lines for each frequency
    for (y=0; y < 320; y++) {
      if (line[y] > 0) {
        tft.drawFastHLine(0, y, line[y], ILI9341_YELLOW);
      }
      if (line[y] < 240) {
        tft.drawFastHLine(line[y], y, 240 - line[y], ILI9341_BLACK);
      }
    }

  }
}
 
Last edited:
Paul:

I browse this forum once in a while and wanted to give you some feedback.

1.) Great job with the Audio library! While my objectives were different, I have a couple audio projects I did with Freescale University Program:

MonkeyJam:
https://community.freescale.com/docs/DOC-100149

MonkeyListen:
https://community.freescale.com/docs/DOC-100207/

2.) I 100% back your decision on the 16-bit 44.1KHz. Don't move from this. Physics is on your side of this one. It covers the 99.9% case and enables some great projects. I personally Like 24/32/48Khz but only because it is an easy one to hit without wierd PLLs or crystals :). 96Khz is just dumb. The other one is sigma-delta converters. The distribution of noise is generally accepted as more pleasing. I did a project using the ADCs in the Kinetis for a guitar:

Intro:
https://www.youtube.com/watch?v=o5Zz9qXT81I
Jamming:
https://www.youtube.com/watch?v=G3G1YBJVIyQ
Physics
https://www.youtube.com/watch?v=hI7nvLrYxc4

The results were good but the "high gain" amp models showcases the difference between Sigma Delta and SAR noise profiles. That being said the 13ish bits were fine for the experiment!

I am working on V2 right now! :)

But either way, what you have is great. I do have application (sound to Partial Diff Eq "Cartoon physics model to LEDs) for the teensy that will be for the Freescale HIT series. I will post when it is at a point worthy of review.


Anyway, keep plowing forward. The work is great! Love the NodeRed stuff BTW!

-Eli
 
edit: well, i do have a question, after all.

My only other wishlist items are
-open file name by index example
-support 22khz, mono wav file playback (for sake of CPU consumption in multi file playback, hopefully)

did you have any luck re open by "index" ? or look into it?

there obviously can't be an example, but i was curious about this, too, ie possible latency improvements. it looks as if uint8_t open(SdFile* dirFile, uint16_t index, uint8_t oflag); didn't make it into the SD wrapper, but i'm not even sure it's worth the effort. i'm measuring about 1500 us worst case until play (sd_play_wav) returns, on average more like 500 us, which doesn't strike me as particularly bad, though i still have to test this in conjunction with real gear.

edit2: well, that's not quite true of course because the latency is progressively getting worse the more files there are, and the less pristine the state of the SD card is.
 
Last edited:
Paul and all,

We did progress on a beat detection and we have a basic beat detection going. If you are interested let me know.

regards
Rob Oudendijk
Julian Villegas
 
I do have application (sound to Partial Diff Eq "Cartoon physics model to LEDs) for the teensy that will be for the Freescale HIT series. I will post when it is at a point worthy of review.

Great, looking forward to seeing it.

Do you suppose Freescale would publish a project with Teensy + Arduino, rather than FRDM + CodeWarrior?!
 
We did progress on a beat detection and we have a basic beat detection going. If you are interested let me know.

YES, if it's sharable as open source, I'd love to see it and probably merge it into the library.

Edit: even if it's not sharable... I'd still love to see a video demo!!
 
edit: well, i do have a question, after all.



did you have any luck re open by "index" ? or look into it?

there obviously can't be an example, but i was curious about this, too, ie possible latency improvements. it looks as if uint8_t open(SdFile* dirFile, uint16_t index, uint8_t oflag); didn't make it into the SD wrapper, but i'm not even sure it's worth the effort. i'm measuring about 1500 us worst case until play (sd_play_wav) returns, on average more like 500 us, which doesn't strike me as particularly bad, though i still have to test this in conjunction with real gear.

edit2: well, that's not quite true of course because the latency is progressively getting worse the more files there are, and the less pristine the state of the SD card is.

No, I have made no progress on 'open by index', but nice to see someone else would be interested in an example to open w/ faster latency than by feeding file names. Worked great in WaveHC for me in the past (old arduino shield). I would be curious to see how much better it would be with this on the Teensy shield. I am busy working to make a commercial product using custom Teensy PCB and bootloader chips from PJRC soon.
 
A bit late, but some time back Paul was after some open source sound samples:

http://download.linuxaudio.org/musical-instrument-libraries/sfz/the_open_source_drumkit.tar.7z

The SFZ file is just a zip file. Inside which there is....yet another zipfile (Caleld "noname", just tag a .zip on the end...) inside which is a series of folders full of drum kit WAVs at 24/96, with around 15 to 20 velocities of strike for each item.

And i quote from the readme:
"THE OPEN SOURCE DRUM KIT by Real Music Media - www.realmusicmedia.net
Mapped by BaardW (Tjuvdalen, Norway) v 1.0 feb 2010 - www.trelyd.org
Partially based on the mappings by SWTrex and herodotus

The samples and the mappings are completely in the public domain.

Please see this this thread on KVR for more info:
http://www.kvraudio.com/forum/viewtopic.php?t=277132

Thanks to Real Music Media for the samples! Check out their site for other free samples of very high quality.

Please report bugs in the above mentioned thread on KVR, or at trelyd [ at ] gmail.com."

and a quote from heredotus in the linked thread from 2010:


"Absolutely.

To reiterate, these drum samples are completely public domain. I am giving up my intellectual property rights to them.

You can do whatever you want to do with them. Hell, you could even add your own mappings and sell them if you wanted. I might think that was kind of, well...iffy, but I wouldn't try to stop it. "
 
I just ran a little test on processor usage, latest teensyduine / Audio library, Overclocked to 96Khz;

5 samples played concurrently uses about 4% of CPU time
10 samples concurrently uses 9% of CPU time

So projecting maximum polyphony of samples around 100 channels mark, at 96Mhz, assuming no other effects or envelopes.

This is far better than I was expecting! Considering that this little baby can be clocked considerbaly higher, this is very promising indeed as a sampler engine.

Thanks Paul :)
 
Last edited:
just a quick update, the teensy (almost) maxed out last night at 93% running 14 concurrent samples and 2 WAV files from SD Card, through 5 mixers.

I do have a comment on the delay effect module; While affording a separate output for each delay is great in terms of flexibility, you will need 3 mixers to pull all 8 taps into one mixed stream, with adjustable fade on each mixer channel. This creates some fairly complex code.

Long term a more useful progression of the effect would have a single mixed output version, duplicating the mixer 4 code to mix all 8 channels into one output in the library, with a selectable gain fade curve for the taps), and a longer sample length to handle the kind of echoing delays you find in time with electronic music. This is probably something I'd like to implement in my beatmaker so I might be able to write it myself, since much of the code is already written for me. Just be aware that I have a lot of work to do on my project, and it's not at the top of my list.

SPI flash memory is the real kicker for me,I'm almost all out of sketch memory before I've even started, loading WAVs from SDCard on the fly into SPI flash is by far the most important element to my success, followed by the 96PPQN (or near) sequencer engine which I will build and then contribute to the project.
 
loading WAVs from SDCard on the fly into SPI flash is by far the most important element to my success, followed by the 96PPQN (or near) sequencer engine which I will build and then contribute to the project.

Both of those would be excellent additions!
 
Another performance update;

Just playing a single SDCard Wav file runs 28% of CPU time.
Adding a flanger to this single stream brings CPU up to 48%

Code:
Proc = 27.69 (28.28),  Mem = 5 (5)
PlayWav1 Flanger On
Proc = 47.12 (47.44),  Mem = 5 (5)
PlayWav1 Flanger Off
Proc = 27.79 (47.39),  Mem = 5 (5)
Proc = 27.70 (28.29),  Mem = 5 (5)
 
I'm porting some old signal processing code to the Teensy 3.1. Though I have 30+ years of experience using C, C++ is still very new to me which complicates my understanding of the Audio source. I'm trying to measure phase between two audio channels which requires the real and imaginary components of the fft output. I see that all I need is within the audio_block_t block data that is internal to the AudioAnalyzeFFT256 module and that the blocks are allocated with AudioMemory(). How do I access this data after fft.available() is true?
 
Status
Not open for further replies.
Back
Top