Small python script I wrote so that you can yell at the console and see the frequency on the screen. The results can be slightly wrong (incorrect spikes in frequency occasionally) but it was great yelling at the computer with my hostel mates to see who’s got the highest ‘range’ 😀
The code is too small to give an explanation. However, you need to set up a few libraries before running the gist (instructions for linux) :
1. aubio – A fantastic library for analysing audio. Packages libaubio and python-aubio are available in the ubuntu/mint repositories. However, I ran into problems (repos have older versions I guess) and was able to fix them only after compiling the source. So head over to this repo, download the source code, and compile.
To compile aubio, head over to the source directory and type:
That will spew out a list of packages you will need at the end. Make sure you install the dev versions of each package. For example, for sndfile, do
sudo apt-get install libsndfile1-dev
Similarly install all the packages that you would need to use with aubio. I did not have a clue as to what I will need so I installed them all.
Now do ./waf build
and then sudo ./waf install
That should install aubio on your linux system. Time to install the python wrappers. ‘cd’ to /python directory in the aubio source.
python setup.py build to build the files and after building, sudo python setup.py install to install the python wrappers for aubio
2. The snippet depends on pysoundcard, which is not available in the repos. Head over here to download the source. Build and install this python package the same way you did the aubio python wrappers
Download (or type) the gist and run it! Happy yelling!
I’ve been longing for this day (/night) for almost an year now! I’ve finally, finally, got some data from an electret mic and finally got it into a beaglebone black. If you really want to understand the depth of this achievement, please go through what I’ve been doing for the past few months:
That’s a lot of questions. And I got a lot of answers. Though I’m no where near completing the actual project, at least getting it started is a relief. I’ve tried making my own amplifier, tried an audioboard from hrc, tried another opamp IC for amplifier, and finally hit upon this :
The previous amplifiers I made might have been working fine – I just might not have read the values properly. Anyways, its working now and that’s all I care about.
Components : Everything that was in the previous link containing the circuit diagram. I did not have 10 uF capacitors so I used 22 uF instead.
Beaglebone black : The INR 4200 beast. This board is being sold out faster than it is being produced. Lucky we could order one!
The process is pretty straightforward now that it works. The beaglebone black has a set of analog pins that can read analog inputs. I connect the mic (which produces voltage variations in the range of 20mv) to a preamplifier (built using the circuit diagram in the link and 741 opamp) and the output of the preamp (in range of 1 v) is given to the analog input of the BBB. When the sound hits the electret mic, it produces a voltage that is proportional to the amplitude of the sound. This is the signal we then amplify and finally measure.
Is this enough to do some signal processing and thus continue the project? Now that requires more experimenting and is a matter for another post.
I made the mistake of not connecting the ground of beaglebone black to the ground rail in the breadboard and cursed many perfectly working amplifier circuit because it BBB did not read.
Now we have to read this value using beaglebone.
First, enable the input output pins :
echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots
If that step went well, you should not see any messages.
Then I wrote a small python script to read the analog pin 1 continously :
Replace AIN1 with your analog pin (for eg: AIN2 or AIN3) and the value in time.sleep with your desira
ble delay between reads. Saved it as test.py and python test.py does the job.
The beaglebone black can read only voltages till 1.8 volts on its analog pins. Also, it can only read DC. That is why there are a lot of 0s in my screenshot – that’s where the negative voltages should go. The solution is to give a DC bias to the analog signal. Say we give 1v bias. Then the readings would be around 1V and will go below 1v when a negative peak occurs.