-
Raspberry Pi, Model 3B (further: RPi)
-
External USB sound card (further: sound card)
-
Microphone, 3.5 mm headphone jack plug (further: mic)
-
"RJ45" Ethernet cable (further: e-cable)
-
Power supply for the RPi (one of the following):
- USB cable + seperate device's USB port (PC, laptop, etc.)
- Common external power supply
-
Server
-
Main operating computer (PC, laptop, etc.; further: MOC)
Sound playing device, 3.5 mm headphone jack plug (further: dynamic)
-
Connect the sound card to the RPi
-
Connect the mic to the sound card
-
Connect the RPi to the power supply
Connect the dynamic to the sound card
- Check whether Curl library is already installed on the RPi by running the following command:
~$ ls /usr/include/curl
If it is not, install it by running the following commands:
~$ sudo apt-get update
~$ sudo apt-get install libcurl3
~$ sudo apt-get install libcurl4-openssl-dev
- Set the sound card as Default by performing the following steps:
Run:
~$ lsusb
The following should be seen:
Bus 001 Device 004: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Run:
~$ sudo nano /etc/asound.conf
Contents of asound.conf should be changed to the following:
pcm.!default
{
type plug
slave
{
pcm "hw:1,0"
}
}
ctl.!default
{
type hw
card 1
}
Go to the home directory of the RPi.
Run:
~$ nano .asoundrc
Contents of .asoundrc should be identical to ones of asound.conf.
Run:
~$ alsamixer
In the opened menu sound card should be seen as a default.
Card: C-Media USB Headphone Set
Chip: USB Mixer
View: F3:[Playback] F4: Capture F5: All
Item: Headphone [dB gain: -20.13, -20.13]
Adjust sound settings of the mic and dynamic according to your preferences:
ββββ ββββ
β β β β
β β β β
β β β β
β β β β
β β β β
β β β β
β β ββββ
ββββ ββββ
ββββ ββββ
ββββ ββββ
ββββ ββββ
ββββ ββββ
ββββ ββββ
ββββ€ ββββ€
βOOβ βMMβ
ββββ ββββ
19<>19 52
Headphone Mic
- alsa-utils should be version 1.0.25, in order to make it so, the following steps should be performed:
Run:
~$ sudo nano /etc/apt/sources.list
Add the following line at the end of sources.list:
deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
Run:
~$ sudo apt-get update
~$ sudo apt-get install alsa-utils=1.0.25-4
Reboot (if necessary).
Optional test of the sound quality:
Run:
~$ arecord -r44100 -c1 -f S16_LE -d5 test.wav
Connect dynamic to the sound card. Run:
~$ aplay test.wav
-
Recording 1 second of audio into test.wav file using RPi
-
Outputting corresponding data in the console window (one of the following):
- Header data and list of 80 RMS values ( DEBUG mode)
- Sound decibel level bar chart (
non-DEBUG mode;
one of the following):
- Displayed using bar (β) symbol ( UNICODE mode)
- Displayed using asterisk ( * ) symbol ( non-UNICODE mode)
βββββββββββββββββ ββββββββββββββββββ βββββββββββββββββββ
β MOC β β (commands) β β RPi β β β Sound card β
β (PuTTY) β β (sound β β (sound.a) β βββββββββββββββββββ
βββββββββββββββββ info / graph) ββββββββββββββββββ β β
βββββββ βββββββββββ
β mic β β dynamic β
βββββββ βββββββββββ
II. Optional part (COMM mode):
-
Sending FastDB (8 decibel values recorded once in every 125 ms) data to the server
-
Storing the data on the server side (both of the following):
- All the data with attached dates in sound_log.txt file
- Last received 8 pieces of sound data in last_line.json file
-
Outputting the last obtained data on the responsive webpage real-time chart
............................................................................
βββββββββββββββββββ ββββββββββββββββββββββββ
β RPi β β (sound data) β β Server β
β (sound.a) β β (sound.php) β
βββββββββββββββββββ β (soundGraph.js) β
β (sound.html) β
βββββββββββββββββββ ββββββββββββββββββββββββ
β MOC β β (sound graph) β²
β (browser) β
βββββββββββββββββββ
There are some preset values ruling conditional compiling in the RPi files:
- DEBUG mode - off ( non-DEBUG mode or DEBUG undefined)
- UNICODE mode - on (UNICODE mode or UNICODE defined)
- COMM mode - on (COMM mode or COMM defined)
The DEBUG constant is defined in sound.h. In order to set it off / on, add / remove two slashes (//) respectively in the beginning of the following line:
#define DEBUG // Conditional compiling
The UNICODE constant is defined in screen.h. In order to set it off / on, add / remove two slashes (//) respectively in the beginning of the following line:
#define UNICODE // Conditional compiling
The COMM constant is defined in comm.h. In order to set it off / on, add / remove two slashes (//) respectively in the beginning of the following line:
#define DEBUG // Conditional compiling
Setting the servers URL address on the RPi side
When COMM mode is set, one should change the URL address in comm.h file in the following line:
#define URL "http://your.server.com/.../sound.php"
-
Launch the RPi
-
Make the object files and the sound.a application by running the following command:
~$ make
- Run the application by entering the following command:
~$ ./sound.a
- Go to the server's URL in the browser on the MOC
In order to stop the program, press Ctrl + C in the PuTTY console window.
-
RPi (8):
- .c files (4):
- comm.c
- main.c
- screen.c
- sound.c
- .h files (3):
- comm.h
- screen.h
- sound.h
- Other files (1):
- makefile
- .c files (4):
-
Server (5 (7 including optional ones)):
- Front-end files (2):
- sound.html
- soundGraph.js
- Back-end files (3):
- last_line.json
- sound.php
- sound_log.php
- Optional files (2):
- sound_log.txt
- last_line.json
- Front-end files (2):
-
Other (3):
- README.md
- LICENCE
- web_site_graph_example.png
Even if there are no optional files, they will be created when the data transmission from RPi to the server starts. But, if one runs the program without data transmission from RPi, the chart will be drawn only if there is last_line.json file with valid data.
{"data":"124.00;219.49;317.29;412.53;389.72;256.49;134.82;192.13;"}
This project is licensed under the GNU General Public License. See the LICENSE file for details
There is only one graph state on the site and it does not change.
- Check the set-up
- Check whether the sound.a is running
- Refresh the web page
The symbols used as bars are some weird ones and completely do not seem to have a bar form. The console does not recognize the UTF-8 symbol U+2590 used as a bar in screen.c file.
Set the console's character set to UTF-8 or, if the console does not support UTF-8, set non-UNICODE mode.
PuTTY solution:
-
Go to the console settings (choose either way)
-
Window (window's left side tree)
-
Translation (window's left side tree)
-
Remote character set (window's right side)
-
Choose UTF-8 (drop-down list)
- Roman Bezusiak - Initial work - Roman Bezusiak (GitHub profile)
- Wikimedia Foundation Inc., Wikipedia - Encyclopedia materials - wikipedia.org
- Chart.js - Graph drawing on the web site - chartjs.org
- jQuery.js - AJAX - jquery.com
- curl/curl.h - Data transmission from the RPi to the server - curl.haxx.se