In this project the hardware video buffers were implemented with 16 bit color. This demanded a reduction of resolution for both video-in and the HPS graphics to 240p. This requiered modifing all of the video drawing code that we used to enforce this. Additionally the pixel calculations had to be changed slightly to account for the change in width for address calculating in the memory.
The sound library from this project is an easy to use method for playing samples on the De1. There are only two main functions in the library that need to be called (initAudio and startSound). The initAudio function sets up the sound envierment and the startSoud function sets a sample to play with a set volume (amplitude). Internally the library also uses two additional functions load and play as well as a struct sample. The sample struct contains all the infromtation that is requiered to play that particular sound sample. This includes a pointer to the region in memory where the actual sample is stored (as 32 bit signed numbers format) as the number of samples in the sound (length of the array). This struct also includes in the info for playing the current sample (the amplitude, current sampleNumber and if it's playing).
The init audio function first defines the pointers to the audio system on the axi bus and allocates space for storing all the sample structs. It then calls the load function for each of the samples passing a struct pointer as well as file name to load. Finally it creates a pthread for the play function to run it so other tasks can continue concurrently.
The load function is the function that is responsable for reading the sound samples from the file system and putting them into memory. First the full path for the file is calculated and the actual wav file is open. Next the relevent information from the headder is read and parced (e.g. number of samples/channels, propper format). Enough space to fit all the samples is then allocated on the heap. Which is then filled by readding through all the samples within the audio file and converting them to a raw data stream of 32 bit values.
The play function is the most important one for the actuall library and runs in its own detecated thread. This function waits for there to be room in the fifo_buffer for the audio chip. It then goes trhough every sample adds its current sample magnitude (* amplitude) if its playing. The total magnatude of all samples is then sent to the DAC's fifo buffer for each channel.
The last function (which is called most often) is startSound. This function sets the parameters to start playing one of the samples from the begining with the chosen amplitude.
The etch a sketch is the first program that we created to demonstrate our hit detection system. The program is made up of a few parts all running in their own thread. The first is the sound thread outlined before. This is slightly modified to always play sample one on a loop as background music. There is also another sound that play whenever a pixel is filled in and one for when the screen is cleared.
The screen is cleared by the blank thread. This thread first truns off echo and canonical mode. This makes it so any keyboard inputs go directly to the program without waiting for a return/enter. This thread just blocks on waiting for any keyinput in the terminal. When one is recieved the terminal is cleared and repalaced with a success message, as well as the cleared sound being started and the VGA screen being wiped to transparent.
The most important thread is the one running the etch function itself. The function cycles through all the hitboxes and checks if any of them have at least the set number of pixels (limit) detected. If it is the function detToPix is used to determine what VGA corrdinates it coresponds to. These cordinates are filled in on the screen and a sound is played if they weren't colored previously.
The drum set is the original demo that we had planned for this system. This program generates a user selectable drums of a random color at the botom of the screen. It then calculates the hitbox coordinates for the drums and converts it to the address range in the detect memory buffer.
The program then prompts the user for a folder which is used to determine whcih subfolder (filled with its own set of wav files should be used as samples). These samples are then loaded into memory to play. Finaly the program looks through the regions in the relevent hitboxes and strart the coresponding sample if it hasn't been played in the last 1/4s.
The image drivers were the last application of the system that was set up. This utalizes a premade library found online to read PNG files and convert them into an array in memory. The data in these files is then read in the pixels that corespond to those that are displayed on the screen. The image data is convered from a standard 24bit RGB to the 16bit RGB that the graphics is using with a simple macro. This data is finaly simply copied over to the HPS video buffer.