RPI update and play MATHEMATICA & SONIC and more SOUNDTOOLS
Posted by kll on November 20 2014 01:22:54
summary:
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
2014-09-09-wheezy-raspbian.zip 980MB, but also a new type of NOOBS NOOBS_v1_3_10.zip 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


0
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 / sonic-pi.net / geekgurl
developing-music and his examples / tutorialvideo


1 start:
-- [insert_php] text_svg('Wolfram',35,'gold','','','','gradient'); [/insert_php]
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:
-- [insert_php] text_svg('Mathematica',35,'gold','','','','gradient'); [/insert_php]
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:
-- [insert_php] text_svg('Sonic Pi',35,'gold','','','','gradient'); [/insert_php]
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
but
$ 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]
PERFECT! THANKS to RBN

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:
-- [insert_php] text_svg('audacity',35,'gold','','','','gradient'); [/insert_php]
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
-- [insert_php] text_svg('new system',35,'gold','','','','gradient'); [/insert_php]
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/
wget http://kll.engineering-news.org/share/arduinoPID_installall.sh
chmod u+x arduinoPID_installall.sh
./arduinoPID_installall.sh 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 192.168.1.101:1 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
-- [insert_php] text_svg('python sound',35,'gold','','','','gradient'); [/insert_php]
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 http://people.csail.mit.edu/hubert/git/pyaudio.git
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo apt-get install python-dev
cd pyaudio
sudo python setup.py install

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

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


7 FluidSynth, Qsynth, Vkeybd
-- [insert_php] text_svg('FluidSynth',35,'gold','','','','gradient'); [/insert_php]
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
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
channels

sudo nano /home/pi/python_fluid/start_fluid
start_fluid
#!/bin/bash
# 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
./start_fluid
open a second terminal
vkeybd
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 kll_keyboard.py 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
-- [insert_php] text_svg('arduino',35,'gold','','','','gradient'); [/insert_php]
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"
-- [insert_php] text_svg('SOUND CARD',35,'gold','','','','gradient'); [/insert_php]
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
lsusb

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