11#ifndef _SAMPLE_RATE_CONVERTER_H_
12#define _SAMPLE_RATE_CONVERTER_H_
22#include <zephyr/sys/ring_buffer.h>
23#include <dsp/filtering_functions.h>
36#define SAMPLE_RATE_CONVERTER_STATE_BUFFER_SIZE \
37 (CONFIG_SAMPLE_RATE_CONVERTER_BLOCK_SIZE_MAX + \
38 CONFIG_SAMPLE_RATE_CONVERTER_MAX_FILTER_SIZE - 1)
50#define SAMPLE_RATE_CONVERTER_INPUT_BUFFER_NUMBER_OVERFLOW_SAMPLES 2
57#define SAMPLE_RATE_CONVERTER_OUTPUT_BUFFER_NUMBER_OVERFLOW_SAMPLES 6
59#ifdef CONFIG_SAMPLE_RATE_CONVERTER_BIT_DEPTH_16
60#define SAMPLE_RATE_CONVERTER_INPUT_BUF_SIZE \
61 (SAMPLE_RATE_CONVERTER_INPUT_BUFFER_NUMBER_OVERFLOW_SAMPLES * sizeof(uint16_t))
62#define SAMPLE_RATE_CONVERTER_RINGBUF_SIZE \
63 ((CONFIG_SAMPLE_RATE_CONVERTER_BLOCK_SIZE_MAX + \
64 SAMPLE_RATE_CONVERTER_OUTPUT_BUFFER_NUMBER_OVERFLOW_SAMPLES) * \
66#elif CONFIG_SAMPLE_RATE_CONVERTER_BIT_DEPTH_32
67#define SAMPLE_RATE_CONVERTER_INPUT_BUF_SIZE \
68 (SAMPLE_RATE_CONVERTER_INPUT_BUFFER_NUMBER_OVERFLOW_SAMPLES * sizeof(uint32_t))
69#define SAMPLE_RATE_CONVERTER_RINGBUF_SIZE \
70 ((CONFIG_SAMPLE_RATE_CONVERTER_BLOCK_SIZE_MAX + \
71 SAMPLE_RATE_CONVERTER_OUTPUT_BUFFER_NUMBER_OVERFLOW_SAMPLES) * \
74#define SAMPLE_RATE_CONVERTER_INPUT_BUF_SIZE 0
75#define SAMPLE_RATE_CONVERTER_RINGBUF_SIZE 0
107#ifdef CONFIG_SAMPLE_RATE_CONVERTER_BIT_DEPTH_16
108 arm_fir_interpolate_instance_q15 fir_interpolate_q15;
109 arm_fir_decimate_instance_q15 fir_decimate_q15;
110#elif CONFIG_SAMPLE_RATE_CONVERTER_BIT_DEPTH_32
111 arm_fir_interpolate_instance_q31 fir_interpolate_q31;
112 arm_fir_decimate_instance_q31 fir_decimate_q31;
119#ifdef CONFIG_SAMPLE_RATE_CONVERTER_BIT_DEPTH_16
121#elif CONFIG_SAMPLE_RATE_CONVERTER_BIT_DEPTH_32
169 size_t input_size, uint32_t input_sample_rate,
void *
const output,
170 size_t output_size,
size_t *output_written,
171 uint32_t output_sample_rate);
int sample_rate_converter_open(struct sample_rate_converter_ctx *ctx)
Open the sample rate converter for a new context.
#define SAMPLE_RATE_CONVERTER_STATE_BUFFER_SIZE
Definition: sample_rate_converter.h:36
sample_rate_converter_filter
Definition: sample_rate_converter.h:41
@ SAMPLE_RATE_FILTER_SIMPLE
Definition: sample_rate_converter.h:43
@ SAMPLE_RATE_FILTER_TEST
Definition: sample_rate_converter.h:42
#define SAMPLE_RATE_CONVERTER_RINGBUF_SIZE
Definition: sample_rate_converter.h:75
#define SAMPLE_RATE_CONVERTER_INPUT_BUF_SIZE
Definition: sample_rate_converter.h:74
int sample_rate_converter_process(struct sample_rate_converter_ctx *ctx, enum sample_rate_converter_filter filter, void const *const input, size_t input_size, uint32_t input_sample_rate, void *const output, size_t output_size, size_t *output_written, uint32_t output_sample_rate)
Process input samples and produce output samples with new sample rate.
uint8_t buf[0]
Definition: sample_rate_converter.h:80
size_t bytes_in_buf
Definition: sample_rate_converter.h:81
Definition: sample_rate_converter.h:79
uint32_t sample_rate_output
Definition: sample_rate_converter.h:88
struct ring_buf output_ringbuf
Definition: sample_rate_converter.h:102
uint32_t sample_rate_input
Definition: sample_rate_converter.h:87
int conversion_ratio
Definition: sample_rate_converter.h:93
enum sample_rate_converter_filter filter_type
Definition: sample_rate_converter.h:96
struct buf_ctx input_buf
Definition: sample_rate_converter.h:99
uint8_t output_ringbuf_data[0]
Definition: sample_rate_converter.h:103
Definition: sample_rate_converter.h:85