Skip to content

Commit

Permalink
some changes to ini settings, adde thread cleanup to synthesizer, add…
Browse files Browse the repository at this point in the history
…ed some RPi specific notes to readme
  • Loading branch information
robertoostenveld committed Dec 13, 2015
1 parent 01a4e10 commit 5a5cb39
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# eegsynth-matlab

Converting real-time EEG into sounds and music.

This repository contains all code for http://www.eegsynth.org.
Expand Down Expand Up @@ -52,3 +53,19 @@ User and Factory Template buttons and insert the USB cable. Release
the Template buttons and press "Record Arm". Finally press the right
arrow button.

### fix audio problems on Raspberry Pi

See https://dbader.org/blog/crackle-free-audio-on-the-raspberry-pi-with-mpd-and-pulseaudio
sudo apt-get install pulseaudio
sudo apt-get install mpd
sudo apt-get install mpc
This did not solve it, I uninstalled them again.

sudo apt-get install libasound2-dev
sudo apt-get install python-dev
wget https://pypi.python.org/packages/source/p/pyalsaaudio/pyalsaaudio-0.8.2.tar.gz
tar xvzf pyalsaaudio-0.8.2.tar.gz
cd pyalsaaudio-0.8.2
python setup.py build
sudo python setup.py install

4 changes: 2 additions & 2 deletions module/keyboard/keyboard.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ port=6379

[midi]
;device=Midi Through Port-0
;device=USB2.0-MIDI Port 1 ; this is the name on my macbook pro
device=USB2.0-MIDI MIDI 1 ; this is the name on my raspberry pi
device=USB2.0-MIDI Port 1 ; this is the name on my macbook pro
;device=USB2.0-MIDI MIDI 1 ; this is the name on my raspberry pi

[output]
prefix=keyboard
Expand Down
4 changes: 2 additions & 2 deletions module/launchcontrol/launchcontrol.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ hostname=localhost
port=6379

[midi]
;device=Launch Control XL ; this is the name on my macbook pro
device=Launch Control XL MIDI 1 ; this is the name on my raspberry pi
device=Launch Control XL ; this is the name on my macbook pro
;device=Launch Control XL MIDI 1 ; this is the name on my raspberry pi

[output]
prefix=launchcontrol
Expand Down
7 changes: 6 additions & 1 deletion module/sequencer/sequencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@

for note in sequence.split():
# this will return empty if not available
new = int(r.get(config.get('input','pattern')))
new = r.get(config.get('input','pattern'))
if new:
new = int(new)
else:
new = config.getint('default','pattern')

if pattern!=new:
pattern = new
try:
Expand Down
8 changes: 4 additions & 4 deletions module/synthesizer/synthesizer.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[general]
name="Synthesizer"
bitrate=44100
blocksize=8820
blocksize=441

[redis]
hostname=localhost
;hostname=192.168.1.2
port=6379

[pyaudio]
output_device_index=3
output_device_index=1

[default]
vco_sin=0.75
Expand All @@ -30,9 +30,9 @@ vco_sin=launchcontrol.channel00.control077
vco_tri=launchcontrol.channel00.control078
vco_saw=launchcontrol.channel00.control079
vco_sqr=launchcontrol.channel00.control080
vco_pitch=launchcontrol.channel00.control081
; vco_pitch=launchcontrol.channel00.control081
; vco_pitch=keyboard.channel00.note
; vco_pitch=sequencer.note
vco_pitch=sequencer.note
lfo_frequency=launchcontrol.channel00.control082
lfo_depth=launchcontrol.channel00.control083
; adsr_gate=launchcontrol.channel00.note
Expand Down
23 changes: 13 additions & 10 deletions module/synthesizer/synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
r = redis.StrictRedis(host=config.get('redis','hostname'),port=config.getint('redis','port'),db=0)
p = pyaudio.PyAudio()

count = p.get_device_count()
devices = []
for i in range(count):
for i in range(p.get_device_count()):
devices.append(p.get_device_info_by_index(i))
print('-------------------------')
for i, dev in enumerate(devices):
print "%d - %s" % (i, dev['name'])
print('-------------------------')

BLOCKSIZE = int(config.get('general','blocksize'))
CHANNELS = 1
Expand Down Expand Up @@ -215,7 +216,8 @@ def run(self):
trigger.start()

offset = 0
while True:
try:
while True:
################################################################################
# generate the signal
################################################################################
Expand Down Expand Up @@ -282,10 +284,11 @@ def run(self):
# write the buffer content to the audio device
stream.write(BUFFER)
offset = offset+BLOCKSIZE

trigger.stop_thread()
control.stop_thread()
stream.stop_stream()
stream.close()
p.terminate()

except KeyboardInterrupt:
trigger.stop_thread()
control.stop_thread()
trigger.join()
control.join()
stream.stop_stream()
stream.close()
p.terminate()

0 comments on commit 5a5cb39

Please sign in to comment.