Building a music player

Does anybody know if you can have multiple melodies and Note durations for each induvial melody all playing at once on four different speakers, kind of like harmony:

int melody1[] = {
  // Add the corresponding note frequencies
  NOTE_C4, NOTE_F4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_D4,  // We wish you a merry Christmas,
  NOTE_D4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_C4,  // We wish you a merry Christmas,
  NOTE_C4, NOTE_A4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_D4, // We wish you a merry Christmas
  NOTE_C4, NOTE_C4, NOTE_D4, NOTE_G4, NOTE_E4, NOTE_F4 // And a happy new year!
};

int melody2[] = {
  // Add the corresponding note frequencies
  /*NOTE_C4, NOTE_C4, NOTE_C4, NOTE_B4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_D4,  // We wish you a merry Christmas,
  NOTE_D4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_C4,  // We wish you a merry Christmas,
  NOTE_C4, NOTE_A4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_D4, // We wish you a merry Christmas
  NOTE_C4, NOTE_C4, NOTE_D4, NOTE_G4, NOTE_E4, NOTE_F4 // And a happy new year!
  */
};
int melody3[] = {
  // Add the corresponding note frequencies
  /*NOTE_C4, NOTE_F4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_D4,  // We wish you a merry Christmas,
  NOTE_D4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_C4,  // We wish you a merry Christmas,
  NOTE_C4, NOTE_A4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_D4, // We wish you a merry Christmas
  NOTE_C4, NOTE_C4, NOTE_D4, NOTE_G4, NOTE_E4, NOTE_F4 // And a happy new year!
  */
};
int melody4[] = {
  // Add the corresponding note frequencies
  /*NOTE_C4, NOTE_F4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_D4,  // We wish you a merry Christmas,
  NOTE_D4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_C4,  // We wish you a merry Christmas,
  NOTE_C4, NOTE_A4, NOTE_A4, NOTE_AS4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_D4, // We wish you a merry Christmas
  NOTE_C4, NOTE_C4, NOTE_D4, NOTE_G4, NOTE_E4, NOTE_F4 // And a happy new year!
  */
};

// Note durations: 4 = quarter note, 8 = eighth note, etc.
int noteDurations1[] = {
  4, 4, 8, 8, 8, 6, 4, 4,
  4, 4, 8, 8, 8, 6, 4, 4,
  4, 4, 8, 8, 8, 6, 4, 4,
  8, 8, 4, 4, 4, 4,
};
int noteDurations2[] = {

}
int noteDurations3[] = {

}
int noteDurations4[] = {

}```
Thanks.

Direct Digital Synthesis (DDS) is one approach, generally requires a fast MCU.

2 Likes

Thanks, I will try that

You can try

or

Both do DDS on the UNO.

a7

1 Like

Cool, I'll try that

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.