Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 15 of 15

Thread: Audio play single in memory WAV - fails

  1. #1

    Audio play single in memory WAV - fails

    I'm trying to play a single wav file from memory on Teensy 3.2 when triggered. As a test I do it in a loop.
    The first play works ok, but subsequent play seem to either play other parts of wav or nothing.

    Below is the basic code used. I'm not including the AudioSample files as most are from the Audio libary examples SamplePlayer. It is pretty simple, only one AudioConnection tween audio and teensy DAC
    Once it starts play, it uses isPlaying() to delay until the sound stops. (is there a better alternative?)
    When playing Buzzer, it plays first time, says it counted to 7, then waits and tries again
    Sometimes the sound comes again, other times it is clipped off, other times nothing comes out even though it says it played.

    If not this, what would be the simplest PlaySound() using Audio library?

    Code:
    // revision of PJRC Audio SamplePlayer that just cycles thru all
    // does not use Buttons, only uses DAC
    
    #include <TeensyAudio.h>  // simple rename to avoid conflict with Arduino Audio lib built into IDE
    #include <SerialFlash.h>
    
    // WAV files converted to code by wav2sketch
    //#include "AudioSampleOne.h"
    //#include "AudioSampleSnare.h"
    //#include "AudioSampleBell.h"
    #include "AudioSampleBuzzer.h"
    
    //#define SOUND AudioSampleOne
    #define SOUND AudioSampleBuzzer
    //#define SOUND AudioSampleBell
    
    // Create the Audio components.  These should be created in the
    // order data flows, inputs/sources -> processing -> outputs
    // one memory sound, one analog output, and one audio connection
    AudioPlayMemory    playMemSound;
    AudioOutputAnalog  dac;  
    AudioConnection c10(playMemSound, 0, dac, 0);
    
    void setup() {
      Serial.begin(115200);
      delay(500);
      Serial.println("Teensy One Sound Player");
    
      // Audio connections require memory to work.  For more
      // detailed information, see the MemoryAndCpuUsage example
      AudioMemory(10);
    
    }
    
    void loop() 
    {
      playOneSound();
      delay (2000);
    }
    
    void playOneSound()
    {
      Serial.println("PlayOneSound");
      int count=0;
    //  delay(100);
      playMemSound.play(SOUND);
    //  delay(50);
      while (playMemSound.isPlaying())
      {
        count++;
        delay(200);
      }
      Serial.printf("Played sound %d counts\n", count);
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,511
    Looks like it oughta work.

    Can you share AudioSampleBuzzer.h and AudioSampleBuzzer.cpp, so I can try running it here?

  3. #3
    Quote Originally Posted by PaulStoffregen View Post
    Looks like it oughta work.

    Can you share AudioSampleBuzzer.h and AudioSampleBuzzer.cpp, so I can try running it here?
    I get similar odd results using the Bell and Snare from the Audio>examples>SamplePlay but here are the Sample One and SampleBuzzer
    Attached Files Attached Files

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,511
    I'm running it here on a Teensy 3.2. It makes a 90s-era business phone ringing sound every 2 seconds. It rings every time. Hasn't stopped even one over the last several minutes.

    I edited "TeensyAudio.h" back to "Audio.h", but otherwise it's exactly the code you posted, with these 4 files added to its folder.

    Maybe your installation is somehow corrupted. Or maybe files from other libs are causing trouble? Simplest thing might be to try on another computer, especially one that hasn't used Arduino before. Or maybe try uninstalling whatever other libs are conflicting? If you're using Windows or Linux, Arduino has a portable mode where it runs self-contained. You could try extracting a copy from a zip file, run the Teensyduino installer on that copy, then create the "portable" folder. Hopefully that will be enough to prevent that copy of the Arduino IDE from using the files elsewhere on your PC.

    Best I can do is tell you it definitely does work when I run it here.

  5. #5
    did you let it run a bit?
    I dont have a naked machine, but I did a clean and reinstall from my mac, and also from a windows 10 laptop. And another PC.All build and load into teensy and it starts to play.

    It plays about 4 times then starts clipping it off. Successive rings/plays clip more and more until it doesnt play at all. Then it comes back strong for a bit, then clips again.

    This happens on both Buzzer and AudioSampleOne. Since they are large, I thought I'd try AudioSampleBell - which is from the Audio>examples>SamplePlayer. It does similar clipping and not playing - it sounds like it is playing from different parts of the memory (eg starting late)

    Maybe it is something with this teensy and/or the speaker? (iHome speaker wired to DAC pin)

    We are wiring up my AudioTutorial with a lineOut to speaker on the Audio board to try it. Maybe some other 3.2 with the DAC too.

    (TeensyAudio hack was to work around an earlier issue with library conflict in the IDE)

  6. #6
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,613
    Quote Originally Posted by isdale View Post

    Maybe it is something with this teensy and/or the speaker? (iHome speaker wired to DAC pin)
    I assume your speaker has an amp. The DAC can only source 1 ma so it should not be hooked directly to a speaker.

  7. #7
    tried on a fresh 3.2 and no change.
    drat. deadline looms.

  8. #8
    the iHome is designed to go from any line output, like a phone (w/o bluetooth). It worked fine taking output from a DFPlayerMini but maybe it does need more boost?

  9. #9
    Ok tried two tests - plugged into a 0.25w adafruit speaker and it is VERY VERY quiet, but seems to play properly. Hard to tell as it is so quiet.

    Plugged into a 12v sparkfun amplifier it clips.

    I dont have an alternative amp or speaker available.
    Suggestions on amps to try?
    https://www.sparkfun.com/products/11044
    https://www.adafruit.com/product/2130

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,511
    Quote Originally Posted by isdale View Post
    did you let it run a bit?
    ...
    It plays about 4 times then starts clipping it off. Successive rings/plays clip more and more until it doesnt play at all. Then it comes back strong for a bit, then clips again.
    Yes, I let it play for several minutes. After a couple hundred plays, I really had to turn the speaker off.

    I tested by connecting the DAC pin directly to the cord which runs to Aux input on the front of this monitor speaker (M-Audio AV40, now discontinued)


    Click image for larger version. 

Name:	DSC_0260_web.jpg 
Views:	3 
Size:	123.0 KB 
ID:	15122
    Last edited by PaulStoffregen; 11-09-2018 at 10:38 AM.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,511
    Quote Originally Posted by isdale View Post
    Plugged into a 12v sparkfun amplifier it clips.
    In theory you should be able to just turn the volume almost all the way down with the pots connected to the inputs. But that amp has so much voltage gain that only the first few degrees of the pot's rotation might be usable.

    Maybe try replacing R1 and R3 on that Sparkfun amplifier with 10K resistors. Or just solder 10K resistors in parallel with the 100K ones already on the board, for approx 9.1K. That should reduce the total voltage gain into a range that's much more useful for this project.

  12. #12
    That 12vdc amp wont be used for final project, but adding resistors may make it more usable for other ones. (I dont want to add another power supply to this system.)
    For this project I ordered one of the LC Prop Shields, and also some of the mono amps from Sparkfun+Adafruit. Given it costs me more for shipping than the boards, I usually buy several at a time. We'll see which ones arrive first and what works best going into the PA system similar to your M-Audio speaker that is part of the whole 'Game Show' rig.
    I'll post some pics of this project when complete. Its been a loooong time building. ;-)

  13. #13
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,511
    Quote Originally Posted by isdale View Post
    and what works best going into the PA system similar to your M-Audio speaker that is part of the whole 'Game Show' rig.
    You should *not* connect those class-D amplifier outputs to anything other than a regular speaker. They output waveforms similar to PWM. The idea is the speaker is basically a big inductor, since it's a coil of wire that doesn't conduct the very high frequency switching. It should *only* ever be connected to a speaker!

    Do not connect a class-D amplifier output to the input of a PA system, home stereo, the input of an amplified computer speaker, or any other gear you care about.

  14. #14
    Quote Originally Posted by PaulStoffregen View Post
    You should *not* connect those class-D amplifier outputs to anything other than a regular speaker. They output waveforms similar to PWM. ...
    Do not connect a class-D amplifier output to the input of a PA system, home stereo, the input of an amplified computer speaker, or any other gear you care about.
    The LM48310 used on the PropShield is a Class D, so it is NOT a viable preamp for the teensy->PA. Do you have any recommendations for a device to go tween them?

  15. #15
    perhaps one of these MAX97220 evaluation boards? https://www.digikey.com/catalog/en/p...tion-kit/42837

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •