Introduction:
In this assignment, we are asked to do a simple program to generate with audio data. However, I am not strong in programming, and I only had one course in C++ programming, so the best thing I can do is using C++ language to write a simple program. During first few classes, we are introduced PortAudio, so for the first assignment, I try to do something with PortAudio; at least understand its basic commands. From PortAudio tutorial, one can understand how to open a default stream, so for first assignment, I am using the given stream in PortAudio, and try to do something with it. After all, I have created three simple programs with different functions.
Purposes:
The first program I made, which is simply to generate repetition of a tone, and for each repetition the program will increase the tone's sleep time, so the user will hear a sound become longer and longer. The reasons I made this program are very simple, which is to allow me to understand the basic commands of PortAudio. In this case, one can understand how to open a stream, and understand what sleep time for audio data is. More importantly, I do believe this is one important thing that makes a tone sounds longer because I think there are sometimes that we do not want a tone with only one sleep time. With different sleep time, a simple tone can become much more interesting, and we can use it in many different situations, even though this is only a simple process.
The second program I made, which is generating a sine wave beep tone. I change the tone to sine wave from the first one because sine wave tone sounds little smooth and better. However, this program works differently with the previous one. This one is repetition of beep, but instead increasing the length of the tone, it decreases the length between each tone, so users are able to hear that the program is beeping faster and faster. This program will generate beeps just like the countdown of a bomb that we watch from the movies.
After some ideas of mixing sound, I also try to do something with the loudness of the sound. As we know, the loudness of sound is related with its amplitude in logarithmic scale. The 3 rd program is increasing the sine wave amplitude for each repetition, so the user will hear the beep become louder at each time.
Approaches:
Basically, for the first program, I just use the modified C++ version that Eric Johnson posted in note board. However, I use his modified version for callback function, error function, and opening stream, which are also posted at PortAudio tutorial for C version. I have to give the credit to Eric because he modified the code to C++ version, which really helps me a lot to make this program. After all, I wrote a loop function for playing a tone, which generates repetitions of a tone. I also add the function that produce the tone with longer sleep time for each repetition. In this case, the program will increase each repetition by 100 milliseconds. Instead of opening and closing the stream again and again for the repetition, I add another command of Pa_sleep() to guarantee there are silence between each tone.
For the second program, I use the basic formula to create a sine wave tone in call back function, which is y = Asin (2(pi)fn/Fs+phase) with f = frequency, Fs = sampling rate, and A = amplitude. I set a constant length and reduce it by half for each beep, so the user will hear that it is beeping faster and faster.
The last program is simple as previous two. I use a loop function for increasing amplitude, so each beeping will become louder. However, these three programs allow me to understand the behaviors of sound.
Here are the text files:
click here to see 1st program (Repetition of a tone with increasing its length)
click here to see 2nd program (Count down beeping)
click here to see 3rd program (Increase the loudness)
Here are the exe files:
click here to download 1st program
click here to download 2nd program
click here to download 3rd program