ikcomponeer blog part 2 — mixdown agent

Bertus van Dalen
3 min readMar 20, 2018

--

The website ikcomponeer.nl has been around since 2009. It contains eight recordings by the Dutch Metropole Orchestra. These recordings are cut to pieces like a jigsaw puzzle and presented in groupings per instrument section. Children may arrange the piece differently and experiment with the sounds, or they may try to make the piece of music as it was recorded. When saving their composition the system makes an mp3 mixdown that can be retrieved in a playlist and listened to, with parents or in the classroom with fellow pupils and a teacher. At its height there were a couple of hundreds of users per day of which 200 stored a composition to the playlist. Because the project is not multilingual these are mostly Belgian (Flemish) and Dutch users.

But alas, now Flash is not well supported for general purposes any longer so the usage is now declining. To make it future proof it will migrate from Flash to Angular and from PHP and MySQL to ASP.NET Core (C#) on Azure and table storage. This series of blog posts will cover the adventures. This post is about the mixdown agent.

The mixdown agent uses ecasound to create a mixdown based on a composition. A composition is a list of MP3 files that are played in a sequence where they may sound at the same time, overlap, or play after one another. The task of the mixdown agent is to turn this composition into one MP3 file by making a so called mixdown. This MP3 file is sent to a location from where it can be played in a playlist.

To make the mixdown it is best to use a linux system because the most handy programs to make the mixdown based on a command, are available for Linux and not for Windows. An important program for this purpose is Ecasound. I found out the cheapest and most robust option is to buy a mac mini. The mac mini will start up when power would go off the grid in case that may happen. You can configure it such that it will start the PHP server again, where you can run scripts to create commands that will run a program to create mixdowns. A cron process that runs each minute will go into a loop where it kicks off a PHP script each second. This PHP script will see if a lock is in place — when the lock file is there it means another process is already running and the script will end, after all one second later another instance will run. When there is no lock file it will

  1. create a lock file owned by itself,
  2. get a mixdown task from a storage queue,
  3. see if all the necessary files are already on local hard disk and
  4. if necessary download them,
  5. create a mixdown,
  6. upload it to a storage container in Azure
  7. publish a message to notify other systems that a mixdown is there,
  8. destroy the lock file and
  9. exit.

The source code that will do all of this is here on BitBucket. The most important file is the front controller that is called each second by the cron job. When you are a music technologist or programmer I hope it will be helpful to you.

--

--