Interface:
The interface was very simple just a bunch of labels and round buttons.
There is one thing I want to point out. The label(in my program) was updated by the model directly, I guess it is not a right way of doing it(according to stanford CS193P tutorial online). Some kind of notification should be used, i guess. But I don't have time to look into the threads and add in notifications, so I just let the model manipulated that directly.The good side is, the frequency of the operation is not so fast(about 100 times/sec), so I thought it's okay. It's running fine, on simulator.
Controller
There is not really a controller, just have to link up the functions to the right button.
Very basic.
Model
As compared to the two categories above, model is a bit more complex, it involves 2 main portions:
The interface was very simple just a bunch of labels and round buttons.
There is one thing I want to point out. The label(in my program) was updated by the model directly, I guess it is not a right way of doing it(according to stanford CS193P tutorial online). Some kind of notification should be used, i guess. But I don't have time to look into the threads and add in notifications, so I just let the model manipulated that directly.The good side is, the frequency of the operation is not so fast(about 100 times/sec), so I thought it's okay. It's running fine, on simulator.
Controller
There is not really a controller, just have to link up the functions to the right button.
Very basic.
Model
As compared to the two categories above, model is a bit more complex, it involves 2 main portions:
- Getting audio Data
- I am using the AudioQueueService
- In order to use a AudioQueue we need to:
- Set up a Audio Session and change the configuration of the audio session to the correct setting(in my case, i used recording, in which input is enabled)
- Implement the call back function that the audioQueue would calls on when a buffer is filled
- This is the most critical part
- We get and process audio data via this audio queue call back function
- Create the audioQueue,initialize, get it proper setting, link it up with the call-back function, allocate the queue some buffer and it's good to go
- Apple AudioQueueProgramingGuide(CookBook) and AudioSessionProgramingGuide is quite good.
- The sample code SpeakHere, by apple does almost the same thing for the audioQueue part. can make use of that with minor modification.
- Data processing
- a data queue was created. The incoming frequency and it's duration is stored into the queue.
- The algorithm would combine the frequencies within a threshold range.
- Some noise rejection code was added in as well, so that stand-alone noise frequency will not appear in the final result.
Potential Problems:
now, how we compute frequency is by counting the number of times that the lPCM data crosses 0. and divided by the length of the PCM data. This might arise a few problems:
- Now, the logic is based on comparison operation. I am not sure, whether this operation is optimized for iPhone platform. If not, it might be slow and might not keep up with sampling rate.
- So far, on simulator, it's working properly
- Noise might have significant effect on the computed frequency, especially when the samples are of low frequency
- Yes, this method does not work for low frequency. Get to use FFT I guess.
- But the cause might not be cause, I guess. It's the resolution! when the frequency resolution gets down to 500HZ, it's of no points saying the frequency is 1kHZ.
- only one fundamental frequency can be extracted(all the harmonics/weaker frequency would be lost)
Therefore, it would be good if we can replace this method by FFT, which would also come down to the availability of computing power on the iPhone device.
Coding Process:
Notification need to be sent from model to view controller.
So Far Achieved(Tested):
Creating a UI-a simple UI to achieve the purpose of testing
Create an Audio Queue-the queue is set up and initialized, need to look into whether or not do we need to get the proper setting for the audio session object as well.
Compute the frequency-from the data obtained from audio queue
To be implemented:
<Done>Work out the call back function, to decode the signal(Compute the frequency of a buffer)
Further analyze the data, figure out the transition states and eliminate the effect of that.
Achieve speed/accuracy
Post a notification to UI to inform the UI about the updates of the data(*Optional, Can be replaced with a button that manually updates the contents of the updated data)


