Need help finishing a simple music mixer project

Haybur

Active member
Update: So glad I posted this because obviously now I fixed it. I upped the audio memory from 10 to 12, which just introduced static noise when I was using a 3.6, but I guess the 4.1 has more memory? Anyways, it's all working now. :)

Hey everyone,

I'm building a super simple music mixer that has 1 button, 4 slide potentiometers, and 5 .wav files. When the button is pressed, all the .wav files will start playing. 1-4 will have their volumes adjustable on the sliders and 5 will be set to a constant volume. Everything is working right now except the first .wav file does not play.

It is easy to mix 4 audio files but in this case, I need 5, so I did this with the audio design tool:
Audiomix.PNG
(First I tried just putting the 5th track straight into mixer 5 but for some reason it didn't work. I've tried so many things but I got this to work until it didn't which is why I'm here.)

I'm printing all the slider values and can see they're all working. I've gotten this to work in the past few days but all of a sudden it doesn't work. All my wav files right now, ONE.wav, TWO.wav, THREE.wav, FOUR.wav, FIVE.wav, are the exact same file just renamed. They are 48.4MB, 1411kbps, and 4:48 minutes long. Again, only ONE.wav is not playing when I hit the button.

Here's the code:
HTML:
#include <Arduino.h>
#include <Button.h>

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

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav5;     //xy=643,497
AudioPlaySdWav           playSdWav4;     //xy=649,385
AudioPlaySdWav           playSdWav2;     //xy=652,245
AudioPlaySdWav           playSdWav3;     //xy=652,310
AudioPlaySdWav           playSdWav1;     //xy=653,175
AudioMixer4              mix3;         //xy=892,504
AudioMixer4              mix2;           //xy=897,245
AudioMixer4              mix1;           //xy=898,351
AudioMixer4              mix4; //xy=898,633
AudioMixer4              mix5;           //xy=1110,289
AudioOutputI2S           headphones;     //xy=1316,294
AudioConnection          patchCord1(playSdWav5, 0, mix3, 0);
AudioConnection          patchCord2(playSdWav5, 1, mix4, 0);
AudioConnection          patchCord3(playSdWav4, 0, mix2, 3);
AudioConnection          patchCord4(playSdWav4, 1, mix1, 3);
AudioConnection          patchCord5(playSdWav2, 0, mix2, 1);
AudioConnection          patchCord6(playSdWav2, 1, mix1, 1);
AudioConnection          patchCord7(playSdWav3, 0, mix2, 2);
AudioConnection          patchCord8(playSdWav3, 1, mix1, 2);
AudioConnection          patchCord9(playSdWav1, 0, mix2, 0);
AudioConnection          patchCord10(playSdWav1, 1, mix1, 0);
AudioConnection          patchCord11(mix3, 0, mix5, 2);
AudioConnection          patchCord12(mix2, 0, mix5, 0);
AudioConnection          patchCord13(mix1, 0, mix5, 1);
AudioConnection          patchCord14(mix4, 0, mix5, 3);
AudioConnection          patchCord15(mix5, 0, headphones, 0);
AudioConnection          patchCord16(mix5, 0, headphones, 1);
AudioControlSGTL5000     audioShield;    //xy=1128,416
// GUItool: end automatically generated code

// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

#define NUM_SENSORS 4
const int sliderPins[NUM_SENSORS] = { A14, A15, A16, A17 };
double gains[NUM_SENSORS];
int potValues[NUM_SENSORS];

#define buttonPin1 0
Button button1(buttonPin1);

void setup() {
  Serial.begin(9600); // Starts the serial communication
  button1.begin();

  AudioMemory(10);
  audioShield.enable();
  audioShield.volume(0.85); 

  mix1.gain(0, 0.4);
  mix1.gain(1, 0.4);
  mix1.gain(2, 0.4);
  mix1.gain(3, 0.4);

  mix2.gain(0, 0.4);
  mix2.gain(1, 0.4);
  mix2.gain(2, 0.4);
  mix2.gain(3, 0.4);

  mix5.gain(0, 0.8);
  mix5.gain(1, 0.8);
  mix5.gain(2, 0.8);
  mix5.gain(3, 0.8);

  mix3.gain(0, 0.1);
  mix4.gain(0, 0.1);

  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here, but print a message repetitively
    while (1) {
      //Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}

void loop() {

  for (int i = 0; i < NUM_SENSORS; i++) {
    potValues[i] = analogRead(sliderPins[i]);
    gains[i] = (potValues[i] * 1.0) / 1023.0;
    Serial.print(gains[i]);
    Serial.print("\t");
  }
  Serial.print(AudioMemoryUsageMax());
  Serial.print("\t");
  Serial.println();

  mix1.gain(0, gains[0]);
  mix1.gain(1, gains[1]);
  mix1.gain(2, gains[2]);
  mix1.gain(3, gains[3]);

  mix2.gain(0, gains[0]);
  mix2.gain(1, gains[1]);
  mix2.gain(2, gains[2]);
  mix2.gain(3, gains[3]);

  mix3.gain(0, .1);
  mix4.gain(0, .1);


  if (button1.pressed()) {
    playSdWav1.play("ONE.wav");
    delay(10); // wait for library to parse WAV info
    playSdWav2.play("TWO.wav");
    delay(10); // wait for library to parse WAV info
    playSdWav3.play("THREE.wav");
    delay(10); // wait for library to parse WAV info
    playSdWav4.play("FOUR.wav");
    delay(10); // wait for library to parse WAV info
    playSdWav5.play("FIVE.wav");
    delay(10); // wait for library to parse WAV info
  }
  





  // if (playSdWav1.isPlaying() == false) {
  //   //Serial.println("Start playing 1");
  //   playSdWav1.play("ONE.wav");
  //   delay(10); // wait for library to parse WAV info
  // }
  // if (playSdWav2.isPlaying() == false) {
  //   //Serial.println("Start playing 2");
  //   playSdWav2.play("TWO.wav");
  //   delay(10); // wait for library to parse WAV info
  // }
  // if (playSdWav3.isPlaying() == false) {
  //   //Serial.println("Start playing 3");
  //   playSdWav3.play("THREE.wav");
  //   delay(10); // wait for library to parse WAV info
  // }
  // if (playSdWav4.isPlaying() == false) {
  //   //Serial.println("Start playing 4");
  //   playSdWav4.play("FOUR.wav");
  //   delay(10); // wait for library to parse WAV info
  // }
  // if (playSdWav5.isPlaying() == false) {
  //   //Serial.println("Start playing 4");
  //   playSdWav5.play("FIVE.wav");
  //   delay(10); // wait for library to parse WAV info
  // }
}
 
Back
Top