Repository navigation
audiotap module - #11639
audiotap module#11639FoamyGuy wants to merge 2 commits into
Conversation
tannewt
left a comment
There was a problem hiding this comment.
Neat idea! A couple comments on the API.
| def pull(sample, times=1): | ||
| out = [] | ||
| for _ in range(times): | ||
| result, buffer = get_buffer(sample) |
There was a problem hiding this comment.
This seems weird to me. I didn't realize audiocore had a get_buffer. I expected you to get something straight from the tap.
There was a problem hiding this comment.
You do get data from the Tap using readinto(), this example uses that as well.
The get_buffer thing here is essentially a standin for a true output. Without an output like I2SOut or similar nothing will pull data through the FX chain. This technique is also used in other existing audio effects tests like here: https://github.com/adafruit/circuitpython/blame/d53b2277cfad71589028e5da77c984c045db990d/tests/circuitpython/audiofilter_filter_reset_buffer.py#L36-L43
| //| :param int buffer_size: The total size in bytes of each of the two playback buffers to use | ||
| //| :param int sample_rate: The sample rate to be used | ||
| //| :param int bits_per_sample: The bits per sample of the audio: 8 or 16 | ||
| //| :param bool samples_signed: Effect is signed (True) or unsigned (False) | ||
| //| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo. |
There was a problem hiding this comment.
Do you need this? Could you inherit these from whatever you play? You could even allocate the ringbuf for the capacity at play time.
There was a problem hiding this comment.
Changed to take format from the source and allocate buffer at play time in the latest commit
| //| samples_signed=mic_format.samples_signed, | ||
| //| max_packet_size=mic_format.max_packet_size, | ||
| //| ) | ||
| //| # Keep a quarter second, more than arrives between reads of the loop below. |
There was a problem hiding this comment.
Maybe you actually want capacity in terms of time too.
There was a problem hiding this comment.
Changed capacity to time based in the latest commit. I think time is easier to use than sample count anyhow, if we want both I can add back one for count.
| MP_DEFINE_CONST_FUN_OBJ_1(audiotap_tap_clear_obj, audiotap_tap_obj_clear); | ||
|
|
||
| //| def levels(self) -> Tuple[float, float]: | ||
| //| """Returns the peak and RMS level of the audio that passed through |
There was a problem hiding this comment.
Do you need both values for the same snapshot of time? If not, you could avoid this tuple allocation.
There was a problem hiding this comment.
I split these into different properties in the latest commit.
…pacity to time based
This new module provides an FX chain object that passes unmodified audio through while keeping a small buffer that can be accessed from the python side.
It allows python code to check the level of the streaming audio for drawing level indicators and similar. Or to read data from the audio stream for analysis while it's still being played.