Generating music via an alternative GAN

Another example of music generation is also included in the Chapter_3 source folder, called Classical-Piano-Composer, with the source located at https://github.com/Skuldur/Classical-Piano-Composer, developed by Sigurður Skúli. This example uses a full set of Final Fantasy MIDI files as source inspiration for the music generation and is a great practical example for generating your own music.

In order to run this sample, you need to run the lstm.py first using the following command from the Classical-Piano-Composer project folder:

python lstm.py 
or
python3 lstm.py

This sample can take a substantial time to train, so be sure to open the file and read through what it does.

After the models are trained, you can run the generator by running the following:

python predict.py
or
python3 predict.py

This script loads the trained model and generates the music. It does this by encoding the MIDI notes into network input in terms of sequences or sets of notes. What we are doing here is breaking up the music files into short sequences, or a music snapshot if you will. You can control the length of these sequences by adjusting the sequences_length property in the code file.

The great thing about this second example is the ability to download your own MIDI files and put them in the appropriate input folder for training. It is also interesting to see how both projects use a similar three-layer LSTM structure but vary quite widely in other forms of execution.

If you want to learn more about audio or music development for games and especially for Unity, check out the book Game Audio Development with Unity 5.x, by Micheal Lanham. This book can show you many more techniques for working with audio and music in games.

Both music samples can take some time to train and then generate music, but it is certainly worth the effort to run through both examples and understand how they work. GANs have innovated the way we think of training neural networks and what type of output they are able to produce. As such, they certainly have a place in generating content for games.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset