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

Playing 16 bit audio using this sample #6

Open
mahaju opened this issue Sep 14, 2021 · 0 comments
Open

Playing 16 bit audio using this sample #6

mahaju opened this issue Sep 14, 2021 · 0 comments

Comments

@mahaju
Copy link

mahaju commented Sep 14, 2021

Hi could you please let me know how you chose the value 250 for this function in pico-pwm-audio.c
pwm_config_set_wrap(&config, 250);
I can understand how your clock divider and other values ultimately set a sampling frequency of 11000 Hz for the clock frequency you have chosen, but I wanted to understand how you chose those specific values.

The reason I ask this is because I want to take audio input from a "line-out" audio signal attached to the ADC and play it back in PWM in real time. I don't have experience with generating audio using PWM and your code is also serving as a tutorial for me. The ADC audio samples are 12-bits and I am storing them in a uint16 and the ADC values that I am getting are in the range 2030 to 2090. Since they are all bigger than 250, using your code as it is now and just using my ADC data as input for the PWM output does not generate any PWM signal. I have tried changing the 12-bits of ADC to 8 [doing something like this in pwm_interrupt_handler()]
pwm_set_gpio_level(AUDIO_PIN, (WAV_DATA[wav_position>>3]) >>4);
but that also adds a lot of noise to the output sound, so I think I may be going about this the wrong way.

So I am guessing it is better if I do not loose any bits of my audio samples and find out a way of playing them as 16 bit audio. Could you give me some ideas on how to do this, or at least what is the proper way to choose the pwm_config_set_wrap value, and the number of shifts in WAV_DATA[wav_position>>3]?

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

1 participant