Skip to content

audiotap module - #11639

Open
FoamyGuy wants to merge 2 commits into
adafruit:mainfrom
FoamyGuy:audiotap_module
Open

FoamyGuy wants to merge 2 commits into
adafruit:mainfrom
FoamyGuy:audiotap_module

Conversation

@FoamyGuy

Copy link
Copy Markdown
Collaborator

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.

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat idea! A couple comments on the API.

def pull(sample, times=1):
out = []
for _ in range(times):
result, buffer = get_buffer(sample)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems weird to me. I didn't realize audiocore had a get_buffer. I expected you to get something straight from the tap.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread shared-bindings/audiotap/Tap.c Outdated
Comment on lines +54 to +58
//| :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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this? Could you inherit these from whatever you play? You could even allocate the ringbuf for the capacity at play time.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you actually want capacity in terms of time too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread shared-bindings/audiotap/Tap.c Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need both values for the same snapshot of time? If not, you could avoid this tuple allocation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split these into different properties in the latest commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants