Debian Codegraph @

src/Examples/CsoundQt/Useful/SF_Play_from_buffer.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 </CsOptions>
4 <CsInstruments>
5
6 sr = 44100
7 ksmps = 16
8 nchnls = 2
9 0dbfs = 1
10
11 /*****Playing a soundfile 1b: play from a buffer*****/
12 ;written by joachim heintz and andres cabrera
13 ;mar 2009
14
15 instr 1; fill the buffer and play
16 Sfile invalue "_Browse1" ;GUI input
17
18 gichn filenchnls Sfile; check if mono or stereo
19 ;reading the data in the buffers (function tables)
20 giL ftgen 0, 0, 0, 1, Sfile, 0, 0, 1
21 if gichn == 2 then
22 giR ftgen 0, 0, 0, 1, Sfile, 0, 0, 2
23 endif
24 turnon 2
25 endin
26
27 instr 2; read the buffer
28 ;GUI input
29 kskip invalue "skip"
30 kloop invalue "loop"
31 iskip = i(kskip)
32 iloop = i(kloop)
33 ;comparing the sample rates and reading the buffer
34 ilensmps = ftlen(giL)
35 idur = ilensmps / sr; duration to read the buffer
36 ireadfreq = sr / ilensmps; frequency of reading the buffer
37 iphs = iskip / idur; starting point as phase
38 aL poscil3 1, ireadfreq, giL, iphs
39 if gichn == 2 then
40 aR poscil3 1, ireadfreq, giR, iphs; right channel for stereo soundfile
41 else
42 aR = aL; right channel for mono soundfile
43 endif
44 ;stop instr after playing the buffer if no loop
45 ktim timeinsts
46 if iloop == 0 && ktim > idur-iskip then
47 turnoff
48 endif
49 outs aL, aR
50 endin
51
52 instr 3; turns off instr 2
53 turnoff2 2, 0, 0
54 endin
55
56
57 </CsInstruments>
58 <CsScore>
59 f 0 36000; don't listen to music longer than 10 hours
60 e
61 </CsScore>
62 </CsoundSynthesizer>
63 <bsbPanel>
64 <label>Widgets</label>
65 <objectName/>
66 <x>1</x>
67 <y>27</y>
68 <width>460</width>
69 <height>602</height>
70 <visible>true</visible>
71 <uuid/>
72 <bgcolor mode="background">
73 <r>127</r>
74 <g>170</g>
75 <b>134</b>
76 </bgcolor>
77 <bsbObject version="2" type="BSBLineEdit">
78 <objectName>_Browse1</objectName>
79 <x>27</x>
80 <y>96</y>
81 <width>295</width>
82 <height>24</height>
83 <uuid>{4b9ff4d6-f93b-471c-8d3b-8f94f2c6f948}</uuid>
84 <visible>true</visible>
85 <midichan>0</midichan>
86 <midicc>-3</midicc>
87 <label/>
88 <alignment>left</alignment>
89 <font>Lucida Grande</font>
90 <fontsize>10</fontsize>
91 <precision>3</precision>
92 <color>
93 <r>0</r>
94 <g>0</g>
95 <b>0</b>
96 </color>
97 <bgcolor mode="nobackground">
98 <r>229</r>
99 <g>229</g>
100 <b>229</b>
101 </bgcolor>
102 <background>nobackground</background>
103 </bsbObject>
104 <bsbObject version="2" type="BSBButton">
105 <objectName>_Browse1</objectName>
106 <x>327</x>
107 <y>93</y>
108 <width>100</width>
109 <height>30</height>
110 <uuid>{0bec8b20-55d0-4e86-b558-e8464ce6530a}</uuid>
111 <visible>true</visible>
112 <midichan>0</midichan>
113 <midicc>-3</midicc>
114 <type>value</type>
115 <pressedValue>1.00000000</pressedValue>
116 <stringvalue/>
117 <text>Open File</text>
118 <image>/</image>
119 <eventLine/>
120 <latch>false</latch>
121 <latched>false</latched>
122 </bsbObject>
123 <bsbObject version="2" type="BSBButton">
124 <objectName/>
125 <x>124</x>
126 <y>139</y>
127 <width>78</width>
128 <height>26</height>
129 <uuid>{25ac6f50-68b3-4f53-8b60-66f6a60801a1}</uuid>
130 <visible>true</visible>
131 <midichan>0</midichan>
132 <midicc>-3</midicc>
133 <type>event</type>
134 <pressedValue>1.00000000</pressedValue>
135 <stringvalue/>
136 <text>Play</text>
137 <image>/</image>
138 <eventLine>i 1 0 9999</eventLine>
139 <latch>false</latch>
140 <latched>false</latched>
141 </bsbObject>
142 <bsbObject version="2" type="BSBButton">
143 <objectName/>
144 <x>225</x>
145 <y>140</y>
146 <width>80</width>
147 <height>25</height>
148 <uuid>{bf4f12d5-4d8b-471a-a52d-d37135249573}</uuid>
149 <visible>true</visible>
150 <midichan>0</midichan>
151 <midicc>-3</midicc>
152 <type>event</type>
153 <pressedValue>1.00000000</pressedValue>
154 <stringvalue/>
155 <text>Stop</text>
156 <image>/</image>
157 <eventLine>i 3 0 .1</eventLine>
158 <latch>false</latch>
159 <latched>false</latched>
160 </bsbObject>
161 <bsbObject version="2" type="BSBSpinBox">
162 <objectName>skip</objectName>
163 <x>156</x>
164 <y>185</y>
165 <width>87</width>
166 <height>25</height>
167 <uuid>{79dec561-416b-4808-bc96-71900361766c}</uuid>
168 <visible>true</visible>
169 <midichan>0</midichan>
170 <midicc>-3</midicc>
171 <alignment>right</alignment>
172 <font>Lucida Grande</font>
173 <fontsize>10</fontsize>
174 <color>
175 <r>0</r>
176 <g>0</g>
177 <b>0</b>
178 </color>
179 <bgcolor mode="nobackground">
180 <r>255</r>
181 <g>255</g>
182 <b>255</b>
183 </bgcolor>
184 <resolution>0.00100000</resolution>
185 <minimum>-1e+12</minimum>
186 <maximum>1e+12</maximum>
187 <randomizable group="0">false</randomizable>
188 <value>0</value>
189 </bsbObject>
190 <bsbObject version="2" type="BSBCheckBox">
191 <objectName>loop</objectName>
192 <x>318</x>
193 <y>188</y>
194 <width>20</width>
195 <height>20</height>
196 <uuid>{388179e5-59be-49c1-859c-3c8ef59c5cb8}</uuid>
197 <visible>true</visible>
198 <midichan>0</midichan>
199 <midicc>-3</midicc>
200 <selected>false</selected>
201 <label/>
202 <pressedValue>1</pressedValue>
203 <randomizable group="0">false</randomizable>
204 </bsbObject>
205 <bsbObject version="2" type="BSBLabel">
206 <objectName/>
207 <x>76</x>
208 <y>184</y>
209 <width>80</width>
210 <height>28</height>
211 <uuid>{2f88b481-1b38-42cd-a00f-aae03542db9f}</uuid>
212 <visible>true</visible>
213 <midichan>0</midichan>
214 <midicc>-3</midicc>
215 <label>skiptime</label>
216 <alignment>center</alignment>
217 <font>Lucida Grande</font>
218 <fontsize>14</fontsize>
219 <precision>3</precision>
220 <color>
221 <r>0</r>
222 <g>0</g>
223 <b>0</b>
224 </color>
225 <bgcolor mode="nobackground">
226 <r>255</r>
227 <g>255</g>
228 <b>255</b>
229 </bgcolor>
230 <bordermode>noborder</bordermode>
231 <borderradius>1</borderradius>
232 <borderwidth>1</borderwidth>
233 </bsbObject>
234 <bsbObject version="2" type="BSBLabel">
235 <objectName/>
236 <x>267</x>
237 <y>183</y>
238 <width>52</width>
239 <height>29</height>
240 <uuid>{c4ddb6ad-ce7a-4624-9959-0d8475b121ae}</uuid>
241 <visible>true</visible>
242 <midichan>0</midichan>
243 <midicc>-3</midicc>
244 <label>loop</label>
245 <alignment>center</alignment>
246 <font>Lucida Grande</font>
247 <fontsize>14</fontsize>
248 <precision>3</precision>
249 <color>
250 <r>0</r>
251 <g>0</g>
252 <b>0</b>
253 </color>
254 <bgcolor mode="nobackground">
255 <r>255</r>
256 <g>255</g>
257 <b>255</b>
258 </bgcolor>
259 <bordermode>noborder</bordermode>
260 <borderradius>1</borderradius>
261 <borderwidth>1</borderwidth>
262 </bsbObject>
263 <bsbObject version="2" type="BSBLabel">
264 <objectName/>
265 <x>29</x>
266 <y>10</y>
267 <width>398</width>
268 <height>43</height>
269 <uuid>{d51eabbc-9ac1-4400-bdce-abffa14335ab}</uuid>
270 <visible>true</visible>
271 <midichan>0</midichan>
272 <midicc>-3</midicc>
273 <label>SIMPLE SOUNDFILE PLAYER</label>
274 <alignment>center</alignment>
275 <font>Lucida Grande</font>
276 <fontsize>26</fontsize>
277 <precision>3</precision>
278 <color>
279 <r>0</r>
280 <g>0</g>
281 <b>0</b>
282 </color>
283 <bgcolor mode="nobackground">
284 <r>255</r>
285 <g>255</g>
286 <b>255</b>
287 </bgcolor>
288 <bordermode>noborder</bordermode>
289 <borderradius>1</borderradius>
290 <borderwidth>1</borderwidth>
291 </bsbObject>
292 <bsbObject version="2" type="BSBLabel">
293 <objectName/>
294 <x>28</x>
295 <y>52</y>
296 <width>398</width>
297 <height>43</height>
298 <uuid>{cde28586-8a73-4794-ac1c-09f1d5af0a2c}</uuid>
299 <visible>true</visible>
300 <midichan>0</midichan>
301 <midicc>-3</midicc>
302 <label>(playing from a buffer)</label>
303 <alignment>center</alignment>
304 <font>Lucida Grande</font>
305 <fontsize>22</fontsize>
306 <precision>3</precision>
307 <color>
308 <r>0</r>
309 <g>0</g>
310 <b>0</b>
311 </color>
312 <bgcolor mode="nobackground">
313 <r>255</r>
314 <g>255</g>
315 <b>255</b>
316 </bgcolor>
317 <bordermode>noborder</bordermode>
318 <borderradius>1</borderradius>
319 <borderwidth>1</borderwidth>
320 </bsbObject>
321 <bsbObject version="2" type="BSBLabel">
322 <objectName/>
323 <x>25</x>
324 <y>410</y>
325 <width>410</width>
326 <height>182</height>
327 <uuid>{d7bc07b9-a49e-44b3-b942-27546029fac0}</uuid>
328 <visible>true</visible>
329 <midichan>0</midichan>
330 <midicc>0</midicc>
331 <label>This simple example shows how a mono or stereo soundfile can be played in Csound from a memory buffer. The disadvantage of playing a soundfile in this way is that it takes some time to read the file in your RAM (and you must have enough RAM), but you have better performance and stability.
332 Note that the file's sample rate is NOT converted to the orchestra sample rate!</label>
333 <alignment>center</alignment>
334 <font>DejaVu Sans</font>
335 <fontsize>14</fontsize>
336 <precision>3</precision>
337 <color>
338 <r>0</r>
339 <g>0</g>
340 <b>0</b>
341 </color>
342 <bgcolor mode="nobackground">
343 <r>255</r>
344 <g>255</g>
345 <b>255</b>
346 </bgcolor>
347 <bordermode>noborder</bordermode>
348 <borderradius>1</borderradius>
349 <borderwidth>1</borderwidth>
350 </bsbObject>
351 <bsbObject version="2" type="BSBScope">
352 <objectName/>
353 <x>31</x>
354 <y>228</y>
355 <width>397</width>
356 <height>89</height>
357 <uuid>{75ecdfe7-0ac2-433a-b89b-cc2270259ddb}</uuid>
358 <visible>true</visible>
359 <midichan>0</midichan>
360 <midicc>-3</midicc>
361 <value>1.00000000</value>
362 <type>scope</type>
363 <zoomx>2.00000000</zoomx>
364 <zoomy>1.00000000</zoomy>
365 <dispx>1.00000000</dispx>
366 <dispy>1.00000000</dispy>
367 <mode>0.00000000</mode>
368 </bsbObject>
369 <bsbObject version="2" type="BSBScope">
370 <objectName/>
371 <x>32</x>
372 <y>314</y>
373 <width>397</width>
374 <height>89</height>
375 <uuid>{440fb58b-dbb2-42db-9f4e-4f15331f5a18}</uuid>
376 <visible>true</visible>
377 <midichan>0</midichan>
378 <midicc>-3</midicc>
379 <value>2.00000000</value>
380 <type>scope</type>
381 <zoomx>2.00000000</zoomx>
382 <zoomy>1.00000000</zoomy>
383 <dispx>1.00000000</dispx>
384 <dispy>1.00000000</dispy>
385 <mode>0.00000000</mode>
386 </bsbObject>
387 </bsbPanel>
388 <bsbPresets>
389 </bsbPresets>