DacAudio 4.0 Released

Version 4.0 is a main update to the DacAudio software as it now adds in one main feature and some nice enhancements. The main part of this release is the ability to play more than one sound at once, whatever that sound is, whether it’s 2 WAV’s or a WAV and a music score, it makes no difference, mix them together as much as you want and output them together! Download it from the DacAudio downloads page. This is a facility I’ve wanted right from the first version but has always been put on the back burner as more important updates/fixes came first. In the old days of sound and computer sound the mixing was done using analogue electronics but now and with the DacAudio library the mixing is done digitally “on-the-fly” so no additional components are required. The DacAudio “Play” function has been expanded to have another parameter and now looks as follows (simplified):

There is now an optional parameter called Mix, if you pass this and it’s set to True then the sound will mix with whatever is currently playing. If you don’t pass it or set it to False then the sound will stop anything currently playing an become the new and only sound that is playing, which is what happened in previous versions by default.

Here’s a simplified example of how you would mix sounds:

The first sound starts and if there was anything playing prior to it, it will stop and this will be the only sound. The second sound then starts and because we’ve passed the second argument as “true” then this sound will play at the same time as the first being “mixed” in together.

Other additions are :

  • Ability to set buffer size more easily when creating DacAudio object
  • All sounds can now be repeated forever – originally this was a property of the music score object only
  • All sounds can now be repeated a certain amount of times – originally this was a property of the music score object only

Buffer Size
Setting the buffer is just now an easy option of passing the number of bytes you want when creating the DacAudio object, not passing anything will set it to a default (currently 4000 bytes). Generally unless you have a specific need to change this I would leave it alone, getting the value wrong can affect the sound play back dramatically. The 4K default is not too much memory used up on an ESP32 system (it has around 300K plus available to the normal coder) and will allow for very slow code in the main loop. For example my Frogger Project runs quite slowly in the main loop (because of sending a lot of data to the screen over SPI) but 4K is still plenty. Too low a value causes sounds to slow down and too high a value can lead to excessive time spent filling the buffer (especially with multiple sound mixes). Whatever you choose, here’s two examples

Repeat Forever
A new option for all play items (WAV’s, music scores, single notes, sequences, whatever can be played) is to play forever. Just set the property of the play item to true to enable it and the sound item will repeat each time it ends, i.e.

Repeat “X” times
Any play item can be set to repeat a certain number of times and then stop, to use it set the Repeat property before setting it to play. Setting it after it has started playing will have no effect. e.g.

Repeating within sequence
The ability to repeat any sound x times or forever can be applied to sequence play items and to the play items within the sequence, for example:

This will play the sequence of the two items (ForceWithYou and Music) twice (once plus 1 repeat). But as those subitems (ForceWithYou and Music) are Play Items we can also set them to repeat, for example;

This will play ForceWithYou three times (once plus 2 repeats) followed by the Music Score once and then repeat all of that another time. You can even set a PlayItem within a sequence to play forever but unless it’s the last part it would make no sense as then you would never play anything in the sequence beyond that item.

New and updated examples are available in the library highlighting the features above and a video will be released soon demo-ing the new features.