1

We designed a big piano with 15 buttons on it. Every button has a proximity sensor. Whenever users interact with the sensor a specific sound plays for that button. My code is working fine for this purpose but now I want to add background music. Our piano button sound should play on top of that background music. I am using tmrpcm library, and I already added a bg music but when I interact with the sensor, bg music stops and starts from the beginning right after the piano button sound stops. Is there a way to play a sound without interrupting a bg music. Any help will be appreciated.

1
  • 1
    use two arduinos – jsotola Sep 5 '20 at 19:03
1

Assuming you are using an Arduino Uno, You didn't say. As there are many Arduino platforms these days.

As the tmrpcm library is using the PWM (Pulse Width Modulator) HW (Hard Ware) to recreate the sound waves from the WAV file on the SDCard, the PWM is not available for creating the sounds from your piano application (you didn't say what piano application you were using). That said, it is not impossible to re-write both applications to SUM the two wave forms together mathematically before resampling the SUM and writing that sample value to the PWM HW to simulate the SUM of the two wave forms. However, this is likely not trivial and it is also likely the Arduino Uno processor (an Atmel ATmega328P) will not be powerful enough (perform the math fast enough) to keep up with normal sound playback.

It would likely be much simpler to use 2 Arduino Uno boards and sum the sound from the sound file application and the piano application using analog techniques external from the Arduno Uno boards.

3
  • I think a single Uno could be made to do it, but if expediency is an issue, one should just use two Arduino Unos. – Gabriel Staples Sep 6 '20 at 7:47
  • 1
    Perhaps you are right @GabrielStaples. But there may be more problems to solve than the OP (or anyone) may want to deal with. Can the tmrpcm library deal with WAV files of different sampling rates? If so, then the piano application would have to be adjusted to create the same note at these new sampling rates. Or the Arduino Uno would have to deal with the differences in sampling rates by re-sampling either the WAV file data or the piano data. – st2000 Sep 6 '20 at 13:51
  • Yeah, it would take a lot of effort no doubt and require a lot of advanced skills and problem-solving. Could be a fun project for those who like to really push the limits of the Arduino, but just a nightmare for those who just want to get the desired results as soon as possible. And if one doesn't have the required skills up-front, and can only work on this nights and weekends, this could be a 3 yr project. I've had many of those: I start something I have no idea how to do, so it has taken me 3 yrs to eventually learn all the pieces and study the datasheet and figure it out. – Gabriel Staples Sep 6 '20 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.