Articles Hierarchy

Articles Home » RPI » RPI update and play MATHEMATICA & SONIC and more SOUNDTOOLS

RPI update and play MATHEMATICA & SONIC and more SOUNDTOOLS

0 infolinks
1 Wolfram
2 Mathematica
3 Sonic Pi
4 audacity
5 new system
6 python sound and other article my python synth
7 FluidSynth, Qsynth, Vkeybd MIDI
8 connect arduino
9 connect USB "soundcard"

first i have to say that i stopped my work for some time because i got bad luck with some hardware.
my new cat ( Fritz ) play / bite the cable with the control setup ( uPCS with arduino due..),
i damaged / burned a touch LCD arduino MEGA setup where i wanted to upgarde the software,
and for the UPS LED project not get the electronic parts here in the 2 shops in CHIANG MAI i know.

But missing the "PLAY" i wanted to setup the RPI again, and i was remembering it as a perfect system ( with arduino data capture, camera setup, webserver setup.. ) i just have to plug in the power adapter. But as usual not lucky here also:
the VNC server does not work, a rpi update / upgrade did not help ( putty ok ),
but found after some testing that a manual start of vncserver :1 helped. somehow the autostart at boot is damaged.

add i see that my system anyway is old: there is now a 980MB, but also a new type of NOOBS 738MB, i read it now only contains the RASPBIAN, all other OS must be added/downloaded online, but still, how it can be smaller??
i tried several times to download. Means i will need some time for a new setup, but hoping that my tools work with the new system.
But i read for new version::
+ Java updated to JDK 8 ?Possibly even processing could be usable now?
+ Mathematica updated to version 10
+ Sonic Pi updated to version 2

meanwhile i want to PLAY on the old but updated system:

- there are the 2 program icons about math
"a new path for learning programming—and connecting it to the real world—"
** Wolfram : command-line version of the Wolfram Language
** Mathematica : notebook user interface for it
- and the new music / programming teaching
** Sonic Pi
i want spend some time with that tools and report here about it,
not as a professional review, just as a basic info if you also not have played with it until now.
-- first check online:
wolfram / getting-started-with-mathematica / worksheet1 / worksheet2 / reference / wolfram / demonstrations

sonic-pi / worksheet1 / worksheet2 / themagpi / / geekgurl
developing-music and his examples / tutorialvideo

1 start:
-- 87 W 111 o 108 l 102 f 114 r 97 a 109 m
and get a terminal window what ask you for inputs like In[1]:= what are variable settings.
In[1]:= a=2 and ENTER gives you Out[1]= 2
In[2]:= b=4; and ENTER suppresses the output.
with math these variables can be connected like:
In[3]:=a+b and ENTER gives you Out[3]= 6

in[3]:=?* gives a list of all functions / that not fits in the terminal window / so better ?A*
from operation i find only
FILE QUIT to stop it, == SHIFT CNTRL Q
as you can not save anything ( inputs or results ) i think i will not use that command line tool,
but possibly i am wrong because i not checked on that many functions.
The LXTerminal allows to adjust the FONT, i need for VNC view.

2 start:
-- 77 M 97 a 116 t 104 h 101 e 109 m 97 a 116 t 105 i 99 c 97 a
i get a 100% CPU for a minute and then see the 2 screens, but CPU still 100% for other minute!
here must enter inputs with SHIFT ENTER to get the output,

the second window besides the so called "notebook" programming window gives just 3 info / help links.
and pls see here a already complex example as oneline input works fine.

now at the first glimps i would say its something like "processing", even with the same speed problems.
But here a other nice ONELINER: a photo with the RPI camera

a saved program file / save as / ... device_rpicam.nb gives not only that one line, it even contains the picture??
play with mathematica and sound:

i see a keyboard for MIDI, why not test that?
- download the KeyboardAndComposer-author.nb ( 3.8MB UUPS )
- upload to RPI with SFTP
- open it by file dialog and WAIT....
- i could play one tone about every 20sec??
so that is obviously too much for a RPI hardware but just to see the principle working is good.

3 start:
-- 83 S 111 o 110 n 105 i 99 c 32 space 80 P 105 i
get intro page and a example random sound

using the blue headphone jack to speaker gives a sound ( while i work headless / not HDMI ), but where is the RPI linux volume control?
i look at Terminal command from here
$ amixer
$ alsamixer pls use up down arrow keys and [m] this works perfect
$ amixer cset numid=3 100% (,100%) __ did not work for me
$ sudo alsactl store __ not tested
$ sudo /etc/init.d/alsa-utils reset __ not tested

but that
$ amixer cset numid=1 -- 400
a whole integer number between -10200 and +400 in centi-dB units did also work!
check on
$ amixer controls

putty terminal windowpi@raspberrypi ~ $ amixer
Simple mixer control 'PCM',0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
Playback channels: Mono
Limits: Playback -10239 - 400
Mono: Playback -760 [89%] [-7.60dB] [on]

pi@raspberrypi ~ $ amixer controls
numid=3,iface=MIXER,name='PCM Playback Route'
numid=2,iface=MIXER,name='PCM Playback Switch'
numid=1,iface=MIXER,name='PCM Playback Volume'
numid=5,iface=PCM,name='IEC958 Playback Con Mask'
numid=4,iface=PCM,name='IEC958 Playback Default'
pi@raspberrypi ~ $

wonder if stereo creation and output RPI speaker works, i test:

the pan ( -1 .. 1 ) gives me a nice left to right speaker shift of the sound.
you can use tones ( play 60 .. ) but there are also lots of sound sample files included.
each TAB / workspace can be saved to a file [Save], but i not find a way to reload the file, code
and you can start [Rec] recording, play / [Run], and stop recording and save it as a *.wav file, listen
+ the content of the TAB / workspace is remembered, so usually not need to save TABs
+ [Run] one sound from TAB 1 and go TAB 2 and [Run] that also ( play at same time )
+ define one sound in one TAB and use it in an other TAB
With additionally [HELP] and [PREFS] switched ON, user interface is very nice.
+ here is also the volume control! more easy
+ Size + - allow to change the Font size
-- But this window options you have to do after every start ? is there a config file for it ?

(here i try my first DRUM session)

As i play with sonic to understand what synth, play 60 / C, or sample
means i see how difficult it can get when you use a sample and tune it with "rate:" to a tone
( it is the speed the sample is played what makes the tone and the length of the sound changing ), as i read more about that from here i decided to use one of his professional examples for reading and testing.
- download the zip to PC
- copy the sonic text file by SFTP to RPI
- copy the samples dir also
- start RPI sonic pi, select empty workspace TAB
- copy code from textfile
- change path for samples directory
- [Run]

when you look at the source: in
/home/pi/.sonic-pi/store/default/.git/config could be settings to change?
/home/pi/.sonic-pi/store/default/*.spi are the workspace TAB as text files for easy backup.

i have some noise issues with my system ( old and new SD same ):
i connected a very old speaker system to RPI audio out
- after reboot there is no noise.
- i start in VNC the Sonic Pi program and hear a noise
- i stop in VNC the Sonic Pi program and hear less noise but like a heart beat ( even after close PC VNC window )
AND i hear a scratching sound when i move the mouse!!!
but only when the mouse is over the VNC window ( in focus) on the PC screen, not when i operate other programs on PC..
no idea what linux make from a mouse movement?? have to test it again when i am on HDMI and the mouse is really on the RPI!
even if i have power issues with my RPI setup, the PC mouse thing is spooky.
used hardware and connection:RPI model B with camera
ethernet cable to router
USB cable to powered BELKIN USB HUB ( and that powers the backward the RPI )
USB stick on USB HUB

a check of amixer not show a change by start / stop of Sonic Pi program
a putty sudo reboot makes after 15sec a shot sound and then speaker is quiet, until restart of VNC window and restart of Sonic Pi
Ahh, also same after play sound with Mathematica
When i disconnect the speaker and use a headphone i do not hear that, when i connect the speaker again its there.
But even if the speaker audio input is bad, ?draw power from RPI? that not tells me how that spooky PC mouse move .. VNC .. RPI sound could happen?
p.s. the PC mouse is USB ( on PC), not radio...
need new speaker?
Hmm, that was not the point, i buy a new audio stereo cable:
i connect that to the old speaker: same
i connect the RPI to the LINE IN of my PC: same
But if i plug in the RPI power supply ( USB like power port ) its gone.
so that might be the explanation for the mystic: ( put on your ELECTRIC THINKING CAP )
move the mouse in VNC window increase communication ethernet ( also LEDs there blinking )
power requirement RPI CPU GPU to evaluate x window program and show the moving mouse
my back feed power via USB HUB is possibly limited by polyfuse what make the suppy voltage drop on higher current?
and there can be even a voltage drop on a ( too small ) line on the PCB, so the audio signal send by RPI might be NULL, but a changing V+ or a moving GND will be send ( as AC ) as sound signal!
Hmm still whats the connection with i have to start Sonic Pi / Mathematica play sound first.
these start ALSA audio output?

4 install and start:
-- 97 a 117 u 100 d 97 a 99 c 105 i 116 t 121 y
to work with sound file / samples.. i installed a tool: ( actually on WIN7 PC and RPI )
sudo apt-get update
sudo apt-get install audacity

5 setup
-- 110 n 101 e 119 w 32 space 115 s 121 y 115 s 116 t 101 e 109 m
i downloaded the new NOOBS and the new RASPBIAN, and unzip RASPBIAN and burn it to a 8GB SD card.
setup system on the HDMI TV, radiolinked KEYBOARD MOUSE, WIFI USB adapter.
back on HEADLESS search ethernet IP and login by PUTTY.
as shown here i download my
install scriptcd /home/pi/
chmod u+x
./ virginRPI

that makes me a UPDATE, UPGRADE,
install mc, gnash, tightvncserver
manually i must do
vncserver :1 and give password.. like piremote piremote n
ifconfig check
sudo reboot
but when i start VNC viewer and try VNC server again get connection refused until i start manually vncserver :1 in putty
ok, as in old and new system is same i must have a problem in/with the /etc/init.d/vncserver file
sudo chown root:root /etc/init.d/vncserver was missing in install!
and the file somehow got the attribute "DOS format" so i edit it new on RPI ( and updated installation tool) After all i know, the problem was created by my installation routine / at its last test, i know for sure after i repaired the other SD card by reinstall/rerun my tool there too.

setup tool here

now, while the setup tool is to remember installations, still need a way to copy some files and dirs between SD cards.
besides SFTP... i like to use BACKUP to USB STICK ( by MC )

summary: with Mathematica and Sonic Pi RPI has 2 more features what makes it worth to buy / start with it.
for PLAY, for LEARN ( Linux and Programming ) and for TEACH ( as i read / not my area ).
Thanks for all your work !

6 python
-- 112 p 121 y 116 t 104 h 111 o 110 n 32 space 115 s 111 o 117 u 110 n 100 d
in case you do not want just load these big programs and learn how to use them, back to the basics,
try to get PYTHON to make a sound:
in RPI python 2.7.3 ( use file pathbrowser ) is installed already the pygame lib 1.9.1 mixer, sndarray
so play WAV and MID files is no problem.
next Step would be to generate a tone, pls see here

But how to install the pyaudio lib.
try sudo apt-get install git
sudo git clone
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo apt-get install python-dev
cd pyaudio
sudo python install

i just loose 2 programs: Sonic Pi and QjackCtl !!

as this was a bad idea, i format SD card and unzip the to it.
setup at HDMI ... putty headless, run my install script

7 FluidSynth, Qsynth, Vkeybd
-- 70 F 108 l 117 u 105 i 100 d 83 S 121 y 110 n 116 t 104 h
in my python sound tool ( see above link ) i
- generate sounds ( sinus... ) and play them
- generate MIDI Notes as files and play them
but got somehow stuck. still no idea if it is possible to play by python
a direct Midi Note without the make and play of a file.
i put that in HOLD and come back here:
i test some more installations: FLUIDSYNTH from here
sudo apt-get install fluidsynth
with it also comes the qsynth GUI

sudo nano /home/pi/python_fluid/config.txt
echo "FLUIDSYNTH Loading Config"
gain 5
select 1 1 0 69
select 2 1 0 70
select 3 1 0 105
select 4 1 0 114
select 5 1 0 115
select 6 1 128 48

sudo nano /home/pi/python_fluid/start_fluid
# Script to start FluidSynth & aconnect
echo Attempting to start FluidSynth
amixer cset numid=3 1
sudo fluidsynth -si -a alsa -m alsa_seq /usr/share/sounds/sf2/FluidR3_GM.sf2 &
sleep 5
sudo pkill fluidsynth
amixer cset numid=3 1
sudo fluidsynth -si -f /home/pi/fluid/config.txt -a alsa -m alsa_seq /usr/share/sounds/sf2/FluidR3_GM.sf2 &
sleep 10
aconnect 20:0 128:0

sudo chmod 755 /home/pi/python_fluid/start_fluid

first i try manually and i see many warnings ? errors?

and i can not test anything because have no MIDI device to connect.

and also install a MIDI keyboard
sudo apt-get install vkeybd

now i disable the last line aconnect from the above start_fluid scipt:
sudo nanu start_fluid "#" in last line
open a second terminal
back in first terminal:
aconnect -i -o
aconnect 129:0 128:0

and can play with the keyboard
under /home/pi/ can find ( after save config..) cat .vkeybdmap and cat .vkeybdrc
but the real config is in cat /usr/share/vkeybd/vkeydbmap, there i make my own one
sudo nano /usr/share/vkeybd/vkeydbmap-kll .code and start/use it with
vkeybd --keymap /usr/share/vkeybd/vkeybdmap-kll
i learn while i play with python pygame that my first key design: 44 key *2(CAPS) is not PLAYable/piano compatible,
while this here used basic concept row "z .. /" and row "a .. l" for #notes is better / common.
more info i found here and i used it for my change, with keysyms and ascii i create the new list from 0 .. 57, where the # notes behind row "@ # ...()" work only with [SHIFT], not with [CAPS], that was better in PYTHON PYGAME with the MOD KEYs usage.

8 connect arduino
-- 97 a 114 r 100 d 117 u 105 i 110 n 111 o
when i say i have no MIDI device, i remembered that i read about arduino can be a MIDI, so i think why not write 5 lines code in my arduino, connect it to RPI USB and aconnect it to FLUIDSYNTH..
and report here that i build one in 5 minutes, ok after 2 days i think that might be a new arduino project! see Link

9 connect USB "soundcard"
-- 83 S 79 O 85 U 78 N 68 D 32 space 67 C 65 A 82 R 68 D
update 02/2015
RPI has no MIC in, only the ahmm "Audio" OUT!
so for that 2 AUDIO problems no input, low quality output i want buy a SOUND CARD
and i found one in a computer accessory shop ( chinese import discount ) for 99THB/3USD

already it waits now 2 weeks to be played with, today i found a web site using exactly that model! search for 2) Microphone, but i not understand his configuration, so google here and here
now i check on

as i can identify the USB stick i remove it, so the rest must be the RPI internal USB hardware.
when i hot plug the USB soundcard, power out, RPI reboot, i can see it

now i change and have USB stick and external powered USB HUB
with WLan and soundcard

we see the device number can change.
the next step i do from putty, because i can paste in the code from the web site.
sudo nano /etc/asound.conf
pcm.!default { type plug slave { pcm "hw:1,0" }}
ctl.!default { type hw card 1}

now see hardware devices and sound devices:

and can find the card in the alsamixer

and test with AUDACITY

while the headset works, the MIC not, the recording did work. at replay i get nothing, when in alsamixer increase to 50% i hear a high pitch sound.
stupid or bad luck?? but i found a special setting in alsamixer ( see next picture )
and a recording command "arecord -d 5 xfiles.wav" (recording WAVE xfiles.wav: Unsigned 8 bit, Rate 8000 Hz, Mono ): play with "aplay xfiles.wav" where i hear some sound behind thenoise signal, so it was not dead, just weak.

while with "arecord -d 5 -f cd xfiles.wav" as Signed 16 bit Little Endian, Rate 44100 Hz, Stereo needed just a higher MIC setting of 32. the MIC capture setting seems to be no use, must see L R CAPTURE or press [space] to see it.
auto gain control can "m" mute, but then nothing.
the example from the web to stop with CTRL Z only works partially, must close terminal window and open again.
its not a clean stop. but the timer switch "-d 5" seconds recording works good.
amixer instead of alsamixer says a lot more, but not help me.
ok, have to search and play more, now have headache.
next day buy a new cheap headset, MD tech MD-6640, for 199THB / 6.10USD
but it has gold contacts. when i try it i could not hear anything / so could not test the MIC also,
angry and ready to bring it back i try on PC and sound works, back to my little RPI sound card
i got it working after i rammed the plug in deeply. and also the MIC worked great.
here i want to share some more anger about cheap hardware, ( why i again go for it? well you know )
PC plugs ( USB and audio) : while on the back you have the plugs from the motherboard,
on the front its a build in of the PC case, and special these front connectors are easy worn out??
and i could not find a spare/replacement! what? i have to buy a new case!
actually i then go for a cheap USB HUB plug into the rear / motherboard, to replace the front USB.
when i look my motherboard i have 2 more connectors for external USB,
but how to use? i never see hardware for this.

so now will test more about the RPI MIC settings.
a sound recording in audacity worked well, audacity MIC on max, alsamixer on 32, change to 60, change to 0, no difference at all, must be because auto gain on? with "m" switch OFF
and test record with different MIC settings, result: small volume independent from MIC volume ?????
and test record with different MIC capture settings (F5), result: works, best with 80
goto MIC 0, MIC capture 80, auto gain ON, loud and 50Hz noise headache.
goto MIC 0, MIC capture 0, auto gain ON, good recording.
need a break lets get loud on PC, because on RPI i see this

update 10.9.2015 here