1
1
.. module :: openal.audio
2
2
:synopsis: Advanced OpenAL audio module
3
3
4
- Using openalaudio
5
- =================
4
+ openal.audio - advanced sound support
5
+ ======================================
6
6
:mod: `openal.audio ` is a set of advanced, pythonic classes for 3D positional
7
7
audio support via the OpenAL standard. It utilises :mod: `openal `, but hides all
8
8
the :mod: `ctypes ` related, sequential programming workflow from you. It is
@@ -47,7 +47,6 @@ while each of them uses its own execution context.
47
47
48
48
Placing the listener
49
49
--------------------
50
-
51
50
The OpenAL standard supports 3D positional audio, so that a source of sound can
52
51
be placed anywhere relative to the listener (the user of the application or
53
52
some in-application avatar).
@@ -121,7 +120,6 @@ ears of you receive the noise in nearly the same way).
121
120
122
121
Creating sound sources
123
122
----------------------
124
-
125
123
A :class: `SoundSource ` represents an object that can emit sounds. It can be any
126
124
kind of object and allows you to play any sound, you put into it. In an
127
125
application you can enable objects to emit sounds, by binding a
@@ -135,7 +133,6 @@ application you can enable objects to emit sounds, by binding a
135
133
136
134
Creating and playing sounds
137
135
---------------------------
138
-
139
136
To create and play sounds you use :class: `SoundData ` objects, which contain the
140
137
raw PCM data to be played. To play the sound, the :class: `SoundData ` needs to
141
138
be queued on a :class: `SoundSource `, which provides all the necessary
@@ -148,20 +145,160 @@ There are some helper functions, which create :class:`SoundData` objects from
148
145
audio files. If you have a raw PCM data buffer, you can create a
149
146
:class: `SoundData ` from it directly. ::
150
147
151
- >>> rawsound = SoundData(pcmformat, pcmbuf, size_of_buf, frequency_in_hz)
148
+ >>> rawsound = SoundData(pcmbuf, size_of_buf, channels, bitrate , frequency_in_hz)
152
149
153
- Queueing the loaded sound is done via the :meth: `SoundSource.queue() ` or
154
- :meth: `SoundSource.play() ` method, which appends the sound to the source for
155
- processing and playback. ::
150
+ Queueing the loaded sound is done via the :meth: `SoundSource.queue() ` method,
151
+ which appends the sound to the source for processing and playback. ::
156
152
157
153
>>> wavsound = load_wav_file("vroom.wav")
158
- >>> source.play (wavsound)
154
+ >>> source.queue (wavsound)
159
155
160
156
You just need to inform the :class: `SoundSink ` about the :class: `SoundSource `
161
157
afterwards, so that it knows that a new sound emitter is available. ::
162
158
163
159
>>> soundsink.play(source)
164
160
165
161
When you add other sounds to play to the source, they will be picked up
166
- automatically for playback, as long as the :class: `SoundSource ` is not paused,
167
- stopped or ran out of something to play.
162
+ automatically for playback, as long as the :class: `SoundSource ` is not paused
163
+ or ran out of something to play.
164
+
165
+ API
166
+ ^^^
167
+
168
+ .. class :: OpenALError([msg=None[, alcdevice=None]])
169
+
170
+ An OpenAL specific exception class. If a new :class: `OpenALError ` is created
171
+ and no *msg * is provided, the message will be set a mapped value of
172
+ :meth: `openal.al.alGetError() `. If an :class: `openal.alc.ALCdevice ` is
173
+ provided as *alcdevice *, :meth: `openal.alc.alcGetError() ` will be used
174
+ instead of :meth: `openal.al.alGetError() `.
175
+
176
+ .. class :: SoundData(data=None, channels=None, bitrate=None, size=None, \
177
+ frequency=None, dformat=None)
178
+
179
+ The :class: `SoundData ` consists of a PCM audio data buffer, the audio
180
+ frequency and additional format information to allow easy buffering through
181
+ OpenAL.
182
+
183
+ .. attribute :: channels
184
+
185
+ The channel count for the sound data.
186
+
187
+ .. attribute :: bitrate
188
+
189
+ The bitrate of the sound data.
190
+
191
+ .. attribute :: size
192
+
193
+ The buffer size in bytes.
194
+
195
+ .. attribute :: frequency
196
+
197
+ The sound frequency in Hz.
198
+
199
+ .. attribute :: data
200
+
201
+ The buffered audio data.
202
+
203
+ .. class :: SoundListener(position=[0, 0, 0], velocity=[0, 0, 0], \
204
+ orientation=[0, 0, -1, 0, 1, 0])
205
+
206
+ A listener object within the 3D audio space.
207
+
208
+ .. attribute :: orientation
209
+
210
+ The listening orientation as 6-value list.
211
+
212
+ .. attribute :: position
213
+
214
+ The listener position as 3-value list.
215
+
216
+ .. attribute :: velocity
217
+
218
+ The movement velocity as 3-value list.
219
+
220
+ .. attribute :: gain
221
+
222
+ The relative sound volume (perceiptive for the listener).
223
+
224
+ .. attribute :: changed
225
+
226
+ Indicates, if an attribute has been changed.
227
+
228
+ .. class :: SoundSource(gain=1.0, pitch=1.0, position=[0, 0, 0], \
229
+ velocity=[0, 0, 0])
230
+
231
+ An object within the application world, which can emit sounds.
232
+
233
+ .. attribute :: gain
234
+
235
+ The volume gain of the source.
236
+
237
+ .. attribute :: pitch
238
+
239
+ The pitch of the source.
240
+
241
+ .. attribute :: position
242
+
243
+ The (initial) position of the source as 3-value tuple in a x-y-z
244
+ coordinate system.
245
+
246
+ .. attribute :: velocity
247
+
248
+ The velocity of the source as 3-value tuple in a x-y-z coordinate system.
249
+
250
+ .. method :: queue(sounddata : SoundData) -> None
251
+
252
+ Adds a :class: `SoundData ` audio buffer to the source's processing and
253
+ playback queue.
254
+
255
+ .. class :: SoundSink(device=None)
256
+
257
+ Audio playback system.
258
+
259
+ The SoundSink handles audio output for sound sources. It connects to an
260
+ audio output device and manages the source settings, their buffer queues
261
+ and the playback of them.
262
+
263
+ .. attribute :: device
264
+
265
+ The used OpenAL :class: `openal.alc.ALCdevice `.
266
+
267
+ .. attribute :: context
268
+
269
+ The used :class: `openal.alc.ALCcontext `.
270
+
271
+ .. method :: activate() -> None
272
+
273
+ Activates the :class: `SoundSink `, marking its :attr: `context ` as the
274
+ currently active one.
275
+
276
+ Subsequent OpenAL operations are done in the context of the
277
+ SoundSink's bindings.
278
+
279
+ .. method :: set_listener(listener : SoundListener) -> None
280
+
281
+ Sets the listener position for the :class: `SoundSink `.
282
+
283
+ .. note ::
284
+
285
+ This implicitly activates the :class: `SoundSink `.
286
+
287
+ .. method :: process_source(source : SoundSource) -> None
288
+
289
+ Processes a single :class: `SoundSource `.
290
+
291
+ .. note ::
292
+
293
+ This does *not * activate the :class: `SoundSink `. If another
294
+ :class: `SoundSink ` is active, chances are good that the
295
+ source is processed in that :class: `SoundSink `.
296
+
297
+ .. method :: process(world, components) -> None
298
+
299
+ Processes :class: `SoundSource ` components, according to their
300
+ :attr: `SoundSource.request `
301
+
302
+ .. note ::
303
+
304
+ This implicitly activates the :class: `SoundSink `.
0 commit comments