I need to record audio from iPhone. During recording I need to know, how many audio waves I have at the current moment and frequency and amplitude of each wave.
It seems to me, that avaudiorecorder can't help me.
I had a look at Apple's SpeakHere sample code, but I can get only amplitude from here (as I understand).
I had a look at Apple's aurioTouch sample code. It seems, that it does, what I need, but sample code is incredibly big and written mostly in C++, so it's difficult for me to understand it.
Can anybody give me examples, how to get Audio frequency and amplitude. It will be better, if you give me code examples.
Apple's aurioTouch sample app appears to be written using some C++ for absolutely no reason. Convert the code to plain C, and maybe you'll understand it better. Near real-time DSP audio analysis doesn't get much easier, so read up on that topic.
Related
I'm making an app on the iphone and I need a way of detecting the tune of the sounds coming in through the microphone. (I.e. A#, G, C♭, etc.)
I assumed I'd use AVAudio but I really don't know and I can't find anything in the documentation..
Any help?
Musical notes are nothing more than specific frequencies of sound. You will need a way to analyze all of the frequencies in your input signal, and then find a way to isolate the individual notes.
Finding frequencies in an audio signal is done using the Fast Fourier Transform (FFT). There is plenty of source code available online to compute the FFT from an audio signal. In particular, oScope offers an open-source solution for the iPhone.
Edit: Pitch detection seems to be the technical name for what you are trying to do. The answers to a similar question here on SO may be of use.
There's nothing built-in to the iOS APIs for musical pitch estimation. You will have to code your own DSP function. The FFTs in the Accelerate framework will give you spectral frequency information from a PCM sampled waveform, but frequency is different from psycho-perceptual pitch.
There are a bunch of good and bad ways to estimate frequency and pitch. I have a long partial list of various estimation methods on my DSP resources web page.
You can look at Apple's aurioTouch sample app for an example of getting iOS device audio input and displaying it's frequency spectrum.
Like #e.James said, you are looking to find the pitch of a note, its called Pitch Detection. There are a ton of resources at CCRMA, Stanford University for what you are looking for. Just google for Pitch Detection and you will see a brilliant collection of algorithms. As far as wanting to find the FFT of blocks of Audio Samples, you could use the built-in FFT function of the Accelerate Framework (see this and this) or use the MoMu toolkit. Using MoMu has the benefit of it's functions decomposing the audio stream into samples for you and easy application of the FFT using it's own functions.
I am working on a program that needs to capture the frequency of sound from a guitar. I have modified the aurioTouch example to output the frequency by using the frequency with the highest magnitude. It works ok for high notes but is very inaccurate on the lower strings. I believe it is due to overtones. I researched ways on how to solve this problem such as Cepstrum Analysis but I am lost on how to implement this within the example code as it is unclear and hard to follow without comments. any help would be greatly appreciated, thanks!
As you have discovered, musical pitch is not the same as peak frequency.
But trying to investigate algorithms while trying to work with real-time audio is not easy.
I suggest you separate the problems. Record some music sounds (guitar plucks, etc.) on your Mac into raw sound files. Try your chosen pitch estimation algorithms on these recorded sample sets. Then, after you get this working, figure out how to integrate your code into the iOS audio and Accelerate (for FFT) frameworks.
i am trying to understand the concepts of digital sound proceesing and i want to implement the FFT of Apple's Accelerate Framework link. In the vDSP API you can find a nice and fast FFT but unfortunately i can not set it up right. I think the documentation is really hard to understand. I am trying to FFT the signal of the iPhone's microphone. Can somebody give me a setup or some sites where i can read about this? Would be really great.
Thanks for all your answers.
Does Aurio Touch use vDSP ? I didn't the last time I looked, but it might now. I think that you are after a power spectrum.
Found this:
Audio File FFT in an OS X environment
Also Apple's example source would collapse down a bit if you deleted all the G4 ppc code...
The audio comes at you as integers: FFTs need floats. Convert with vDSP_vflt32 or similar.
Aurio touch is good cause you can see how all the callbacks work for sound i/o.
Hi unfortunately I've not been able to figure out audio on the iPhone. The best I've come close to are the AVAudioRecorder/Player classes and I know that they are no good fo audio processing.
So i'm wondering if someone would be able to explain to me how to "listen" to the iPhone's mic input in chunks of say 1024 samples, analyse the samples and do stuff. And just keep going like that until my app terminates or tells it to stop. I'm not looking to save any data, all I want is to analyse the data in real time and do stuff in real time with it.
I've attempted to try and understand apples "aurioTouch" example but it's just way too complicated for me to understand.
So can someone explain to me how I should go about this?
If you want to analyze audio input in real-time, it doesn't get a lot simpler than Apple's aurioTouch iOS sample app with source code (there is also a mirror site). You can google a bit more info on using the Audio Unit RemoteIO API for recording, but you'll still have to figure out the real-time analysis DSP portion.
The Audio Queue API is a slight bit simpler for getting input buffers of raw PCM audio data from the mic, but not much simpler, and it has a higher latency.
Added later: There's also a version of aurioTouch converted to Swift here: https://github.com/ooper-shlab/aurioTouch2.0-Swift
AVAudioPlayer/Recorder class won't take you there if you wanna do any real time audio processing. The Audio Toolbox and Audio Unit frameworks are the way to go. Check here for apple's audio programming guide to see which framework suits your need. And believe me, these low level stuff is not easy and is poorly documented. CocoaDev has some tutorials where you can find sample codes. Also, there is an audio DSP library DIRAC I recently discovered for tempo and pitch manipulation. I haven't looked into it much but you might find it useful.
If all you want is samples with a minimum amount of processing by the OS, you probably want the Audio Queue API; see Audio Queue Services Programming Guide.
AVAudioRecorder is designed for recording to a file, and AudioUnit is more for "pluggable" audio processing (and on the Mac side of things, AU Lab is actually pretty cool).
Can someone help me use the AudioQueue services on the iPhone to play a certain frequency (say, 440 Hz)? I've looked at the documentation, but I can't seem to figure out quite how to do it. Apple's sample code also isn't helping me too much.
Thanks!
/Developer/Examples/CoreAudio/SimpleSDK/DefaultOutputUnit has a sample of how to play a tone at a given frequency and sample rate.
I basically copied the code (also using a bit from this blog entry) and it worked with basically no change on the iPhone.
It isn't hard at all to do this. Take a look at the AudioQueue examples. If you look at the code to play back an audio file, you're going to just do that, except without actually reading a file.
You just divide the sampling rate by your frequency, calculate a sine wave, and feed those values into the audioqueue in your playback callback function.
ok, this is kinda lame, but if no one comes up with the real answer, you could just pre-record a sine wave and loop it. If it's cut well, it should play just fine. Of course this response would only work if you had only a few different frequencies to play.