Bringing Audio Loopers into the Digital World

This week saw a lot of time invested in learning about and building an SFML application, and had a massive leap in progress. Beginning with a barely-working audio I/O script, and ending with a fully functional basic audio looper, it’s safe to say the project is well off the ground. Progress included getting multiple audio loops to play, as well as recording audio with immediate playback.

Multiple Audio Loops

The first task this week was learning how SFML could play multiple audio streams, how those would be controlled, and how performance would be. the sf::Music object works just like any other C++ datatype, meaning an array of musics can exist using the following code:

sf::Music[10] musics;

Currently, this array is static and would only allow up to 10 audio streams to play at once. However, it wouldn’t be difficult to create a function that allocates a new array and removes the current, essentially creating a dynamic array of audio streams.

Next, learning to control the array of Music objects needed to be addressed. Because this is an array of objects, using a standard C++ for loop and playing/pausing/stopping all objects in the array will work:

for (int i = 0; i < musics_len; i++)
{
musics[i].play();
}

where musics_len is the number of loops in our array, tracked manually. The worry I had with using this was performance, whether each loop would be offset by not executing “play” at the exact same time. However, I couldn’t find any negative effects on the sound played from my speakers.

Recording Audio

Next, I wanted to tackle recording audio and see how it could be integrated with the aforementioned music array. SFML has a tutorial for recording audio, so I began there, taking a simple audio input and saving it to a file. After some trouble shooting, I managed to get this to work. There is some tradeoff here, in that saving audio to a file prior to playback could be detrimental to performance. However, it is necessary to be able to perform functions later, such as reversing the audio.

Next, it would be easy to plug this audio into the music array. I already had a function for loading audio into the array, so I simple parsed in the file name and it got the new audio in. Finally, simply executing the function to play all audio in the array would add this to the stream. There is one problem with this in that it would reset to the beginning of the audio when recording stops. This may not be an issue if we time everything and restrict recording to a certain time frame in a certain window, but that will need to be determined later.

Leave a comment

Your email address will not be published. Required fields are marked *