From UBC Wiki


Authors: Seiyoung Ahn, Alyssa Zhao

What is the problem?

For this project, we will implement a Prolog program that will allow users to specify a piece of music they wish to play, whereby the program will output an audio file containing a piano rendition of the piece. The user will be able to provide this digitized "sheet music" in the form of a sequence of notes, as well as a MIDI file. The output of the program will likely be in the form of a WAV file.

What is the something extra?

In addition to allowing the user to play a MIDI file, we also plan on implementing a means by which the user is able to transpose the given composition. The user will be able to specify the number of semitones they wish to move up or down from the original key, as an integer within the range [-12, +12].

What did we learn from doing this?

Following the completion of this Prolog project, we were able to draw several conclusions from our experience using the language. Firstly, we found that the syntax Prolog uses (pattern matching in particular) enables the generation of incredibly concise code; however, this comes at the price of general readability. Accordingly, the naming of variables and predicates plays a crucial role in ensuring the code is understandable by both current and future developers.

One of the areas where Prolog is lacking is in its absence of libraries and other such external support. Compared to more popular languages such as Python, Prolog does not have nearly as much support for certain file types, encodings or mathematical/statistical calculations (e.g. Fast Fourier Transforms that would be useful for pitch shifting). Furthermore, we also had some difficulties debugging our program, which were only amplified by Prolog's ambiguous error messages.

Although Prolog is most well-suited for applications involving logical reasoning and backtracking, we found that it was also performed adequately with regards to solving our musical problem. We were able to implement our version of a piano-playing application in a concise manner, and, due to the declarative nature of Prolog, achieved a high level of confidence in the fidelity of the relationships we defined. Future considerations for this project include the addition of modules to allow pitch shifting through the use of byte manipulation in the form of Fast Fourier Transforms, as well as the ability to play several notes simultaneously without introducing an unacceptable level of distortion. This would involve the use of some heavier mathematical transformations at the byte level, and algorithms to both optimize the resultant volume levels and minimize sound clipping.

Links to code etc