This module provides access to the audaspace audio library.
This script shows how to use the classes: Device, Factory and Handle.
import aud
device = aud.device()
# load sound file (it can be a video file with audio)
factory = aud.Factory('music.ogg')
# play the audio, this return a handle to control play/pause
handle = device.play(factory)
# if the audio is not too big and will be used often you can buffer it
factory_buffered = aud.Factory.buffer(factory)
handle_buffered = device.play(factory_buffered)
# stop the sounds (otherwise they play until their ends)
handle.stop()
handle_buffered.stop()
constant value 3
constant value 0
constant value 1
constant value 2
constant value 5
constant value 6
constant value 0
constant value 1
constant value 2
constant value 3
constant value 4
constant value 36
constant value 40
constant value 0
constant value 18
constant value 19
constant value 20
constant value 1
constant value 0
constant value 2
constant value 1
device()
Returns the application’s Device.
return: | The application’s Device. |
---|---|
rtype: | Device |
Device objects represent an audio output backend like OpenAL or SDL, but might also represent a file output or RAM buffer output.
lock()
Locks the device so that it’s guaranteed, that no samples are read from the streams until unlock() is called. This is useful if you want to do start/stop/pause/resume some sounds at the same time.
Note
The device has to be unlocked as often as locked to be able to continue playback.
Warning
Make sure the time between locking and unlocking is as short as possible to avoid clicks.
play(factory, keep=False)
Plays a factory.
Parameters: |
|
---|---|
Returns: | The playback handle with which playback can be controlled with. |
Return type: |
stopAll()
Stops all playing and paused sounds.
unlock()
Unlocks the device after a lock call, see lock() for details.
The channel count of the device.
The distance model of the device.
The doppler factor of the device. This factor is a scaling factor for the velocity vectors in doppler calculation. So a value bigger than 1 will exaggerate the effect as it raises the velocity.
The native sample format of the device.
The listeners’s location in 3D space, a 3D tuple of floats.
The listener’s orientation in 3D space as quaternion, a 4 float tuple.
The listener’s velocity in 3D space, a 3D tuple of floats.
The sampling rate of the device in Hz.
The speed of sound of the device. The speed of sound in air is typically 343 m/s.
The overall volume of the device.
Factory objects are immutable and represent a sound that can be played simultaneously multiple times. They are called factories because they create reader objects internally that are used for playback.
file(filename)
Creates a factory object of a sound file.
Parameters: | filename (string) – Path of the file. |
---|---|
Returns: | The created Factory object. |
Return type: | Factory |
Warning
If the file doesn’t exist or can’t be read you will not get an exception immediately, but when you try to start playback of that factory.
sine(frequency, rate=44100)
Creates a sine factory which plays a sine wave.
Parameters: |
|
---|---|
Returns: | The created Factory object. |
Return type: |
buffer()
Buffers a factory into RAM. This saves CPU usage needed for decoding and file access if the underlying factory reads from a file on the harddisk, but it consumes a lot of memory.
Returns: | The created Factory object. |
---|---|
Return type: | Factory |
Note
Only known-length factories can be buffered.
Warning
Raw PCM data needs a lot of space, only buffer short factories.
delay(time)
Delays by playing adding silence in front of the other factory’s data.
Parameters: | time (float) – How many seconds of silence should be added before the factory. |
---|---|
Returns: | The created Factory object. |
Return type: | Factory |
fadein(start, length)
Fades a factory in by raising the volume linearly in the given time interval.
Parameters: |
|
---|---|
Returns: | The created Factory object. |
Return type: |
Note
Before the fade starts it plays silence.
fadeout(start, length)
Fades a factory in by lowering the volume linearly in the given time interval.
Parameters: |
|
---|---|
Returns: | The created Factory object. |
Return type: |
Note
After the fade this factory plays silence, so that the length of the factory is not altered.
filter(b, a = (1))
Filters a factory with the supplied IIR filter coefficients. Without the second parameter you’ll get a FIR filter. If the first value of the a sequence is 0 it will be set to 1 automatically. If the first value of the a sequence is neither 0 nor 1, all filter coefficients will be scaled by this value so that it is 1 in the end, you don’t have to scale yourself.
Parameters: |
|
---|---|
Returns: | The created Factory object. |
Return type: |
highpass(frequency, Q=0.5)
Creates a second order highpass filter based on the transfer function H(s) = s^2 / (s^2 + s/Q + 1)
Parameters: |
|
---|---|
Returns: | The created Factory object. |
Return type: |
join(factory)
Plays two factories in sequence.
Parameters: | factory (Factory) – The factory to play second. |
---|---|
Returns: | The created Factory object. |
Return type: | Factory |
Note
The two factories have to have the same specifications (channels and samplerate).
limit(start, end)
Limits a factory within a specific start and end time.
Parameters: |
|
---|---|
Returns: | The created Factory object. |
Return type: |
loop(count)
Loops a factory.
Parameters: | count (integer) – How often the factory should be looped. Negative values mean endlessly. |
---|---|
Returns: | The created Factory object. |
Return type: | Factory |
Note
This is a filter function, you might consider using Handle.loop_count instead.
lowpass(frequency, Q=0.5)
Creates a second order lowpass filter based on the transfer function H(s) = 1 / (s^2 + s/Q + 1)
Parameters: |
|
---|---|
Returns: | The created Factory object. |
Return type: |
mix(factory)
Mixes two factories.
Parameters: | factory (Factory) – The factory to mix over the other. |
---|---|
Returns: | The created Factory object. |
Return type: | Factory |
Note
The two factories have to have the same specifications (channels and samplerate).
pingpong()
Plays a factory forward and then backward. This is like joining a factory with its reverse.
Returns: | The created Factory object. |
---|---|
Return type: | Factory |
pitch(factor)
Changes the pitch of a factory with a specific factor.
Parameters: | factor (float) – The factor to change the pitch with. |
---|---|
Returns: | The created Factory object. |
Return type: | Factory |
Note
This is done by changing the sample rate of the underlying factory, which has to be an integer, so the factor value rounded and the factor may not be 100 % accurate.
Note
This is a filter function, you might consider using Handle.pitch instead.
reverse()
Plays a factory reversed.
Returns: | The created Factory object. |
---|---|
Return type: | Factory |
Note
The factory has to have a finite length and has to be seekable. It’s recommended to use this only with factories with fast and accurate seeking, which is not true for encoded audio files, such ones should be buffered using buffer() before being played reversed.
Warning
If seeking is not accurate in the underlying factory you’ll likely hear skips/jumps/cracks.
square(threshold = 0)
Makes a square wave out of an audio wave by setting all samples with a amplitude >= threshold to 1, all <= -threshold to -1 and all between to 0.
Parameters: | threshold (float) – Threshold value over which an amplitude counts non-zero. |
---|---|
Returns: | The created Factory object. |
Return type: | Factory |
volume(volume)
Changes the volume of a factory.
Parameters: | volume (float) – The new volume.. |
---|---|
Returns: | The created Factory object. |
Return type: | Factory |
Note
Should be in the range [0, 1] to avoid clipping.
Note
This is a filter function, you might consider using Handle.volume instead.
Handle objects are playback handles that can be used to control playback of a sound. If a sound is played back multiple times then there are as many handles.
pause()
Pauses playback.
Returns: | Whether the action succeeded. |
---|---|
Return type: | bool |
resume()
Resumes playback.
Returns: | Whether the action succeeded. |
---|---|
Return type: | bool |
stop()
Stops playback.
Returns: | Whether the action succeeded. |
---|---|
Return type: | bool |
Note
This makes the handle invalid.
This factor is used for distance based attenuation of the source.
See also
The opening angle of the inner cone of the source. If the cone values of a source are set there are two (audible) cones with the apex at the location of the source and with infinite height, heading in the direction of the source’s orientation. In the inner cone the volume is normal. Outside the outer cone the volume will be cone_volume_outer and in the area between the volume will be interpolated linearly.
The opening angle of the outer cone of the source.
See also
The volume outside the outer cone of the source.
See also
The maximum distance of the source. If the listener is further away the source volume will be 0.
See also
The reference distance of the source. At this distance the volume will be exactly volume.
See also
Whether the sound should be kept paused in the device when its end is reached. This can be used to seek the sound to some position and start playback again.
Warning
If this is set to true and you forget stopping this equals a memory leak as the handle exists until the device is destroyed.
The source’s location in 3D space, a 3D tuple of floats.
The (remaining) loop count of the sound. A negative value indicates infinity.
The source’s orientation in 3D space as quaternion, a 4 float tuple.
The pitch of the sound.
The playback position of the sound in seconds.
Whether the source’s location, velocity and orientation is relative or absolute to the listener.
Whether the sound is playing, paused or stopped (=invalid).
The source’s velocity in 3D space, a 3D tuple of floats.
The volume of the sound.
The maximum volume of the source.
See also
The minimum volume of the source.
See also