[CentralOH] Async buffer generation update
Eric Floehr
eric at intellovations.com
Wed Jun 22 16:53:14 EDT 2016
Thank you Neil and Andrew for getting me pointed in the right direction.
Here is where I am now.
I've taken Neil's suggestion of a Queue, and am using the multiprocessing
module's Queue which is thread-safe, and am using that as the audio buffer.
I then use multiprocessing's Process class to throw the generation process
into a separate process, like so:
import multiprocessing
audio_bytes = multiprocessing.Queue(maxsize=int(RATE/4.0))
def generate_samples():
while True:
audio_bytes.put((round(random.random() * VOLRANGE) + MINVOL))
def get_samples(in_data, frame_count, time_info, status_flags):
out_data = b""
for _ in range(frame_count):
out_data += pack('h', audio_bytes.get())
return out_data, pyaudio.paContinue
def main():
sound_process = multiprocessing.Process(target=generate_samples)
sound_process.start()
Currently, I'm using a buffer size of a quarter of a second. I'm still not
using a generator to create the samples, but I'm working towards that. I
wanted to get the basics down first.
I also thought that I could use asyncio's ensure_future() to accomplish
effectively the same thing effectively, except asyncio is just concurrent,
whereas multiprocessing is parallel (I believe?).
-Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20160622/9a4aaead/attachment.html>
More information about the CentralOH
mailing list