Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 230
Registered: ‎01-12-2013
My Device: z30
My Carrier: Mobile Vikings

Real Time audio analysis

Hello Developers

 

I want to analyse audio in real time with FFT (Fast Fourier Transformation) to get the frequency of the audio input of the device. I was searching for a way to retrieve the raw audio stream or something like that but the only classes I found was the AudioManager. I guess I have to use low level C functions for this instead of the higher level manager because that class can only save the audio to a file. I want to analyse the sound in real time instead of recording, analysing it and then showing the results.

 

Thanks in advance!

______________________________________________________
BB10-OAuth: GitHub
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Real Time audio analysis

While there may be other approaches, you could definitely do this with an appropriate third-party (or your own) FFT library plus the PCM audio stuff. Look here for a start: https://developer.blackberry.com/native/documentation/core/com.qnx.doc.neutrino.audio/topic/about.ht...

There's a "Play a .wav file" sample that could also be helpful for introducing you to some routines in that library, though obviously you'd be using audio capture instead of playback.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 230
Registered: ‎01-12-2013
My Device: z30
My Carrier: Mobile Vikings

Re: Real Time audio analysis

Hey Peter

 

Thanks for the link. I will probably use a 3rd party library for the FFT.

 

Any ideas on how to analyse the sound? I mean, should I capture a lot of short sound samples from the microphone and analyse those with FFT or is it possible to analyse it in real time? I want to retrieve the frequency of the input signal.

 

Thanks!

______________________________________________________
BB10-OAuth: GitHub
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Real Time audio analysis

You will find the answers to those sorts of questions by studying FFTs and reading up on related topics. How much data you need to capture depends on a number of factors, including how accurate you want the measurement to be. FFTs basically give you a histogram representing how much a range of frequencies contribute to the overall signal. Frequencies other than those exactly matching the centre frequency of each bin "bleed" into an adjacent bin (think of it as a weighted average type of thing).

Depending again on the specific needs of your situation, you'll also want to apply a "windowing" function, which reduces the errors that arise from using a shorter block of samples where the signal in effect cuts off suddenly at the start and end.

Generally you can do this with short blocks captured in real time, and since FFTs are so fast you can run one after each block is captured. You can also do things like combine blocks in real time to form longer blocks, using a "sliding window" mechanism, to increase the FFT resolution while still generating measurements frequently as opposed to having it maybe wait many seconds between updates.

It's a fun and educational area to work in... but non-trivial if you want it to be done correctly. :-)

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
BlackBerry Development Advisor
Posts: 158
Registered: ‎09-06-2010
My Device: Classic
My Carrier: Vodafone UK

Re: Real Time audio analysis

This may be perhaps be of some interest in this context:

 

http://supportforums.blackberry.com/t5/Native-Development-Knowledge/Integrating-accessories-with-Bla...

 

When I was looking at attaching accessories to BlackBerry 10 devices I took a look at using the Audio Jack as a transport medium. It implements a simple audio FSK ( Frequency Shift Keying ) scheme to allow encoding of character data. The part that's probably common with your requirements is how I manipulated blocks of audio PCM samples.

 

Anyway, the code is here:

 

https://github.com/blackberry/Cascades-Community-Samples/tree/master/AudioAccessory

 

And there is even a video of it working here courtesy of my collegue @mdwrim

 

http://youtu.be/cQzL-5b1P_g

 

In practical terms the real challenge using the audio port in a breadboard scenario was noise.

 

Anyway, it was a fun project and demonstrated a number of patterns in manipulating audio.

 

John @jcmrim

---------------------------------------
Please refrain from posting new questions in solved threads.
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Found a bug? Report it here
Follow me on Twitter @jcmrim