]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - mixer.py
9e8179a9a3989c692b3e97d7da1783a57c748e94
1 import sounddevice
as sd
11 self
.stream
= sd
.RawOutputStream(samplerate
=frame_rate
,
13 dtype
='int' + str(8*sample_width
), # FIXME: ?
16 callback
=self
.play_callback
,
20 def add_file(self
, music_file
):
21 if music_file
not in self
.open_files
:
22 self
.open_files
.append(music_file
)
25 def remove_file(self
, music_file
):
26 self
.open_files
.remove(music_file
)
27 if len(self
.open_files
) == 0:
36 def play_callback(self
, out_data
, frame_count
, time_info
, status_flags
):
37 out_data_length
= len(out_data
)
38 empty_data
= b
"\0" * out_data_length
39 data
= b
"\0" * out_data_length
41 for open_file
in self
.open_files
:
42 file_data
= open_file
.play_callback(out_data_length
, frame_count
)
44 if data
== empty_data
:
46 elif file_data
!= empty_data
:
47 data
= audioop
.add(data
, file_data
, sample_width
)