diff --git a/include/aprs_pico.h b/include/aprs_pico.h index 6c51c81..1b79d21 100644 --- a/include/aprs_pico.h +++ b/include/aprs_pico.h @@ -65,8 +65,9 @@ bool aprs_pico_sendAPRS(audio_buffer_pool_t* audio_buffer_pool, * * \param[in, out] audio_buffer_pool The pool of audio buffers to be used for rendering the sine audio signal * \param[in] freq_in_hz The frequency of the sine wave to be generated (in Hz) + * \param[in] sample_freq_in_hz The sampling frequency of the sine wave to be generated (in Hz) * \param[in] volume The volume level of the generated signal (0 ... 256) */ -void aprs_pico_send_sine_wave(audio_buffer_pool_t* audio_buffer_pool, unsigned int freq_in_hz, uint16_t volume); +void aprs_pico_send_sine_wave(audio_buffer_pool_t* audio_buffer_pool, unsigned int freq_in_hz, unsigned int sample_freq_in_hz, uint16_t volume); #endif // APRS_PICO_H diff --git a/src/aprs_pico.c b/src/aprs_pico.c index 570680d..490972a 100644 --- a/src/aprs_pico.c +++ b/src/aprs_pico.c @@ -183,20 +183,17 @@ audio_buffer_pool_t* aprs_pico_init() // See the header file for documentation -void aprs_pico_send_sine_wave(audio_buffer_pool_t* audio_buffer_pool, unsigned int freq_in_hz, uint16_t volume) +void aprs_pico_send_sine_wave(audio_buffer_pool_t* audio_buffer_pool, unsigned int freq_in_hz, unsigned int sample_freq_in_hz, uint16_t volume) { assert(audio_buffer_pool != NULL); - // WARNING: ATTOW, the pico audio PWM lib worked only @ 22050 Hz sampling frequency and 48 MHz system clock - // This is documented here: https://github.com/raspberrypi/pico-extras - const unsigned int SAMPLE_FREQ_IN_HZ = APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB_FIXED_SAMPLE_FREQ_IN_HZ; - const unsigned int num_samples_per_period = SAMPLE_FREQ_IN_HZ / freq_in_hz; - typedef int16_t wave_table_value_t; const wave_table_value_t WAVE_TABLE_VALUE_MAX = INT16_MAX; - aprs_pico_initClock(SAMPLE_FREQ_IN_HZ); + aprs_pico_initClock(sample_freq_in_hz); + + const unsigned int num_samples_per_period = sample_freq_in_hz / freq_in_hz; wave_table_value_t* sine_period_wave_table = malloc(num_samples_per_period * sizeof(wave_table_value_t)); diff --git a/src/aprs_pico_example.c b/src/aprs_pico_example.c index d4a48f5..202e4d8 100644 --- a/src/aprs_pico_example.c +++ b/src/aprs_pico_example.c @@ -31,10 +31,11 @@ int main() #if (SINE_WAVE_TEST == 1) - const unsigned int FREQ_IN_HZ = 1000u; - const uint16_t VOLUME = 128u; + const unsigned int FREQ_IN_HZ = 1000u; + const unsigned int SAMPLE_FREQ_IN_HZ = 48000u; + const uint16_t VOLUME = 128u; - aprs_pico_send_sine_wave(audio_buffer_pool, FREQ_IN_HZ, VOLUME); + aprs_pico_send_sine_wave(audio_buffer_pool, FREQ_IN_HZ, SAMPLE_FREQ_IN_HZ, VOLUME); #else // !SINE_WAVE_TEST