sound_lib 0.82__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sound_lib/__init__.py +26 -0
- sound_lib/channel.py +680 -0
- sound_lib/config.py +72 -0
- sound_lib/effects/__init__.py +2 -0
- sound_lib/effects/bass.py +57 -0
- sound_lib/effects/bass_fx.py +21 -0
- sound_lib/effects/effect.py +103 -0
- sound_lib/effects/tempo.py +112 -0
- sound_lib/encoder.py +188 -0
- sound_lib/external/__init__.py +10 -0
- sound_lib/external/paths.py +9 -0
- sound_lib/external/pybass.py +1127 -0
- sound_lib/external/pybass_aac.py +53 -0
- sound_lib/external/pybass_alac.py +24 -0
- sound_lib/external/pybass_fx.py +383 -0
- sound_lib/external/pybassenc.py +169 -0
- sound_lib/external/pybassflac.py +41 -0
- sound_lib/external/pybassmidi.py +205 -0
- sound_lib/external/pybassmix.py +116 -0
- sound_lib/external/pybassopus.py +31 -0
- sound_lib/external/pybasswasapi.py +154 -0
- sound_lib/external/pybasswma.py +149 -0
- sound_lib/external/pytags.py +48 -0
- sound_lib/input.py +161 -0
- sound_lib/lib/x64/bass.dll +0 -0
- sound_lib/lib/x64/bass_aac.dll +0 -0
- sound_lib/lib/x64/bass_alac.dll +0 -0
- sound_lib/lib/x64/bass_fx.dll +0 -0
- sound_lib/lib/x64/bassflac.dll +0 -0
- sound_lib/lib/x64/bassmidi.dll +0 -0
- sound_lib/lib/x64/bassmix.dll +0 -0
- sound_lib/lib/x64/bassopus.dll +0 -0
- sound_lib/lib/x64/basswasapi.dll +0 -0
- sound_lib/lib/x64/basswma.dll +0 -0
- sound_lib/lib/x64/libbass.dylib +0 -0
- sound_lib/lib/x64/libbass.so +0 -0
- sound_lib/lib/x64/libbass_aac.so +0 -0
- sound_lib/lib/x64/libbass_alac.so +0 -0
- sound_lib/lib/x64/libbass_fx.dylib +0 -0
- sound_lib/lib/x64/libbass_fx.so +0 -0
- sound_lib/lib/x64/libbassenc.so +0 -0
- sound_lib/lib/x64/libbassflac.so +0 -0
- sound_lib/lib/x64/libbassmidi.so +0 -0
- sound_lib/lib/x64/libbassmix.so +0 -0
- sound_lib/lib/x64/libbassopus.dylib +0 -0
- sound_lib/lib/x64/libbassopus.so +0 -0
- sound_lib/lib/x64/libtags.so +0 -0
- sound_lib/lib/x64/tags.dll +0 -0
- sound_lib/lib/x86/bass.dll +0 -0
- sound_lib/lib/x86/bass_aac.dll +0 -0
- sound_lib/lib/x86/bass_alac.dll +0 -0
- sound_lib/lib/x86/bass_fx.dll +0 -0
- sound_lib/lib/x86/bassenc.dll +0 -0
- sound_lib/lib/x86/bassflac.dll +0 -0
- sound_lib/lib/x86/bassmidi.dll +0 -0
- sound_lib/lib/x86/bassmix.dll +0 -0
- sound_lib/lib/x86/bassopus.dll +0 -0
- sound_lib/lib/x86/basswasapi.dll +0 -0
- sound_lib/lib/x86/basswma.dll +0 -0
- sound_lib/lib/x86/libbass.dylib +0 -0
- sound_lib/lib/x86/libbass.so +0 -0
- sound_lib/lib/x86/libbass_aac.dylib +0 -0
- sound_lib/lib/x86/libbass_aac.so +0 -0
- sound_lib/lib/x86/libbass_alac.so +0 -0
- sound_lib/lib/x86/libbass_fx.dylib +0 -0
- sound_lib/lib/x86/libbass_fx.so +0 -0
- sound_lib/lib/x86/libbassenc.dylib +0 -0
- sound_lib/lib/x86/libbassenc.so +0 -0
- sound_lib/lib/x86/libbassflac.dylib +0 -0
- sound_lib/lib/x86/libbassflac.so +0 -0
- sound_lib/lib/x86/libbassmidi.dylib +0 -0
- sound_lib/lib/x86/libbassmidi.so +0 -0
- sound_lib/lib/x86/libbassmix.dylib +0 -0
- sound_lib/lib/x86/libbassmix.so +0 -0
- sound_lib/lib/x86/libbassopus.dylib +0 -0
- sound_lib/lib/x86/libbassopus.so +0 -0
- sound_lib/lib/x86/libtags.dylib +0 -0
- sound_lib/lib/x86/libtags.so +0 -0
- sound_lib/lib/x86/tags.dll +0 -0
- sound_lib/listener.py +200 -0
- sound_lib/main.py +136 -0
- sound_lib/music.py +19 -0
- sound_lib/output.py +321 -0
- sound_lib/recording.py +85 -0
- sound_lib/stream.py +163 -0
- sound_lib-0.82.dist-info/LICENSE +19 -0
- sound_lib-0.82.dist-info/METADATA +20 -0
- sound_lib-0.82.dist-info/RECORD +91 -0
- sound_lib-0.82.dist-info/WHEEL +6 -0
- sound_lib-0.82.dist-info/dependency_links.txt +2 -0
- sound_lib-0.82.dist-info/top_level.txt +1 -0
sound_lib/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
__author__ = "Christopher Toth"
|
|
2
|
+
__version__ = 0.82
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def find_datafiles():
|
|
6
|
+
""" """
|
|
7
|
+
from glob import glob
|
|
8
|
+
import os
|
|
9
|
+
import platform
|
|
10
|
+
import sound_lib
|
|
11
|
+
|
|
12
|
+
path = os.path.join(sound_lib.__path__[0], "lib")
|
|
13
|
+
system = platform.system()
|
|
14
|
+
if system == "Windows":
|
|
15
|
+
file_ext = "*.dll"
|
|
16
|
+
elif system == "Darwin":
|
|
17
|
+
file_ext = "*.dylib"
|
|
18
|
+
else:
|
|
19
|
+
file_ext = "*.so"
|
|
20
|
+
if platform.architecture()[0] == "32bit" or platform.system() == "Darwin":
|
|
21
|
+
arch = "x86"
|
|
22
|
+
else:
|
|
23
|
+
arch = "x64"
|
|
24
|
+
dest_dir = os.path.join("sound_lib", "lib", arch)
|
|
25
|
+
source = glob(os.path.join(path, arch, file_ext))
|
|
26
|
+
return [(dest_dir, source)]
|
sound_lib/channel.py
ADDED
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from .external.pybass import *
|
|
3
|
+
from .main import bass_call, bass_call_0, BassError, update_3d_system, FlagObject
|
|
4
|
+
from ctypes import pointer, c_float, c_long, c_ulong, c_buffer
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Channel(FlagObject):
|
|
8
|
+
"""A "channel" can be a sample playback channel (HCHANNEL), a sample stream (HSTREAM), a MOD music (HMUSIC), or a recording (HRECORD).
|
|
9
|
+
Chances are, if you're playing audio, you're using a channel on one level or another.
|
|
10
|
+
Each "Channel" function can be used with one or more of these channel types.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
attribute_mapping = {}
|
|
14
|
+
|
|
15
|
+
def __init__(self, handle):
|
|
16
|
+
self.handle = handle
|
|
17
|
+
self.attribute_mapping = {
|
|
18
|
+
"eaxmix": BASS_ATTRIB_EAXMIX,
|
|
19
|
+
"frequency": BASS_ATTRIB_FREQ,
|
|
20
|
+
"pan": BASS_ATTRIB_PAN,
|
|
21
|
+
"volume": BASS_ATTRIB_VOL,
|
|
22
|
+
"byte": BASS_POS_BYTE,
|
|
23
|
+
"decode": BASS_POS_DECODE,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def add_attributes_to_mapping(self, **attrs):
|
|
27
|
+
self.attribute_mapping.update(**attrs)
|
|
28
|
+
|
|
29
|
+
def play(self, restart=False):
|
|
30
|
+
"""Starts (or resumes) playback of a sample, stream, MOD music, or recording.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
restart (bool): Specifies whether playback position should be thrown to the beginning of the stream. Defaults to False
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
bool: True on success, False otherwise.
|
|
37
|
+
"""
|
|
38
|
+
return bass_call(BASS_ChannelPlay, self.handle, restart)
|
|
39
|
+
|
|
40
|
+
def play_blocking(self, restart=False):
|
|
41
|
+
"""Starts (or resumes) playback, waiting to return until reaching the end of the stream
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
restart (bool): Specifies whether playback position should be thrown to the beginning of the stream. Defaults to False.
|
|
45
|
+
"""
|
|
46
|
+
self.play(restart=restart)
|
|
47
|
+
while self.is_playing:
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
def pause(self):
|
|
51
|
+
"""Pauses a sample, stream, MOD music, or recording.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
bool: True on success, False otherwise.
|
|
55
|
+
|
|
56
|
+
raises:
|
|
57
|
+
sound_lib.main.BassError: If this channel isn't currently playing, already paused, or is a decoding channel and thus not playable.
|
|
58
|
+
"""
|
|
59
|
+
return bass_call(BASS_ChannelPause, self.handle)
|
|
60
|
+
|
|
61
|
+
def is_active(self):
|
|
62
|
+
"""Checks if a sample, stream, or MOD music is active (playing) or stalled. Can also check if a recording is in progress.
|
|
63
|
+
"""
|
|
64
|
+
return bass_call_0(BASS_ChannelIsActive, self.handle)
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def is_playing(self):
|
|
68
|
+
"""Checks whether the stream is currently playing or recording.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
bool: True if playing, False otherwise.
|
|
72
|
+
"""
|
|
73
|
+
return self.is_active() == BASS_ACTIVE_PLAYING
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def is_paused(self):
|
|
77
|
+
"""
|
|
78
|
+
Checks whether the stream is currently paused.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
bool: True if paused, False otherwise.
|
|
82
|
+
"""
|
|
83
|
+
return self.is_active() == BASS_ACTIVE_PAUSED
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def is_stopped(self):
|
|
87
|
+
"""
|
|
88
|
+
Checks whether the stream is currently stopped.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
bool: True if stopped, False otherwise.
|
|
92
|
+
"""
|
|
93
|
+
return self.is_active() == BASS_ACTIVE_STOPPED
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def is_stalled(self):
|
|
97
|
+
"""
|
|
98
|
+
Checks whether playback of a stream has been stalled.
|
|
99
|
+
This is due to a lack of sample data. Playback will automatically resume once there is sufficient data to do so.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
bool: True if stalled, False otherwise.
|
|
103
|
+
"""
|
|
104
|
+
return self.is_active() == BASS_ACTIVE_STALLED
|
|
105
|
+
|
|
106
|
+
def get_position(self, mode=BASS_POS_BYTE):
|
|
107
|
+
"""Retrieves the playback position of a sample, stream, or MOD music. Can also be used with a recording channel.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
mode (str): How to retrieve the position. Defaults to "byte".
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
int: The current position.
|
|
114
|
+
|
|
115
|
+
raises:
|
|
116
|
+
sound_lib.main.BassError: If the requested position is not available.
|
|
117
|
+
"""
|
|
118
|
+
return bass_call_0(BASS_ChannelGetPosition, self.handle, mode)
|
|
119
|
+
|
|
120
|
+
def set_position(self, pos, mode=BASS_POS_BYTE):
|
|
121
|
+
"""Sets the playback position of a sample, MOD music, or stream.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
pos (int): The position, in units determined by the mode.
|
|
125
|
+
mode: (str): How to set the position. Defaults to "byte".
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
bool: True if the position was set, False otherwise.
|
|
129
|
+
|
|
130
|
+
raises:
|
|
131
|
+
sound_lib.main.BassError: If the stream is not a sound_lib.stream.FileStream or the requested position/mode is not available.
|
|
132
|
+
"""
|
|
133
|
+
return bass_call(BASS_ChannelSetPosition, self.handle, pos, mode)
|
|
134
|
+
|
|
135
|
+
position = property(get_position, set_position)
|
|
136
|
+
|
|
137
|
+
def stop(self):
|
|
138
|
+
"""Stops a sample, stream, MOD music, or recording."""
|
|
139
|
+
return bass_call(BASS_ChannelStop, self.handle)
|
|
140
|
+
|
|
141
|
+
def update(self, length=0):
|
|
142
|
+
"""Updates the playback buffer of a stream or MOD music.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
length (int): The amount of data to render, in milliseconds...
|
|
146
|
+
0 = default (2 x update period). This is capped at the space available in the buffer.
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
bool: True on success, False otherwise.
|
|
150
|
+
|
|
151
|
+
raises:
|
|
152
|
+
sound_lib.main.BassError: If this channel has ended or doesn't have an output -buffer.
|
|
153
|
+
"""
|
|
154
|
+
return bass_call(BASS_ChannelUpdate, self.handle, length)
|
|
155
|
+
|
|
156
|
+
def get_length(self, mode=BASS_POS_BYTE):
|
|
157
|
+
"""Retrieves the playback length of this channel.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
mode: How to retrieve the length. Can take either a flag attribute (string) or bass constent (int). Defaults to "byte".
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
int: The channel length on success, -1 on failure.
|
|
164
|
+
|
|
165
|
+
raises:
|
|
166
|
+
sound_lib.main.BassError: If the requested mode is not available.
|
|
167
|
+
"""
|
|
168
|
+
return bass_call_0(BASS_ChannelGetLength, self.handle, mode)
|
|
169
|
+
|
|
170
|
+
__len__ = get_length
|
|
171
|
+
|
|
172
|
+
def __nonzero__(self):
|
|
173
|
+
return True
|
|
174
|
+
|
|
175
|
+
def get_device(self):
|
|
176
|
+
"""Retrieves the device in use by this channel.
|
|
177
|
+
|
|
178
|
+
returns:
|
|
179
|
+
int: The device number, -1 on failure.
|
|
180
|
+
"""
|
|
181
|
+
return bass_call_0(BASS_ChannelGetDevice, self.handle)
|
|
182
|
+
|
|
183
|
+
def set_device(self, device):
|
|
184
|
+
"""Changes the device in use by this channel. Must be a stream, MOD music or sample.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
device: The device to use... 0 = no sound, 1 = first real output device, BASS_NODEVICE = no device.
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
bool: True on success, False otherwise.
|
|
191
|
+
|
|
192
|
+
raises:
|
|
193
|
+
sound_lib.main.BassError: If device is invalid, device hasn't been initialized, this channel is already using the requested device, the sample format is not supported by the device/drivers or there is insufficient memory.
|
|
194
|
+
"""
|
|
195
|
+
bass_call(BASS_ChannelSetDevice, self.handle, device)
|
|
196
|
+
|
|
197
|
+
device = property(get_device, set_device)
|
|
198
|
+
|
|
199
|
+
def set_fx(self, type, priority=0):
|
|
200
|
+
"""Sets an effect on a stream, MOD music, or recording channel.
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
type: The type of effect
|
|
204
|
+
priority: The priority of the new FX, which determines its position in the DSP chain. DSP/FX with higher priority are applied before those with lower. This parameter has no effect with DX8 effects when the "with FX flag" DX8 effect implementation is used. Defaults to 0.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
A handle to the new effect on success, False otherwise.
|
|
208
|
+
|
|
209
|
+
raises:
|
|
210
|
+
sound_lib.main.BassError: If type is invalid, the specified DX8 effect is unavailable or this channel's format is not supported by the effect.
|
|
211
|
+
"""
|
|
212
|
+
return SoundEffect(bass_call(BASS_ChannelSetFX, type, priority))
|
|
213
|
+
|
|
214
|
+
def bytes_to_seconds(self, position=None):
|
|
215
|
+
"""Translates a byte position into time (seconds), based on the format in use by this channel.
|
|
216
|
+
|
|
217
|
+
Args:
|
|
218
|
+
position: The position to translate. Defaults to None
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
int: The translated length on success, a negative bass error code on failure.
|
|
222
|
+
"""
|
|
223
|
+
position = position or self.position
|
|
224
|
+
return bass_call_0(BASS_ChannelBytes2Seconds, self.handle, position)
|
|
225
|
+
|
|
226
|
+
def length_in_seconds(self):
|
|
227
|
+
"""Retrieves the length of the stream, in seconds, regardless of position.
|
|
228
|
+
|
|
229
|
+
returns:
|
|
230
|
+
int: The length on success, a negative bass error code on failure.
|
|
231
|
+
"""
|
|
232
|
+
return self.bytes_to_seconds(self.get_length())
|
|
233
|
+
|
|
234
|
+
def seconds_to_bytes(self, position):
|
|
235
|
+
"""Translates a time (seconds) position into bytes, based on the format in use by this channel.
|
|
236
|
+
|
|
237
|
+
Args:
|
|
238
|
+
position: The position to translate.
|
|
239
|
+
|
|
240
|
+
Returns:
|
|
241
|
+
int: The translated length on success, a negative bass error code on failure.
|
|
242
|
+
"""
|
|
243
|
+
return bass_call_0(BASS_ChannelSeconds2Bytes, self.handle, position)
|
|
244
|
+
|
|
245
|
+
def get_attribute(self, attribute):
|
|
246
|
+
"""Retrieves the value of this channel's attribute.
|
|
247
|
+
|
|
248
|
+
Args:
|
|
249
|
+
attribute: The attribute to get the value of. Can either be an of type str or int.
|
|
250
|
+
|
|
251
|
+
Returns:
|
|
252
|
+
The value on success, None on failure.
|
|
253
|
+
|
|
254
|
+
raises:
|
|
255
|
+
sound_lib.main.BassError: If the attribute is either unavailable or invalid.
|
|
256
|
+
Some attributes have additional possible instances where an exception might be raised.
|
|
257
|
+
"""
|
|
258
|
+
value = pointer(c_float())
|
|
259
|
+
if attribute in self.attribute_mapping:
|
|
260
|
+
attribute = self.attribute_mapping[attribute]
|
|
261
|
+
bass_call(BASS_ChannelGetAttribute, self.handle, attribute, value)
|
|
262
|
+
return value.contents.value
|
|
263
|
+
|
|
264
|
+
def set_attribute(self, attribute, value):
|
|
265
|
+
"""Sets the value of an attribute on this channel.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
attribute: The attribute to set the value of. Can either be of type str or int.
|
|
269
|
+
value:
|
|
270
|
+
|
|
271
|
+
Returns:
|
|
272
|
+
bool: True on success, False on failure.
|
|
273
|
+
|
|
274
|
+
raises:
|
|
275
|
+
sound_lib.main.BassError: If either attribute or value is invalid.
|
|
276
|
+
"""
|
|
277
|
+
if attribute in self.attribute_mapping:
|
|
278
|
+
attribute = self.attribute_mapping[attribute]
|
|
279
|
+
return bass_call(BASS_ChannelSetAttribute, self.handle, attribute, value)
|
|
280
|
+
|
|
281
|
+
def slide_attribute(self, attribute, value, time):
|
|
282
|
+
"""Slides this channel's attribute from its current value to a new value.
|
|
283
|
+
|
|
284
|
+
Args:
|
|
285
|
+
attribute: The attribute to slide the value of.
|
|
286
|
+
value: The new attribute value. Consult specific documentation depending on the one in question.
|
|
287
|
+
time: The length of time (in milliseconds) that it should take for the attribute to reach the value.
|
|
288
|
+
|
|
289
|
+
Returns:
|
|
290
|
+
bool: True on success, False on failure.
|
|
291
|
+
|
|
292
|
+
raises:
|
|
293
|
+
sound_lib.main.BassError: If attribute is invalid, or the attributes value is set to go from positive to negative or vice versa when the BASS_SLIDE_LOG flag is used.
|
|
294
|
+
"""
|
|
295
|
+
if attribute in self.attribute_mapping:
|
|
296
|
+
attribute = self.attribute_mapping[attribute]
|
|
297
|
+
return bass_call(
|
|
298
|
+
BASS_ChannelSlideAttribute, self.handle, attribute, value, time * 1000
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
def is_sliding(self, attribute=0):
|
|
302
|
+
"""Checks if an attribute (or any attribute) of this channel is sliding. Must be a sample, stream, or MOD music.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
attribute: The attribute to check for sliding, or0 for any. Defaults to 0.
|
|
306
|
+
|
|
307
|
+
Returns:
|
|
308
|
+
bool: True if sliding, False otherwise.
|
|
309
|
+
|
|
310
|
+
"""
|
|
311
|
+
return bass_call_0(BASS_ChannelIsSliding, self.handle, attribute)
|
|
312
|
+
|
|
313
|
+
def get_info(self):
|
|
314
|
+
"""Retrieves information on this channel.
|
|
315
|
+
|
|
316
|
+
returns:
|
|
317
|
+
A BASS_CHANNELINFO structure.
|
|
318
|
+
"""
|
|
319
|
+
value = pointer(BASS_CHANNELINFO())
|
|
320
|
+
bass_call(BASS_ChannelGetInfo, self.handle, value)
|
|
321
|
+
return value[0]
|
|
322
|
+
|
|
323
|
+
def get_level(self):
|
|
324
|
+
"""Retrieves the level (peak amplitude) of a stream, MOD music or recording channel.
|
|
325
|
+
|
|
326
|
+
returns:
|
|
327
|
+
int: -1 on error. If successful, the level of the left channel is returned in the low word (low 16 bits), and the level of the right channel is returned in the high word (high 16 bits).
|
|
328
|
+
If the channel is mono, then the low word is duplicated in the high word. The level ranges linearly from 0 (silent) to 32768 (max).
|
|
329
|
+
0 will be returned when a channel is stalled.
|
|
330
|
+
|
|
331
|
+
raises:
|
|
332
|
+
sound_lib.main.BassError: If this channel is not playing, or this is a decoding channel which has reached the end
|
|
333
|
+
"""
|
|
334
|
+
return bass_call_0(BASS_ChannelGetLevel, self.handle)
|
|
335
|
+
|
|
336
|
+
def lock(self):
|
|
337
|
+
"""Locks a stream, MOD music or recording channel to the current thread.
|
|
338
|
+
|
|
339
|
+
returns:
|
|
340
|
+
bool: True on success, False on failure.
|
|
341
|
+
"""
|
|
342
|
+
return bass_call(BASS_ChannelLock, self.handle, True)
|
|
343
|
+
|
|
344
|
+
def unlock(self):
|
|
345
|
+
"""Unlocks a stream, MOD music or recording channel from the current thread.
|
|
346
|
+
|
|
347
|
+
returns:
|
|
348
|
+
bool: True on success, False on failure.
|
|
349
|
+
"""
|
|
350
|
+
return bass_call(BASS_ChannelLock, self.handle, False)
|
|
351
|
+
|
|
352
|
+
def get_3d_attributes(self):
|
|
353
|
+
"""Retrieves the 3D attributes of a sample, stream, or MOD music channel with 3D functionality.
|
|
354
|
+
|
|
355
|
+
returns:
|
|
356
|
+
dict: A dict containing the stream's 3d attributes
|
|
357
|
+
|
|
358
|
+
raises:
|
|
359
|
+
sound_lib.main.BassError: If this channel does not have 3d functionality.
|
|
360
|
+
"""
|
|
361
|
+
answer = dict(
|
|
362
|
+
mode=c_ulong(),
|
|
363
|
+
min=c_float(),
|
|
364
|
+
max=c_float(),
|
|
365
|
+
iangle=c_ulong(),
|
|
366
|
+
oangle=c_ulong(),
|
|
367
|
+
outvol=c_float(),
|
|
368
|
+
)
|
|
369
|
+
bass_call(
|
|
370
|
+
BASS_ChannelGet3DAttributes,
|
|
371
|
+
self.handle,
|
|
372
|
+
pointer(answer["mode"]),
|
|
373
|
+
pointer(answer["min"]),
|
|
374
|
+
pointer(answer["max"]),
|
|
375
|
+
pointer(answer["iangle"]),
|
|
376
|
+
pointer(answer["oangle"]),
|
|
377
|
+
pointer(answer["outvol"]),
|
|
378
|
+
)
|
|
379
|
+
for k in answer:
|
|
380
|
+
answer[k] = answer[k].value()
|
|
381
|
+
return answer
|
|
382
|
+
|
|
383
|
+
@update_3d_system
|
|
384
|
+
def set_3d_attributes(
|
|
385
|
+
self, mode=-1, min=0.0, max=0.0, iangle=-1, oangle=-1, outvol=-1
|
|
386
|
+
):
|
|
387
|
+
"""Sets the 3D attributes of a sample, stream, or MOD music channel with 3D functionality.
|
|
388
|
+
|
|
389
|
+
Args:
|
|
390
|
+
mode: The 3D processing mode. Defaults to -1.
|
|
391
|
+
min (float): The minimum distance. The channel's volume is at maximum when the listener is within this distance... 0 or less = leave current. Defaults to 0.0.
|
|
392
|
+
max (float): The maximum distance. The channel's volume stops decreasing when the listener is beyond this distance... 0 or less = leave current. Defaults to 0.0.
|
|
393
|
+
iangle (int): The angle of the inside projection cone in degrees... 0 (no cone) to 360 (sphere), -1 = leave current. Defaults to -1.
|
|
394
|
+
oangle (int): The angle of the inside projection cone in degrees... 0 (no cone) to 360 (sphere), -1 = leave current. Defaults to -1.
|
|
395
|
+
outvol (float): The delta-volume outside the outer projection cone... 0 (silent) to 1 (same as inside the cone), less than 0 = leave current. Defaults to -1.0.
|
|
396
|
+
|
|
397
|
+
Returns:
|
|
398
|
+
bool: True on success, False otherwise.
|
|
399
|
+
|
|
400
|
+
raises:
|
|
401
|
+
sound_lib.main.BassError: If this channel does not have 3d functionality, or one or more attribute values are invalid.
|
|
402
|
+
"""
|
|
403
|
+
return bass_call(
|
|
404
|
+
BASS_ChannelSet3DAttributes,
|
|
405
|
+
self.handle,
|
|
406
|
+
mode,
|
|
407
|
+
min,
|
|
408
|
+
max,
|
|
409
|
+
iangle,
|
|
410
|
+
oangle,
|
|
411
|
+
outvol,
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
def get_3d_position(self):
|
|
415
|
+
"""Retrieves the 3D position of a sample, stream, or MOD music channel with 3D functionality.
|
|
416
|
+
|
|
417
|
+
raises:
|
|
418
|
+
sound_lib.main.BassError: If this channel was not initialized with support for 3d functionality.
|
|
419
|
+
"""
|
|
420
|
+
answer = dict(
|
|
421
|
+
position=BASS_3DVECTOR(),
|
|
422
|
+
orientation=BASS_3DVECTOR(),
|
|
423
|
+
velocity=BASS_3DVECTOR(),
|
|
424
|
+
)
|
|
425
|
+
bass_call(
|
|
426
|
+
BASS_ChannelGet3DPosition,
|
|
427
|
+
self.handle,
|
|
428
|
+
pointer(answer["position"]),
|
|
429
|
+
pointer(answer["orientation"]),
|
|
430
|
+
pointer(answer["velocity"]),
|
|
431
|
+
)
|
|
432
|
+
return answer
|
|
433
|
+
|
|
434
|
+
@update_3d_system
|
|
435
|
+
def set_3d_position(self, position=None, orientation=None, velocity=None):
|
|
436
|
+
"""Sets the 3D position of a sample, stream, or MOD music channel with 3D functionality.
|
|
437
|
+
|
|
438
|
+
Args:
|
|
439
|
+
position: Defaults to None.
|
|
440
|
+
orientation: Defaults to None.
|
|
441
|
+
velocity: Defaults to None
|
|
442
|
+
|
|
443
|
+
raises:
|
|
444
|
+
sound_lib.main.BassError: If this channel was not initialized with support for 3d functionality.
|
|
445
|
+
"""
|
|
446
|
+
if position:
|
|
447
|
+
position = pointer(position)
|
|
448
|
+
if orientation:
|
|
449
|
+
orientation = pointer(orientation)
|
|
450
|
+
if velocity:
|
|
451
|
+
velocity = pointer(velocity)
|
|
452
|
+
return bass_call(
|
|
453
|
+
BASS_ChannelSet3DPosition, self.handle, position, orientation, velocity
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
def set_link(self, handle):
|
|
457
|
+
"""Links two MOD music or stream channels together.
|
|
458
|
+
|
|
459
|
+
Args:
|
|
460
|
+
handle: The bass handle to link with this one. Can take both a sound_lib.channel or bass handle. Must be HMUSIC or HSTREAM.
|
|
461
|
+
|
|
462
|
+
Returns:
|
|
463
|
+
bool: True on success, False on failure.
|
|
464
|
+
|
|
465
|
+
raises:
|
|
466
|
+
sound_lib.main.BassError: If handle points to an invalid channel, either one is a decoding channel, or this channel is already linked to handle.
|
|
467
|
+
"""
|
|
468
|
+
if isinstance(handle, Channel):
|
|
469
|
+
handle=handle.handle
|
|
470
|
+
bass_call(BASS_ChannelSetLink, self.handle, handle)
|
|
471
|
+
|
|
472
|
+
def remove_link(self, handle):
|
|
473
|
+
"""Removes a link between two MOD music or stream channels.
|
|
474
|
+
|
|
475
|
+
Args:
|
|
476
|
+
handle: The bass handle to unlink with this one. Can take both a sound_lib.channel or bass handle. Must be a HMUSIC or HSTREAM. Must currently be linked.
|
|
477
|
+
|
|
478
|
+
Returns:
|
|
479
|
+
bool: True on success, False on failure.
|
|
480
|
+
raises:
|
|
481
|
+
sound_lib.main.BassError: If chan is either not a valid channel, or is not already linked to handle.
|
|
482
|
+
|
|
483
|
+
"""
|
|
484
|
+
if isinstance(handle, Channel):
|
|
485
|
+
handle=handle.handle
|
|
486
|
+
return bass_call(BASS_ChannelRemoveLink, self.handle, handle)
|
|
487
|
+
|
|
488
|
+
def __iadd__(self, other):
|
|
489
|
+
"""Convenience method to link this channel to another. Calls set_link on the passed in item's handle"""
|
|
490
|
+
self.set_link(other.handle)
|
|
491
|
+
return self
|
|
492
|
+
|
|
493
|
+
def __isub__(self, other):
|
|
494
|
+
"""Convenience method to unlink this channel from another. Calls remove_link on the passed in item's handle"""
|
|
495
|
+
self.remove_link(other.handle)
|
|
496
|
+
return self
|
|
497
|
+
|
|
498
|
+
def get_frequency(self):
|
|
499
|
+
"""Retrieves sample frequency (sample rate).
|
|
500
|
+
|
|
501
|
+
returns:
|
|
502
|
+
bool: True on success, False on failure.
|
|
503
|
+
"""
|
|
504
|
+
return self.get_attribute(BASS_ATTRIB_FREQ)
|
|
505
|
+
|
|
506
|
+
def set_frequency(self, frequency):
|
|
507
|
+
"""Sets the frequency (sample rate) of this channel.
|
|
508
|
+
|
|
509
|
+
Args:
|
|
510
|
+
frequency (float): The sample rate... 0 = original rate (when the channel was created).
|
|
511
|
+
|
|
512
|
+
Returns:
|
|
513
|
+
bool: True on success, False on failure.
|
|
514
|
+
"""
|
|
515
|
+
self.set_attribute(BASS_ATTRIB_FREQ, frequency)
|
|
516
|
+
|
|
517
|
+
frequency = property(fget=get_frequency, fset=set_frequency)
|
|
518
|
+
|
|
519
|
+
def get_pan(self):
|
|
520
|
+
"""Gets the panning/balance position of this channel."""
|
|
521
|
+
return self.get_attribute(BASS_ATTRIB_PAN)
|
|
522
|
+
|
|
523
|
+
def set_pan(self, pan):
|
|
524
|
+
"""Sets the panning/balance position of this channel.
|
|
525
|
+
|
|
526
|
+
Args:
|
|
527
|
+
pan (float): The pan position... -1 (full left) to +1 (full right), 0 = centre.
|
|
528
|
+
|
|
529
|
+
Returns:
|
|
530
|
+
bool: True on success, False on Failure.
|
|
531
|
+
|
|
532
|
+
"""
|
|
533
|
+
return self.set_attribute(BASS_ATTRIB_PAN, pan)
|
|
534
|
+
|
|
535
|
+
pan = property(fget=get_pan, fset=set_pan)
|
|
536
|
+
|
|
537
|
+
def get_volume(self):
|
|
538
|
+
"""Gets the volume level of a channel.
|
|
539
|
+
|
|
540
|
+
returns:
|
|
541
|
+
float: The volume level... 0 = silent, 1.0 = normal, above 1.0 = amplification.
|
|
542
|
+
"""
|
|
543
|
+
return self.get_attribute(BASS_ATTRIB_VOL)
|
|
544
|
+
|
|
545
|
+
def set_volume(self, volume):
|
|
546
|
+
"""sets the volume level of a channel.
|
|
547
|
+
|
|
548
|
+
Args:
|
|
549
|
+
volume (float): The volume level... 0 = silent, 1.0 = normal, above 1.0 = amplification.
|
|
550
|
+
|
|
551
|
+
Returns:
|
|
552
|
+
True on success, False on failure.
|
|
553
|
+
"""
|
|
554
|
+
self.set_attribute(BASS_ATTRIB_VOL, volume)
|
|
555
|
+
|
|
556
|
+
volume = property(fget=get_volume, fset=set_volume)
|
|
557
|
+
|
|
558
|
+
def get_data(self, length=16384):
|
|
559
|
+
"""Retrieves the immediate sample data (or an FFT representation of it) of this channel. Must be a sample channel, stream, MOD music, or recording channel.
|
|
560
|
+
|
|
561
|
+
Args:
|
|
562
|
+
length: Number of bytes wanted (up to 268435455 or 0xFFFFFFF). Defaults to 16384.
|
|
563
|
+
|
|
564
|
+
Returns:
|
|
565
|
+
The requested bytes.
|
|
566
|
+
|
|
567
|
+
raises:
|
|
568
|
+
sound_lib.main.BassError: If this channel has reached the end, or the BASS_DATA_AVAILABLE flag was used and this is a decoding channel.
|
|
569
|
+
"""
|
|
570
|
+
buf = c_buffer(length)
|
|
571
|
+
bass_call_0(BASS_ChannelGetData, self.handle, pointer(buf), length)
|
|
572
|
+
return buf
|
|
573
|
+
|
|
574
|
+
# This is less and less of a one-to-one mapping,
|
|
575
|
+
# But I feel that it's better to be consistent with ourselves
|
|
576
|
+
# Than with the library. We won't punish ourselves
|
|
577
|
+
# For their bad decisions
|
|
578
|
+
|
|
579
|
+
def get_looping(self):
|
|
580
|
+
"""Returns whether this channel is currently setup to loop."""
|
|
581
|
+
return bass_call_0(BASS_ChannelFlags, self.handle, BASS_SAMPLE_LOOP, 0) == 20
|
|
582
|
+
|
|
583
|
+
def set_looping(self, looping):
|
|
584
|
+
"""Determines whether this channel is setup to loop.
|
|
585
|
+
|
|
586
|
+
Args:
|
|
587
|
+
looping: (bool): Specifies whether this channel should loop.
|
|
588
|
+
"""
|
|
589
|
+
if looping:
|
|
590
|
+
return bass_call_0(
|
|
591
|
+
BASS_ChannelFlags, self.handle, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP
|
|
592
|
+
)
|
|
593
|
+
return bass_call_0(BASS_ChannelFlags, self.handle, 0, BASS_SAMPLE_LOOP)
|
|
594
|
+
|
|
595
|
+
looping = property(fget=get_looping, fset=set_looping)
|
|
596
|
+
|
|
597
|
+
def __del__(self):
|
|
598
|
+
try:
|
|
599
|
+
self.free()
|
|
600
|
+
except:
|
|
601
|
+
pass
|
|
602
|
+
|
|
603
|
+
def get_x(self):
|
|
604
|
+
"""Retrieves this channel's position on the X-axis, if 3d functionality is available.
|
|
605
|
+
|
|
606
|
+
raises:
|
|
607
|
+
sound_lib.main.BassError: If this channel was not initialized with support for 3d functionality.
|
|
608
|
+
"""
|
|
609
|
+
return self.get_3d_position()["position"].x
|
|
610
|
+
|
|
611
|
+
def set_x(self, val):
|
|
612
|
+
"""Sets positioning of this channel on the X-axis, if 3d functionality is available.
|
|
613
|
+
|
|
614
|
+
Args:
|
|
615
|
+
val: The coordinate position.
|
|
616
|
+
|
|
617
|
+
raises:
|
|
618
|
+
sound_lib.main.BassError: If this channel was not initialized with support for 3d functionality.
|
|
619
|
+
"""
|
|
620
|
+
pos = self.get_3d_position()
|
|
621
|
+
pos["position"].x = val
|
|
622
|
+
self.set_3d_position(**pos)
|
|
623
|
+
|
|
624
|
+
x = property(fget=get_x, fset=set_x)
|
|
625
|
+
|
|
626
|
+
def get_y(self):
|
|
627
|
+
"""Retrieves this channel's position on the Y-axis, if 3d functionality is available.
|
|
628
|
+
|
|
629
|
+
raises:
|
|
630
|
+
sound_lib.main.BassError: If this channel was not initialized with support for 3d functionality.
|
|
631
|
+
"""
|
|
632
|
+
return self.get_3d_position()["position"].y
|
|
633
|
+
|
|
634
|
+
def set_y(self, val):
|
|
635
|
+
"""Sets positioning of this channel on the Y-axis, if 3d functionality is available.
|
|
636
|
+
|
|
637
|
+
Args:
|
|
638
|
+
val: The coordinate position.
|
|
639
|
+
|
|
640
|
+
raises:
|
|
641
|
+
sound_lib.main.BassError: If this channel was not initialized with support for 3d functionality.
|
|
642
|
+
"""
|
|
643
|
+
pos = self.get_3d_position()
|
|
644
|
+
pos["position"].y = val
|
|
645
|
+
self.set_3d_position(**pos)
|
|
646
|
+
|
|
647
|
+
y = property(fget=get_y, fset=set_y)
|
|
648
|
+
|
|
649
|
+
def get_z(self):
|
|
650
|
+
"""Retrieves this channel's position on the Z-axis, if 3d functionality is available.
|
|
651
|
+
|
|
652
|
+
raises:
|
|
653
|
+
sound_lib.main.BassError: If this channel was not initialized with support for 3d functionality.
|
|
654
|
+
"""
|
|
655
|
+
return self.get_3d_position()["position"].z
|
|
656
|
+
|
|
657
|
+
def set_z(self, val):
|
|
658
|
+
"""Sets positioning of this channel on the Z-axis, if 3d functionality is available.
|
|
659
|
+
|
|
660
|
+
Args:
|
|
661
|
+
val: The coordinate position.
|
|
662
|
+
|
|
663
|
+
raises:
|
|
664
|
+
sound_lib.main.BassError: If this channel was not initialized with support for 3d functionality.
|
|
665
|
+
"""
|
|
666
|
+
pos = self.get_3d_position()
|
|
667
|
+
pos["position"].z = val
|
|
668
|
+
self.set_3d_position(**pos)
|
|
669
|
+
|
|
670
|
+
z = property(fget=get_z, fset=set_z)
|
|
671
|
+
|
|
672
|
+
def get_attributes(self):
|
|
673
|
+
"""Retrieves all values of all attributes from this object and displays them in a dictionary whose keys are determined by this object's attribute_mapping"""
|
|
674
|
+
res = {}
|
|
675
|
+
for k in self.attribute_mapping:
|
|
676
|
+
try:
|
|
677
|
+
res[k] = self.get_attribute(k)
|
|
678
|
+
except BassError:
|
|
679
|
+
pass
|
|
680
|
+
return res
|