This lab project intends to simulate a 2D wave equation on a square mesh in real-time to produce drum-like sounds. The square mesh is generated by set of nodes arranged in a 2D planar surface. Each node exhibits the wave equation which incorporates the interaction between neighbouring nodes.
To generate a drum-like sound, an initial energy is supplied at the centre node within the mesh while all other nodes will have no energy initially. The energy then circulates through all other nodes radially outwards guided by the wave equation. The collective behaviour of all nodes together generates the drum-like sound.
One of the requirement of this project is to generate different timbers of the drums which can be selected by means of switches. Different timbers can be generated by varying the value of the physical parameter called rho (ρ) which uniquely generates different timbers. The value of rho (ρ) was made switch configurable to generate different timbers as required.
2. RTL schematics of the system
The RTL schematics of the complete system is shown below in figure 1.
The State machine for single is node is shown below in figure 2. The state machine for the single is very simple and incorporates only three states namely RESET, COMPUTE and HISTORY.
As can be seen from the above state machine diagram, the state machine is very simple. The various states in this state machine are explained below.
Upon reset, each Drum Node enters the RESET state. In this state, various node parameters are set and then the initial energy is imparted to the system. In the next cycle, the system transitions to the COMPUTE state.
In this state, energy level of each node is calculated as guided by the wave equation for each node by using the energy levels of the neighbouring nodes. In this next cycle, the each node transitions to HISTORY state.
In this state, the last computed energy level is stored in the history to be used to compute the further energy levels in the future.
Each node continues to loop though COMPUTE and HISTORY states until the wave damps down or RESET is pressed.
3. Design and Testing
The design for this system was implemented incrementally in three stages namely audio interface implementation, generating single node of drum and finally instantiating a mesh of nodes to generate drum sounds.
3.1. Audio Interface:
In the first stage, a simple square wave is generated and outputted to the audio port. The simple square wave module comprised of an Audio controller, a Reset Delay module and a VGA_Audio_PLL. This square wave implementation was borrowed from one of the audio examples implemented by Scott McKenzie and Miles Pedrone. This hardware audio interface is a Wolfson WM8731 codec which is controlled by an I2C interface. The audio coded produces 16-bit 2’s complement numbers. The 16 bit numbers should be considered as fractional values within the range +/- 1 volt.
This audio controller module takes in reset delay generated by the Reset_Delay module and the audio control clock of 18 MHz generated by the VGA_Audio_PLL. Apart from these, the audio controller takes in two audio-in signals in quadrature and outputs the audio through the speaker connected to the audio jack on the board. All these modules were tested by Scott and Miles and were heavily used in many applications and previous projects and as such there was no trouble implementing the audio interface without the need for any significant testing. The quick test for these modules was to make sure that the system outputs a square wave audio signal.
3.2. Single Drum Node Generation:
After making sure that the audio interface is implemented correctly and testing for the audio signal over the speaker, it was time to generate a single node whose energy level is guided by the drum wave equation for a square mesh. This single node generation comprised of a simple state machine shown in figure 2 in the previous section. Upon implementing one node, the same was tested by applying initial energy to the node and applying zero energy levels for its neighbouring nodes. This single drum node was tested to generate different timbers of drum sounds by configuring rho (ρ) with different values set by the switches. Finally, this module was tested for various damping levels which was also configured by switches.
3.3. Instantiating square mesh of Nodes
After making sure that the node works fine as per the wave equation for drum, multiple nodes were instantiated in a square mesh structure to generate drum sounds. One of the requirement for this project was to generate maximum number of nodes possible to simulate drum sounds. The limitation for this was expected to be the limited on board resources such as multipliers and logical elements. However, during the implementation, the real challenge was with respect to compilation time. As the number of nodes increased, the compilation time also increased significantly from 1minute for one node to around 6 minutes for 5X5 nodes to couple of hours for 10X10 and higher sets of nodes.
To reduce the compilation time two approaches are used. In the first approach, the whole system was compiled incrementally. In other words, instead of compiling 5X5 nodes directly, one node was compiled first followed by one row of nodes and then finally 5X5 nodes. This reduced the compilation time significantly as the system did not have to compile the previously compiled part of the system.
In the second approach, the symmetry in the square drum mesh structure was exploited. In other words, the drum square mesh structure exhibits symmetry across horizontal and vertical sets of nodes. As such, if we divide the whole square mesh structure into 4 quadrants, it was sufficient to calculate the energy levels of one quadrant of nodes and replicate the same to remaining quadrants symmetrically. This is shown in the RTL schematics of the complete system in figure 1. The nodes which are greyed out were the symmetrical nodes. They copied the energy levels of the corresponding node from first quadrant which had non-greyed nodes which performed the actual computations. This helped to quickly increase the number of nodes by factor of 4. After implementing 5X5 nodes with actual computations another three sets of 5X5 nodes were instantiated which only copied the energy levels from the first quadrant. This lead to quick implementation of 10X10 nodes.
Finally, the complete square mesh structure of nodes were tested for different rho and eta (damping factor) values to generate different timbers of drum with different damping levels.
The system did not have any software design as the whole system was implemented in hardware.
The project implemented the lab successfully. The system was successful in generating multiple timbers of drum sounds with a switch control. The damping of the drum sounds was controlled by setting different values to the damping constant eta which was also switch configurable. The system implemented a 5X5 node with 4 quadrant symmetry thus mimicking 10X10 node square mesh structure. The different timbers of drum sounds along with Hanning FFT window of their actual power spectrum are shown below. As can be seen from figures Drum sounds, different timbers could be clearly differentiated by energy levels and spaces within the audio signal components. The power spectrum of both these timbers of drum sounds are also shown below.
This section documents the wave equation that guides the drum node. The equation is mentioned below.
In the above wave equation,
uni,j à current energy level of node at position (i,j)
un+1i,j à next energy level to be computed for node at position (i,j)
uni,j à previous energy level of node at position (i,j)
ρ à rho: defines the timber of the drum sounds uniquely
Ƞ à eta: damping factor
6. Parallelization scheme used
The square mesh structure of drum nodes can be implemented in two ways namely by means of fine grained parallelism or course grained multiprocessors. Challenges with multiprocessors was to instantiate multiprocessors each tended to set of nodes. Dividing the nodes amongst various multiprocessors was a difficult task. Also, all the nodes needs to be in sync to output a good drum sound without much of disturbance. Achieving this while different nodes were processed by different processors was a challenging task. This required that all the microprocessors were synchronized.
On the other hand, the fine grained parallelism is faster as the whole system is implemented in hardware. The major challenge with fine grained parallelism was to instantiate all nodes correctly in the hardware since there were so many nodes each with multiple IO connections. This was easily solved by writing a script in Matlab to generate the code that instantiates required number of nodes with correct connections. Also, with increased nodes, the compilation time was increasing tremendously. This was also resolved by exploiting symmetry in the drum square mesh structure and employing incremental compilation. Thus, the fine grained parallelism was faster and easier to implement. Thus, this project used fine grained parallelism for implementation.