pico_audio_pwm: `take_audio_buffer` never returns null

Open
#29 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp

Research direction

Start by tracing the take_audio_buffer implementation and the PWM audio path mentioned in the report. Reproduce the continuous main-loop case and compare the function's behavior with the expected empty-buffer semantics; done means the issue's reported behavior is resolved without advancing audio at an unintended rate.

Written by the indexing model from the issue text.

Description

We've been tinkering with audio on PicoSystem and in the case of at least PWM audio, take_audio_buffer never seems to return null, and never seems to stall for any length of time.

In instances where we're naively calling an "audio_update" function at an arbitrary speed (too quickly in our case) this results in the audio engine getting clocked at some multiple it's intended speed, since we're relying upon take_audio_buffer to give us a buffer if and only if there is an consumed buffer in the pool.

For example, our update_audio function might look something like this:

void update_audio(uint32_t time) {
  struct audio_buffer *buffer = take_audio_buffer(audio_pool, false);
  if(buffer) {
    auto samples = (int16_t *) buffer->buffer->bytes;
    for(uint32_t i = 0; i < buffer->max_sample_count; i++) {
      *samples++ = get_audio_frame();
    }
  }
  buffer->sample_count = buffer->max_sample_count;
  give_audio_buffer(audio_pool, buffer);
}

And this would be called continuously in the main loop.

No matter how fast we run this, if(buffer) is always true.

Dominant language
C
Stars
605
Forks
155
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/pico-extras

All issues in raspberrypi/pico-extras

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.