Lab 5

In this lab we are going to be testing two algorithms that scale 16 bit integer sound samples with a scaling factor. The first algorithm we will test will be straight multiplication and the second  algorithm we will test will be multiplication with bit shifting. Both algorithms will be tested on arm64 and x86 architectures.

The first algorithm we tested was straight multiplying. We took the volume and multiplied it by the sound sample in a loop and stored the new scaled sample in the same array. It looked like:

float volume = 1.0;
for(int i =0;i<size;i++){
myArray[i] = myArray[i] * volume;
}

The Second algorithm we tested was similar but we converted the volume to a 32 bit integer, converted the array value to a 32 bit integer with casting, multiplied the two values then bit shifted them to the right by 16 bits to convert them back to 16 bit integers and stored the result. It looked like this:

float volume = 1.0;
int32_t result = volume* 65536;
for(int i =0;i>16;
}

This approach has the advantage in theory of speeding up the casting process with bit shifting. When both approaches were tested using 1 million samples they were able to scale the samples in 4 seconds. A difference in algorithm speed could be seen only when testing 100 million samples but even then the difference was a couple 100 ms for the bit shifting algorithm. The goal of this lab was to test if the algorithms could keep up with scaling 44100 samples per second on two channels. Both algorithms could scale 500 thousand samples in less then two seconds safely allowing them to process the two 44k sound sample channels.

Testing optimization settings on the compiler greatly speed up the algorithms. Both of these tests were conducted without optimizing to avoid the risk of the compiler deleting code as it is not used later. However after performing initial tests I recompiled both algorithms with -03 and tested 10 million samples. Algorithm 1 and 2 both went from 43 down to 10 ms run time.
 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s