bastibe / PySoundCard

PySoundCard is an audio library based on PortAudio, CFFI and NumPy
BSD 3-Clause "New" or "Revised" License
87 stars 9 forks source link

Request: callback returns None #9

Closed kousu closed 10 years ago

kousu commented 10 years ago

I would like to be able to write def pysoundcard_callback(in_data, frame_count, time_info, status): return

and def pysoundcard_callback(in_data, frame_count, time_info, status): return continue_flag

and def pysoundcard_callback(in_data, frame_count, time_info, status): return (None, continue_flag)

all to mean def pysoundcard_callback(in_data, frame_count, time_info, status): return (zeros_like(in_data), continue_flag)

bastibe commented 10 years ago

We had a long discussion about this back when I was working on PyAudio. The thing is, the callback is meant for cases in which you want very specific timing control for both input and output. In most other cases, the read and write functions are probably the better option.

Because of that, I try to keep the callback function as lean and as explicit and as possible.

You could easily write a function decorator that transforms a "lazy" callback like you are describing into the required form, though.

On 22.12.2013, at 06:36, Nick notifications@github.com wrote:

I would like to be able to write def pysoundcard_callback(in_data, frame_count, time_info, status): return

and def pysoundcard_callback(in_data, frame_count, time_info, status): return continue_flag

and def pysoundcard_callback(in_data, frame_count, time_info, status): return (None, continue_flag)

all to mean def pysoundcard_callback(in_data, frame_count, time_info, status): return (zeros_like(in_data), continue_flag)

— Reply to this email directly or view it on GitHub.

kousu commented 10 years ago

You are correct. Like I said in #8, I assumed that callback was the more efficient design.