skip to main |
skip to sidebar
I have researched the ways to add sound effects using c code and OpenCV. The best way appears to be to use a Musical Instrument Digital Interface (MIDI) voice. MIDI works by transmitting digital data about the pitch, intensity and length of notes, for example.
In the code I set up sound as an integer variable to include:
- Frequency (as a floating point number)
- Duration (as an integer variable)
- Volume (as an integer variable)
- Voice (as an integer variable)
- Tempo (as a floating point number)
Volume ranges from 0 – 127, or off to loudest
Voice ranges from 0 – 127, each number representing a different voice or instrument effect
This took some time for experimentation and research to find the noises I wanted to include in the game.
A sample of the code looks like this:

As the game needs to include text I have carried out some research into the font options available using OpenCV and then carried out some experiments with these.
Text items include:- Initialisation
- Score
- Countdown
- Game over
- High score board
This is an example of the initialisation screen and the font used throughout the game.