Step-based volume adjustment

Hi there, I'm pretty new to Arduino, with a basic Arduino Uno set. I have a project that essentially requires the following things:

  • Plays two different set of sounds into right and left earphone channels separately - let's call them sound A in the right, and sound B in the left
  • Two buttons/triggers to vary only sound A. If I press one button, sound A increases in volume, if I press the other button, it decreases in volume in steps, eg. by 5 decibels. This process repeats over several tracks.
  • A way to record how many times the tracks were played and the respective decibels/decibel changes, if any.
    I'm having a hard time understanding what parts I might need to go about achieving this. A friend recommended the MP3 shield, but will I need earphone jacks? An external battery to run this separate from the computer? Any help would be really appreciated!

Be aware that this project can not be done with just an Arduino Uno. Also it is a complex processor intensive project, it might sound simple to you but that is because you have no idea yet about what is needed.

I would advise you to look at the Teensy 3.6 board and the I2S sound output board they sell. They have developed a graphics interface for complex projects like this.

This page tells you about it in the long video

I did some looking around and was further recommended to use Robertsonic’s WAV Trigger, which seems to be able to do what I need for now.

What I’m trying to do now is actually have it activate the sequence with a pushbutton. (Later, I’ll redefine it to increase/decrease volume accordingly.) I’ve taken bits from the original WAV Trigger code, as well as a basic two pushbutton trigger code.

/* Libraries */
#include <Metro.h>
#include <AltSoftSerial.h>
#include <wavTrigger.h>

/* Define buttons */
int buttonBpin = 8;
#define LED 13                // our LED
wavTrigger wTrig;             // Our WAV Trigger object
Metro gLedMetro(500);         // LED blink interval timer
Metro gSeqMetro(6000);        // Sequencer state machine interval timer
byte gLedState = 0;           // LED State
int  gSeqState = 0;           // Main program sequencer state
int  gRateOffset = 0;         // WAV Trigger sample-rate offset

void setup() {
  pinMode(buttonBpin, INPUT_PULLUP); 

    // If the Arduino is powering the WAV Trigger, we should wait for the WAV
  //  Trigger to finish reset before trying to send commands.

  // WAV Trigger startup at 57600
  // Send a stop-all command and reset the sample-rate offset, in case we have
  //  reset while the WAV Trigger was already playing.

void loop() {

  if (digitalRead(buttonBpin) == HIGH)
    int i;
          switch (gSeqState) {
          // State 0: Demonstrates how to fade in a music track 
          case 0:
              wTrig.samplerateOffset(0);            // Reset our sample rate offset
              wTrig.masterGain(0);                  // Reset the master gain to 0dB
              wTrig.trackGain(2, -40);              // Preset Track 2 gain to -40dB
              wTrig.trackPlayPoly(2);               // Start Track 2
              wTrig.trackFade(2, 0, 2000, 0);       // Fade Track 2 up to 0dB over 2 secs

          // State 1: Demonstrates how to cross-fade music tracks
          case 1:

              wTrig.trackGain(1, -40);              // Preset Track 1 gain to -40dB
              wTrig.trackPlayPoly(1);               // Start Track 1
              wTrig.trackFade(1, 0, 3000, false);   // Fade Track 1 up to 0db over 3 secs
              delay(2000);                          // Wait 2 secs
              wTrig.trackFade(2, -40, 3000, true);  // Fade Track 2 down to -40dB over 3 secs and stop
          // State 2: Fade down music and start looping dialog
          case 2:

              wTrig.trackFade(1, -6, 500, 0);
              wTrig.trackPlayPoly(4);               // Start Track 4 poly
              wTrig.trackLoop(4, 1);                // Enable Track 4 looping

          // State 3: Honk the horn 2 times
          case 3:

              wTrig.trackPlayPoly(5);               // Start Track 5 poly
              wTrig.trackStop(5);                   // Stop Track 5
              wTrig.trackPlayPoly(5);               // Start Track 5 poly
              wTrig.trackStop(5);                   // Stop Track 5
          // State 4: Fade out and stop dialog
          case 4:

              wTrig.trackLoop(4, 0);                // Disable Track 4 looping
              wTrig.trackFade(4, -50, 5000, 1);     // Fade Track 4 to -50dB and stop
          // State 5: This demonstrates playing musical instrument samples, with decay on
          //  release
          case 5:
              wTrig.masterGain(-8);                 // Lower main volume
              wTrig.trackPlayPoly(6);               // Play first note
              wTrig.trackPlayPoly(7);               // Play second note
              wTrig.trackPlayPoly(8);               // Play third note
              wTrig.trackFade(6, -50, 5000, 1);     // Fade Track 6 to -50dB and stop
              wTrig.trackFade(7, -50, 5000, 1);     // Fade Track 7 to -50dB and stop
              wTrig.trackFade(8, -50, 5000, 1);     // Fade Track 8 to -50dB and stop
          // State 6: Demonstrates preloading tracks and starting them in sample-sync, and
          //  real-time samplerate control (pitch bending);
          case 6:
              wTrig.trackLoad(6);                   // Load and pause Track 6
              wTrig.trackLoad(7);                   // Load and pause Track 7
              wTrig.trackLoad(8);                   // Load and pause Track 8
              wTrig.resumeAllInSync();              // Start all in sample sync
              for (i = 0; i < 100; i++) {
                gRateOffset -= 200;
              for (i = 0; i < 100; i++) {
                gRateOffset += 200;
              wTrig.stopAllTracks();                // Stop all
      } // switch
      // Increment our state
      if (gSeqState > 6)
          gSeqState = 0;
  } // if (digitalRead(buttonBpin)

  // If time to do so, toggle the LED
  if (gLedMetro.check() == 1) {
      if (gLedState == 0) gLedState = 1;
      else gLedState = 0;
      digitalWrite(LED, gLedState);
  } // if (gLedMetro.check() == 1)

  // Delay 30 msecs

However, I’ve been getting the following error message: (Using Windows 10, Arduino 1.8.5, an Arduino Uno and WAV Trigger board)

C:\Users\sixsmith\AppData\Local\Temp\ccA3y1EC.ltrans0.ltrans.o:(.rodata+0x6): undefined reference to `Print::write(unsigned char const*, unsigned int)’

c:/program files/windowsapps/arduinollc.arduinoide_1.8.10.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/…/lib/gcc/avr/4.9.2/…/…/…/…/avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to `main’

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

Wondering if anyone is able to help with this?

It looks like you have not installed all the libraries correctly

When you post code with obscure libraries you should also include links to the libiary.

Apologies! Here are the individual libraries.

WAV Trigger

I deleted them and reinstalled them, but I seem to be getting more error messages:

Arduino: 1.8.5 (Windows Store (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\sixsmith\Documents\Arduino\libraries\Metro\Metro.cpp:42:16: warning: extra tokens at end of #ifdef directive



c:\program files\windowsapps\arduinollc.arduinoide_1.8.10.0_x86__mdqgnx93n4wtt\hardware\tools\avr\bin../lib/gcc/avr/4.9.2/../../../../avr/bin/ar.exe: unable to rename 'core\core.a'; reason: File exists

exit status 1
Error compiling for board Arduino/Genuino Uno.

I should probably point out that I could get the WAV Trigger's example file to work fine previously, although now it doesn't seem to be running either (same error message appears).

When I tried it I had to extract the Metro folder from the Metro-Arduino-Wiring folder and just put it in the libraries. Did you remove the "-Master" bit from the other folders before you put them in the libiary folder?

It then compiles on my system.

Restart the IDE when you have made these changes.

Master is just a github thing, its the branch in the repo, remove it