Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 46

Thread: Problems w/ Tone.h and MusicWithoutDelay.h Compiling

  1. #1
    Junior Member
    Join Date
    Aug 2018
    Location
    Columbia, SC
    Posts
    8

    Problems w/ Tone.h and MusicWithoutDelay.h Compiling

    Hello All,

    I am working on a project using a Teensy 3.5 and I would like to be able to use the MusicWithoutDelay library in conjunction with a passive piezo buzzer. It seems that this library depends on the Tone.h library by Brett Hagman. To start with I'm attempting to load up and test the "Basic" example sketch for the MusicWithoutDelay library, but while compiling I'm confronted with the following error:

    Code:
    Arduino: 1.8.5 (Mac OS X), TD: 1.40, Board: "Teensy 3.5, Serial, 120 MHz, Faster, US English"
    
    /Applications/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/wittyoctopus/Documents/Arduino/libraries -fqbn=teensy:avr:teensy35:usb=serial,speed=120,opt=o2std,keys=en-us -vid-pid=0X16C0_0X0483 -ide-version=10805 -build-path /var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178 -warnings=default -build-cache /var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_cache_567795 -verbose /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay/examples/Basic/Basic.ino
    /Applications/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/wittyoctopus/Documents/Arduino/libraries -fqbn=teensy:avr:teensy35:usb=serial,speed=120,opt=o2std,keys=en-us -vid-pid=0X16C0_0X0483 -ide-version=10805 -build-path /var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178 -warnings=default -build-cache /var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_cache_567795 -verbose /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay/examples/Basic/Basic.ino
    Using board 'teensy35' from platform in folder: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr
    Using core 'teensy3' from platform in folder: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr
    Detecting libraries used...
    "/Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w  -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=140 -DARDUINO=10805 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3" "/var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/sketch/Basic.ino.cpp" -o "/dev/null"
    "/Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w  -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=140 -DARDUINO=10805 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3" "-I/Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay/src" "/var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/sketch/Basic.ino.cpp" -o "/dev/null"
    "/Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w  -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=140 -DARDUINO=10805 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3" "-I/Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay/src" "-I/Users/wittyoctopus/Documents/Arduino/libraries/Tone" "/var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/sketch/Basic.ino.cpp" -o "/dev/null"
    Using cached library dependencies for file: /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay/src/MusicWithoutDelay.cpp
    "/Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w  -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=140 -DARDUINO=10805 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3" "-I/Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay/src" "-I/Users/wittyoctopus/Documents/Arduino/libraries/Tone" "/Users/wittyoctopus/Documents/Arduino/libraries/Tone/Tone.cpp" -o "/dev/null"
    Generating function prototypes...
    "/Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w  -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=140 -DARDUINO=10805 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3" "-I/Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay/src" "-I/Users/wittyoctopus/Documents/Arduino/libraries/Tone" "/var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/sketch/Basic.ino.cpp" -o "/var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/preproc/ctags_target_for_gcc_minus_e.cpp"
    "/Applications/Arduino.app/Contents/Java/tools-builder/ctags/5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "/var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/preproc/ctags_target_for_gcc_minus_e.cpp"
    Compiling sketch...
    "/Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++14 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=140 -DARDUINO=10805 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3" "-I/Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay/src" "-I/Users/wittyoctopus/Documents/Arduino/libraries/Tone" "/var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/sketch/Basic.ino.cpp" -o "/var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/sketch/Basic.ino.cpp.o"
    Basic:12: warning: ISO C++ forbids converting a string constant to 'char*' 
     char *song = ":d=4:c,d,e,f,g,a,b,c1";  //the C major scale. This format is known as RingTone Transfer Language or RTTL(It was used by Nokia's phone company).
                  ^
    Compiling libraries...
    Compiling library "MusicWithoutDelay"
    Using previously compiled file: /var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/libraries/MusicWithoutDelay/MusicWithoutDelay.cpp.o
    Compiling library "Tone"
    "/Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++14 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=140 -DARDUINO=10805 -DF_CPU=120000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3" "-I/Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay/src" "-I/Users/wittyoctopus/Documents/Arduino/libraries/Tone" "/Users/wittyoctopus/Documents/Arduino/libraries/Tone/Tone.cpp" -o "/var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_build_532178/libraries/Tone/Tone.cpp.o"
    /Users/wittyoctopus/Documents/Arduino/libraries/Tone/Tone.cpp:126:4: error: expected constructor, destructor, or type conversion before '(' token
     ISR(TIMER0_COMPA_vect)
        ^
    Using library MusicWithoutDelay at version 1.0.0 in folder: /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay 
    Using library Tone at version 1.0.0 in folder: /Users/wittyoctopus/Documents/Arduino/libraries/Tone 
    Error compiling for board Teensy 3.5.
    I'm assuming that the lines:

    Code:
     /Users/wittyoctopus/Documents/Arduino/libraries/Tone/Tone.cpp:126:4: error: expected constructor, destructor, or type conversion before '(' token
     ISR(TIMER0_COMPA_vect)
        ^
    point to the heart of the problem. It appears that the Tone.h library has not been optimized for use with the Teensy platform.

    My questions for y'all is would it be possible to easily optimize this library for use with the Teensy? Has this library already been optimized for Teensy and I just missed it in my internet searches? In the alternative, would it be possible to modify the MusicWithoutDelay library to operate independently of the Tone.h library? Or does anyone have any suggestions for a library like MusicWithoutDelay that has already been optimized for use with the Teensy.

    Thank you for any assistance that you could provide and please let me know if I need to edit anything or if you need further information.

    EDIT:

    Here's the exact source code I'm attempting to compile from the MusicWithoutDelay's example folder:

    Code:
    //Type 's' in serial monitor, you should see something :D  (This proves that my library doesn't use delay)
    /*Example for the MusicWithoutDelay Library by Nathan Ramanathan. nathan6ramanathan@gmail.com
       This simple sketch is the most basic thing my library does effectively.
       It plays the C Major scale, with each note being a quarter note.
       The song stops playing when the instrument is done playing forward and backward once.
       Obviously, you can do other things while the song is being played.
       For example, talk to Serial, read buttons, display images on an OLED screen, etc...
    */
    //To learn more about this project go to https://github.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary
    #include <MusicWithoutDelay.h>
    #include <Tone.h>                //https://github.com/bhagman/Tone
    char *song = ":d=4:c,d,e,f,g,a,b,c1";  //the C major scale. This format is known as RingTone Transfer Language or RTTL(It was used by Nokia's phone company).
    MusicWithoutDelay instrument(song);          //d=4 means that every note without a number in front of the letter is assumed to be a quarter note.
    Tone myTone;
    void setup() {                               //For details on the RTTL format, look at https://github.com/nathanRamaNoodles/MusicWithoutDelay-LIbrary documentation
      // put your setup code here, to run once:
      myTone.begin(11);  //connect speaker with 200 ohm resistor to pin 11.
      Serial.begin(9600);
      unsigned long t = instrument.getTotalTime();  //spits out total time in milliseconds
    
      Serial.print("Total Time: "); Serial.println(t / 1E3);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      unsigned long cMillis = millis();  //I know millis() can be implemented in my library,
      instrument.play(cMillis, myTone);  //but its important to recognize that this library depends
      if (instrument.isEnd()) {          //on your main code not having delay().  Also, it increases stability, so your welcome :D
        instrument.reverse();     //reverses song when end is reached
      }
      if (instrument.isStart()) {
        instrument.pause();  //stops the song when beginning is reached while song was played backwards
      }
      if (Serial.available()) {
        char str = Serial.read();
        switch (str) {
          case 's':  //type 's' in Serial monitor.
            //instrument.skipTo(instrument.getTotalTime() * (0.50)); //skip to halfway point
            Serial.println("What's it to ya?  I don't use delay, and you shouldn't either.\n Star this project on Github, and spread this good news to others.");
            break;
        }
      }
    }
    Last edited by woodenbots; 08-28-2018 at 09:08 PM. Reason: Title Correction

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,586
    The mention of TIMER0_COMPA_vect shows that this library is written uniquely for the old and outdated 8bit AVR processors. It obviously doesn‘t have support for modern 32bit ARM Cortex M4 hardware, where timer compare interrupts are handled in a completely different way.
    The much more powerful Teensys can do music in a much more elegant and efficient way, using the Teensyduino audio library, and using one or both internal 12bit DACs of the T3.5 instead of that somewhat crappy PWM approach.

  3. #3
    Junior Member
    Join Date
    Aug 2018
    Location
    Columbia, SC
    Posts
    8
    I understand, I think, that the Teensy can handle pretty powerful audio output, should it need to; however, for this project all Iím looking to accomplish is a three or four tone piezo buzzer audio effect for example:

    Code:
    tone(piezoPin, 2500, 300);
    delay(300);
    tone(piezoPin, 3500, 400);
    delay(400);
    tone(piezoPin, 2500, 500);
    delay(500);
    Because of this audio ďjingleísĒ location in my sketch a typical play without delay type function doesnít cut it, which is why I was hoping that the MusicWithoutDelay library would work perfectly.

    Would the teensy audio library be able to handle something this simple? Most, if not all of the tutorials that I can find for that library are for far more complex needs. My searches for solutions to solving this situation with the teensy audio library have been fruitless thus far.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,001
    You certainly can use the audio library for this. The design would probably look something like this:

    Click image for larger version. 

Name:	sc.png 
Views:	29 
Size:	18.8 KB 
ID:	14585

    In your code, you'd just configure the 4 waveforms to create the tones you wish to each. It all runs non-blocking, so your program can do other works (or just delay) while the waveforms are generated.

    Of course, you can get so much more with the audio library. Each waveform can have different amplitude as well as frequency, rather than having them all the same as with that simple library. You can also select from several different waveforms, rather than being limited to only square waves. If you want more than 4, no problem, just add more mixers and more waveforms. You can also add envelope effects between the waveform and mixer, and then use the envelope to turn the note on/off. The envelope's ADSR response gives a much more natural and pleasing on/off than just starting and stopping the oscillator. Especially if you configure long release times, the effect can be a very smooth & graceful sound.

    But if you only want 4 equal amplitude square waves, with nothing fancy like envelopes or effects, the audio library does have that capability. Just configure the 4 waveforms for square and set all their amplitudes to 0.25 (or set the mixer gains to 0.25) so when they are all at peak the output will be 1.0 max. The one difference is the audio library doesn't have timed functions like tone(), so if you want the note to be on for 300 ms, you need to turn it on (set the frequency & amplitude) and then 300 ms later turn it off (set the amplitude to zero). There isn't a function which turns it off automatically.

    If you later want to do want to do awesome stuff, the audio library makes it extremely easy to do things like just drop a reverb effect into the design between the mixer & output, and suddenly you've got reverb on your sound!

  5. #5
    Junior Member
    Join Date
    Aug 2018
    Location
    Columbia, SC
    Posts
    8
    Thank you for all that information. I think I should be able to use that as a jumping off point for solving the problem. And now Iím intrigued by what else can be accomplished. Iím continually amazed as to what can be done with these tiny boards.

    I think one of the chief obstacles to my understanding of what can be accomplished with the Teensy audio library has been seeing ďwaveformsĒ as something along the lines of a .wav file, instead of something that could be modulated and edited through code. One of my many shortcomings I suppose.

    At this point I have just enough arduino coding skills to know how little knowledge I actually have. Iím slowly but surely deepening my knowledge base though. Thank you all for contributing.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,001
    I'll take a look at that old library too. Maybe it can be ported.

  7. #7
    Junior Member
    Join Date
    Aug 2018
    Location
    Columbia, SC
    Posts
    8
    Thank you.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,001
    I looked at the MusicWithoutDelay library. It's actually doing quite a bit of sophisticated 8 bit synthesis.

    Here's a port for Teensy.

    https://github.com/PaulStoffregen/Mu...tDelay-LIbrary

    I'm running the "Basic" example right now on a Teensy 3.5. Sounds pretty good for 8 bit synth.

  9. #9
    Junior Member
    Join Date
    Aug 2018
    Location
    Columbia, SC
    Posts
    8
    Thatís amazing. Thank you again. Once I get all the kids to bed Iíll get a chance to test it out myself.

    I also just want to say that I truly appreciate the hard work that you put in here and for these boards (double meaning intended). As a small business owner myself I know how exhausting it can be to stay on top of everything. The facts that you work so hard to continually help out the people using the teensy and keep it updated and improving the way you do is impressive.

    Thank you again.

  10. #10
    Junior Member
    Join Date
    Aug 2018
    Location
    Columbia, SC
    Posts
    8
    Quote Originally Posted by PaulStoffregen View Post
    I looked at the MusicWithoutDelay library. It's actually doing quite a bit of sophisticated 8 bit synthesis.

    Here's a port for Teensy.

    https://github.com/PaulStoffregen/Mu...tDelay-LIbrary

    I'm running the "Basic" example right now on a Teensy 3.5. Sounds pretty good for 8 bit synth.
    Not to be too much of a pill. Just installed the library and it seems to be having difficulty compiling the tables.h. Here's a sampling of the error messages I'm getting.

    Code:
    In file included from /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay-LIbrary-master/src/synth.h:13:0,
                     from /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay-LIbrary-master/src/MusicWithoutDelay.h:32,
                     from /var/folders/t4/6n9gw0tn5hd0lc9l1jh2jl9m0000gn/T/arduino_modified_sketch_687862/Basic.ino:32:
    /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay-LIbrary-master/src/tables.h:315:1: error: narrowing conversion of '-3' from 'int' to 'char' inside { } [-Wnarrowing]
     };
     ^
    /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay-LIbrary-master/src/tables.h:315:1: error: narrowing conversion of '-6' from 'int' to 'char' inside { } [-Wnarrowing]
    /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay-LIbrary-master/src/tables.h:315:1: error: narrowing conversion of '-9' from 'int' to 'char' inside { } [-Wnarrowing]
    /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay-LIbrary-master/src/tables.h:315:1: error: narrowing conversion of '-12' from 'int' to 'char' inside { } [-Wnarrowing]
    /Users/wittyoctopus/Documents/Arduino/libraries/MusicWithoutDelay-LIbrary-master/src/tables.h:315:1: error: narrowing conversion of '-15' from 'int' to 'char' inside { } [-Wnarrowing]
    That error is the same for every one of what appear to be arrays in the header file. It's possible that I did something wrong.

    EDIT: I know I'm missing something but in synth.h DIFF is defined as 1 and CHA as 2 and CHB as 3, does that mean that the library has the potential of output on 2 and 3, and are those a reference to the DAC pins on the Teensy 3.5?
    Last edited by woodenbots; 08-29-2018 at 04:01 AM. Reason: Question regarding pins

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,001
    Maybe you have an old version of Teensyduino? (from before we changed the narrowing conversion to just a warning) In Arduino, click Help > About (or Arduino > About if using a Mac) to check the version.

    I tested with 1.43-beta2.

    https://forum.pjrc.com/threads/53574...no-1-43-Beta-2


    And just to confirm, when I compiled it here I saw maybe a hundred or more warnings. But none were errors and it did work. Seems the author has warnings turned off and unwittingly wrote a lot of less-than-perfect code.

  12. #12
    Junior Member
    Join Date
    Aug 2018
    Location
    Columbia, SC
    Posts
    8
    Quote Originally Posted by PaulStoffregen View Post
    Maybe you have an old version of Teensyduino? (from before we changed the narrowing conversion to just a warning) In Arduino, click Help > About (or Arduino > About if using a Mac) to check the version.

    I tested with 1.43-beta2.

    https://forum.pjrc.com/threads/53574...no-1-43-Beta-2


    And just to confirm, when I compiled it here I saw maybe a hundred or more warnings. But none were errors and it did work. Seems the author has warnings turned off and unwittingly wrote a lot of less-than-perfect code.
    Perfect, worked like a charm. Sorry, I should have thought about double checking the version I was running at the start.

  13. #13
    Quote Originally Posted by woodenbots View Post
    Perfect, worked like a charm. Sorry, I should have thought about double checking the version I was running at the start.
    Hi there, I created the MusicWithoutDelay library, and thank you for using it. Unfortunately, I have abandoned it due to others lack of interest. Also, out of curiousity, why did you choose my library? Is there anything you want for me to adjust to make it better?
    😃Thanks

  14. #14
    Junior Member
    Join Date
    Aug 2018
    Location
    Columbia, SC
    Posts
    8
    Quote Originally Posted by nathanSuperStar View Post
    Hi there, I created the MusicWithoutDelay library, and thank you for using it. Unfortunately, I have abandoned it due to others lack of interest. Also, out of curiousity, why did you choose my library? Is there anything you want for me to adjust to make it better?
    😃Thanks
    I'm glad you jumped on here. Thank you for your work on that library it happened to be just what I needed for my project. It's always nice to be able to thank people "in person" for the work that they've done.

    I was looking for a library that would allow me to create short samples of different tones and alerts that I could easily trigger and stop but wouldn't interfere with the mainline program, as I'm also running an OLED screen, many LEDs, switches, toggles, and some NeoPixels. I'd messed around a bit trying to create some simple work with a piezo buzzer and the general blink without delay concept when I stumbled across your library, which seemed to be doing exactly what I'd already started work on. Thus far it's been almost exactly what I've needed and it's nice to have more control over the sounds than the basic bleeps and bloops of the tone() command.

    There's only really one or two things that I could think that I'd like to see tweaked or added.

    1. It would be nice to see a "play once" type of function. Something that could be triggered and would play the riff, alert, tone, etc. one time and then stop until the playOnce() was called again. I looked into the .cpp to see if it would be something I could add, but to be honest I've just now started dabbling in class creation so I decided not to immediately try to jump into the deep end of that. I'm currently working around that by just having a simple "if(example.isEnd())" catch all in my loop to pause the samples after they've been triggered and played once.

    2. The second would be something along the lines of an "example.stop()" function that would stop the selected sample and be able to restart by the "example.play()" function call. I know that the pause function works similar to this, but the problem I've run into is that while the play() call is required the first time a sample is started, after that I have to use the pause() call to restart it after pausing, which just makes for a slightly more complex code.

    Right now I'm just working around these two minor things by creating "if...else" statements along these lines:

    Code:
    if(x == 1){
        if(example.isPaused()){
            example.skipTo(0);
            example.pause();
        }
        else{
            example.play();
        }
    }
    
    if(example.isEnd()){
        example.pause();
    }
    I have to use the "if" statement with both play and pause to trigger the same effect because after the first time that it's been played and paused the only way to trigger it again is to call the pause() function a second time. It'd be nice to simplify that down to either:

    Code:
    if(x == 1){
        example.playOnce();
    }
    
    //or even
    
    if(x == 1){
        example.skipTo(0);
        example.play();
    }
    
    if(example.isEnd()){
        example.stop();
    }
    Right now those are the only two things I could think of that would make it "better". In reality it's more about looking for a way to simplify my code and not due to any problems that I've run into with the library.

    I might be missing a feature or method of doing this that's more efficient and if you have any pointers I'm more than happy to take them.

    I know I'm probably using your library outside of its original scope as I'm using it more as a soundboard than a synth chip tunes player, but it has been working really well for my purposes and it saved me from convincing myself to finally tackle my own library creation... for now. To be fair I do feel like I'm underutilizing the full power of your library to a degree, but I have really enjoyed "composing" alerts and what not. Last night I spent about an hour with my wife working out the perfect series of tones to truly convey disappointment in a dice roll result. (Nerdy I know, but she did choose to marry me.)

    Thank you again and I'm glad to see you popping in here. I'm more than happy to take any advice or pointers that you're willing to give.

  15. #15

    Cool MusicWithoutDelay upgrade(v3.0.0)

    Quote Originally Posted by woodenbots View Post
    There's only really one or two things that I could think that I'd like to see tweaked or added.
    Hey bud,
    I got bored and updated my library to v3.0.0
    It's got all sorts of fancy stuff, such as VOLUME CONTROL 😎(This was the legendary battle I had for months between me and my 8-bit microcontroller, and I finally TAMED IT) and Sustain Override 🌊.
    Also, I listened to what you said, and I made a repeat function that plays the song a number of times without letting you do the hard work of pausing it when it reaches the end.
    So all you have to do is call
    Code:
    buzzer.play(1)
    to play one time. But is you want to play an infinte amount of times like last time, simply call:
    Code:
    buzzer.play(); //empty inside
    Also, A bunch of other stuff changed like pausing, to pause you have to call
    Code:
    buzzer.pause(true);
    and since the "play()" function has a different purpose, you need to change the old
    Code:
    "buzzer.play()"
    to
    Code:
    buzzer.update()
    Simply put, check out the readMe file, My library just got a ton better. Also Paul gave me a free Teensy
    Also, I got rid of those annoying compiler warnings you guys made fun of me for.

  16. #16
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,001
    I'm a bit sad you closed the pull request to add Teensy support. What's up with that?

  17. #17

    I did add Teensy Support

    Quote Originally Posted by PaulStoffregen View Post
    I'm a bit sad you closed the pull request to add Teensy support. What's up with that?
    I did add it. I didn't know I had to merge Pull requests. So I just "copy and pasted" it. I'm kinda an amateur when it comes to GitHub ��

    Don't worry, I'll make sure it has support even if it doesn't work

    Use MusicWithoutDelay v3.0.0 with Teensy and let me know if it works.

  18. #18
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,666
    Quote Originally Posted by PaulStoffregen View Post
    I'm a bit sad you closed the pull request to add Teensy support. What's up with that?
    Quick code scan looks like this was manually inserted? #if and all?

  19. #19
    Yeah, the code on Github is a bit behind, so I had to manually enter the Teensy support because I had new code on my laptop for the volume control.

    I'm not sure how to get around that.
    I could call "git pull origin master" but then the latest code on my laptop will be erased.

  20. #20
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,666
    Merging with conflicts is no fun, getting it done is good work.

    Interesting library planning to look at it soon.

  21. #21
    Quote Originally Posted by defragster View Post
    Merging with conflicts is no fun, getting it done is good work.

    Interesting library planning to look at it soon.
    If only there were some way to show it to many people. It's been up there on Github and Arduino's create website for 6 months, but I feel like not many people know about it. My main goal was to be able to play simple chiptunes, but I got carried away(as you can tell by the number of functions).

    If you wanna talk difficulty, I'd say about 9.5/10 especially right here.
    That skipSolver function is the meat of the computing power. It has to skip to a specific time given by the user in milliseconds.

  22. #22
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,666
    I have a T_LC with sockets and a PJRC Prop Shield LC - working wired to a breadboard to run running the example/BASIC.

    Note the example [issues/8] has a bad link to github: https://github.com/nathanRamaNoodles/MusicWithoutDelay
    should be https://github.com/nathanRamaNoodles...tDelay-LIbrary

    Click image for larger version. 

Name:	Musicwnd.PNG 
Views:	31 
Size:	642.4 KB 
ID:	14644

    The USB<>VIN trace is cut so there are extra 5V wires around.

    <edit> It Works! …. modified BASIC example with .setVolume
    Code:
          case '+':  //type '+' in Serial monitor.
            if ( mVol < 97 ) mVol += 3;
            instrument.setVolume(mVol);
            instrument2.setVolume(mVol);
            instrument3.setVolume(mVol);
            instrument4.setVolume(mVol);
            break;
    Last edited by defragster; 09-04-2018 at 02:06 AM.

  23. #23
    Is the volume muted by default on the teensy?
    If you liked the basic sketch, try the "song_Mod" example, you won't be disappointed

  24. #24
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,666
    No the default volume was fine - it worked before, just noting the setVolume works as well - I just wanted to try the ability to do +/- and it worked.

  25. #25
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,666
    I don't have buttons connected - so "song_with_MOD" was disappointing

Posting Permissions

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