audio_resample.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. /**
  6. * Initialize the audio resampler.
  7. *
  8. * @param input_rate Source sample rate (e.g. 44100)
  9. * @param output_rate Target sample rate (e.g. 48000)
  10. * @param channels Number of channels (2 for stereo)
  11. * @return true on success
  12. */
  13. bool audio_resample_init(uint32_t input_rate, uint32_t output_rate,
  14. int channels);
  15. /**
  16. * Resample a block of interleaved int16_t PCM.
  17. *
  18. * @param in Input samples (interleaved stereo int16)
  19. * @param in_frames Number of input frames (samples per channel)
  20. * @param out Output buffer (int16, must hold max_output_frames)
  21. * @param out_capacity Maximum output frames the buffer can hold
  22. * @return Number of output frames written
  23. */
  24. size_t audio_resample_process(const int16_t *in, size_t in_frames, int16_t *out,
  25. size_t out_capacity);
  26. /**
  27. * @return true if resampling is active (rates differ)
  28. */
  29. bool audio_resample_is_active(void);
  30. /**
  31. * Reset resampler state (call on stream flush).
  32. */
  33. void audio_resample_reset(void);
  34. /**
  35. * Destroy the resampler and free resources.
  36. */
  37. void audio_resample_destroy(void);
  38. /**
  39. * Get the maximum number of output frames for a given input frame count.
  40. */
  41. size_t audio_resample_max_output(size_t in_frames);