Repository navigation
Expand file tree
/
Copy pathtest.r3
More file actions
130 lines (109 loc) · 3.57 KB
/
Copy pathtest.r3
File metadata and controls
130 lines (109 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Rebol [
title: "Rebol/MiniAudio extension test"
]
unless audio [
audio: import miniaudio
init-device: function[/pause][
;; list all available devices:
devices: transcode audio/get-devices
?? devices
id: 0
foreach device devices/playback [
++ id
if find [
;; ignore these playback devices...
"Null Audio Device"
"Speakers (Steam Streaming Speakers)"
] device [continue]
return audio/init-playback/:pause id
]
;; GitHub Actions on Windows and macOS does not have any audio device.
print as-purple "No audio device found."
quit
]
;; init a playback device...
;; keep the reference to the device handle, else it will be released by GC!
;; (for test purpose, not starting the playback automatically)
device: init-device/pause
]
;; load a sound for later use...
probe sound: audio/load probe %assets/žbluňk_02.wav
print as-green sound/source
;; changing the initial playback start time offset in PCM frames
device/frames: 44100
;; delay the start of the sound in frames
sound/start: 44100
print ["Sound will start in" sound/start - device/frames "frames (1s)..."]
audio/start device ;; finally start the paused playback device
audio/start sound ;; this sound will start after 44100 frames!
wait 1
print "Now there should be the sound!"
wait 1
;; play a looping sound...
print "Now start a loop with fast fade-in (0.5 seconds)..."
probe drums: audio/play/loop/fade %assets/drumloop.wav 0:0:0.5
print as-green drums/source
;; list resources linked with the playback device...
print ["Available sounds:" mold device/resources]
;; work in Rebol as usually
wait 0:0:1
;; for synchronization purposes the global playback time may be accessed and modified
print ["Device global time in PCM frames:" device/frames "as time:" device/time]
print "Modifying global playback time to 44100 PCM frames (1s)"
device/frames: 44100
print ["Device global time in PCM frames:" device/frames "as time:" device/time]
print "Modifying global playback time to 0:0:2"
device/time: 0:0:2
print ["Device global time in PCM frames:" device/frames "as time:" device/time]
;; fade the music with a fade 5 seconds...
print "Now fade out the loop in 5 seconds..."
audio/fade :drums 0:0:5 100% 5%
;; wait for the sound to fade out...
wait 5
;; play already loaded sound...
sound/pan: 1.0
audio/play :sound
wait 1
sound/pan: -1.0
audio/play :device/resources/1
wait 1
;- Using delay node...
delay: audio/make-delay-node 0.25 50% ;; 0.25s delay with 50% decay
print ["Prepared delay:" delay/delay "frames and" delay/decay "decay."]
;; set the music output bus to the delay node...
drums/output: :delay
;; fade in the music
audio/fade :drums 0:0:2.5 5% 100%
wait 5
;; stop the music with a fade 5 seconds...
print "Now stop the loop in 5 seconds fade-out..."
;; modify the decay...
delay/decay: 85%
print ["Decay value changed to:" delay/decay]
audio/stop/fade :drums 0:0:5
wait 4
;- Using a data-source node...
a: 0
b: PI
with audio [
probe wave: make-waveform-node type_sine 0.5 440.0
print ["amplitude:" wave/amplitude "frequency:" wave/frequency]
probe sound: play/fade wave 0:0:3 ;; start playing with a fade..
;; modify the wave's parameters while playing...
loop 500 [
a: a + 0.01
b: b + 0.006
wave/frequency: 440.0 + (220.0 * ((sin a) * cos b))
wait 0.01
]
stop/fade sound 0:0:2
loop 400 [
a: a + 0.02
b: b + 0.003
wave/frequency: 440.0 + (220.0 * ((sin a) * cos b))
wait 0.005
]
]
;; release the playback device (and all resources)
release device
print "done"