3 -- Swamp Bike Opera embedded system for Kaffe Matthews
4 -- Copyright (C) 2012 Wolfgang Hauptfleisch, Dave Griffiths
6 -- This program is free software: you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as published by
8 -- the Free Software Foundation, either version 3 of the License, or
9 -- (at your option) any later version.
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 -- You should have received a copy of the GNU General Public License
15 -- along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package.path = package.path..";./?.lua;../lib/?.lua"
18 package.cpath = package.cpath..";./?.so;../lib/?.so"
21 -- create an audio device using default parameters and exit in case of errors
26 print("starting player")
27 posix.mkfifo("/tmp/dodo")
29 dofile '../config/swamp.conf'
31 if not proAudio.create( ) then -- 8, 44000, 1024 ) then
35 --- initialize the sample and sound table
42 start_load = os.time()
44 sample[1] = proAudio.sampleFromFile(CONFIG.sound_path.."1.ogg")
46 --sample[2] = proAudio.sampleFromFile(CONFIG.sound_path.."2.ogg")
48 --sample[3] = proAudio.sampleFromFile(CONFIG.sound_path.."3.ogg")
50 --sample[4] = proAudio.sampleFromFile(CONFIG.sound_path.."4.ogg")
52 --sample[5] = proAudio.sampleFromFile(CONFIG.sound_path.."5.ogg")
54 --sample[6] = proAudio.sampleFromFile(CONFIG.sound_path.."6.ogg")
56 --sample[7] = proAudio.sampleFromFile(CONFIG.sound_path.."7.ogg")
58 --sample[8] = proAudio.sampleFromFile(CONFIG.sound_path.."8.ogg")
60 --sample[9] = proAudio.sampleFromFile(CONFIG.sound_path.."9.ogg")
62 --sample[10] = proAudio.sampleFromFile(CONFIG.sound_path.."10.ogg")
64 --sample[31] = proAudio.sampleFromFile(CONFIG.sound_path.."31.ogg")
65 --sample[32] = proAudio.sampleFromFile(CONFIG.sound_path.."32.ogg")
66 --sample[33] = proAudio.sampleFromFile(CONFIG.sound_path.."33.ogg")
67 --sample[34] = proAudio.sampleFromFile(CONFIG.sound_path.."34.ogg")
68 --sample[35] = proAudio.sampleFromFile(CONFIG.sound_path.."35.ogg")
69 --sample[36] = proAudio.sampleFromFile(CONFIG.sound_path.."36.ogg")
70 --sample[37] = proAudio.sampleFromFile(CONFIG.sound_path.."37.ogg")
71 --sample[38] = proAudio.sampleFromFile(CONFIG.sound_path.."38.ogg")
72 --sample[39] = proAudio.sampleFromFile(CONFIG.sound_path.."39.ogg")
73 print("pre-loading finished")
74 print("took "..os.time() - start_load.." seconds.")
77 PITCH = { slow = 0.5 ,
85 local file = io.open("/tmp/dodo","r")
90 local line = file:read()
93 local message , n = string.match(line, "^(.-)%s(.-)$")
99 if message == "play" then
101 --sample[n] = proAudio.sampleFromFile(CONFIG.sound_path.."audio/"..n..".ogg")
102 if sample[n] then sound[n] = proAudio.soundPlay(sample[n])
103 else print("sound "..n.." not loaded")
106 print("sound "..n.." allready playing")
109 elseif message == "loop" then
111 --sample[n] = proAudio.sampleFromFile(CONFIG.sound_path.."audio/"..n..".ogg")
112 if sample[n] then sound[n] = proAudio.soundLoop(sample[n])
113 else print("sound "..n.." not loaded")
116 print("sound "..n.." allready playing")
119 elseif message == "play_right" then
121 --sample[n] = proAudio.sampleFromFile(CONFIG.sound_path.."audio/"..n..".ogg")
122 if sample[n] then sound[n] = proAudio.soundLoop(sample[n])
123 else print("sound "..n.." not loaded")
125 proAudio.soundUpdate( sound[n], 0.0, 2.0, 0.0, 1.0 )
127 print("sound "..n.." allready playing")
130 elseif message == "play_left" then
132 --sample[n] = proAudio.sampleFromFile(CONFIG.sound_path.."audio/"..n..".ogg")
133 if sample[n] then sound[n] = proAudio.soundLoop(sample[n])
134 else print("sound "..n.." not loaded")
136 proAudio.soundUpdate( sound[n], 2.0, 0.0, 0.0, 1.0 )
138 print("sound "..n.." allready playing")
142 elseif message == "stop" then
146 proAudio.soundStop(sound[n])
153 proAudio.soundStop(sound[n])
159 elseif message == "right" then
161 proAudio.soundUpdate( sound[n], 0.0, 2.0, 0.0, 1.0 )
165 elseif message == "left" then
167 proAudio.soundUpdate( sound[n], 2.0, 0.0, 0.0, 1.0 )
171 elseif message == "slow" then
173 proAudio.soundUpdate( sound[n], 1.0, 1.0, 0.0, 0.5 )
177 elseif message == "normal" then
179 proAudio.soundUpdate( sound[n], 1.0, 1.0, 0.0, 1.0 )
183 elseif message == "fast" then
185 proAudio.soundUpdate( sound[n], 1.0, 1.0, 0.0, 2.0 )
190 elseif message == "fadeout" then
191 for i= 1 , 0 , -0.1 do
192 proAudio.soundUpdate( sound[n], i, i, 0.0, 1.0 )
195 proAudio.soundStop(sound[n])
198 print("invalid message")
202 print("invalid or missing parameter")
211 os.remove("/tmp/dodo")