Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pico_audio_pwm: take_audio_buffer never returns null #29

Open
Gadgetoid opened this issue Oct 13, 2021 · 1 comment
Open

pico_audio_pwm: take_audio_buffer never returns null #29

Gadgetoid opened this issue Oct 13, 2021 · 1 comment

Comments

@Gadgetoid
Copy link

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.

@kilograham
Copy link
Contributor

yeah that PWM code assumes 48Mhz clock and 22058Hz audio (I think it says that somewhere)... so of limited use (unless you can set your CPU frequency and PIO clock divider accordingly).

we are working on a new audio API (with parity across all audio types - i.e. run whatever freq you want) which will make its way into SDK at some point - somewhat of a replacement for these APIs.

Frankly on PicoSystem you can just use PWM and DMA to that (to get 8 bit audio).

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

No branches or pull requests

2 participants