You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
4.6KB

  1. /*
  2. ** Copyright (c) 2002-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
  3. ** All rights reserved.
  4. **
  5. ** This code is released under 2-clause BSD license. Please see the
  6. ** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
  7. */
  8. /*
  9. ** API documentation is available here:
  10. ** http://www.mega-nerd.com/SRC/api.html
  11. */
  12. #ifndef SAMPLERATE_H
  13. #define SAMPLERATE_H
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif /* __cplusplus */
  17. /* Opaque data type SRC_STATE. */
  18. typedef struct SRC_STATE_tag SRC_STATE ;
  19. /* SRC_DATA is used to pass data to src_simple() and src_process(). */
  20. typedef struct
  21. { const float *data_in ;
  22. float *data_out ;
  23. long input_frames, output_frames ;
  24. long input_frames_used, output_frames_gen ;
  25. int end_of_input ;
  26. double src_ratio ;
  27. } SRC_DATA ;
  28. /*
  29. ** User supplied callback function type for use with src_callback_new()
  30. ** and src_callback_read(). First parameter is the same pointer that was
  31. ** passed into src_callback_new(). Second parameter is pointer to a
  32. ** pointer. The user supplied callback function must modify *data to
  33. ** point to the start of the user supplied float array. The user supplied
  34. ** function must return the number of frames that **data points to.
  35. */
  36. typedef long (*src_callback_t) (void *cb_data, float **data) ;
  37. /*
  38. ** Standard initialisation function : return an anonymous pointer to the
  39. ** internal state of the converter. Choose a converter from the enums below.
  40. ** Error returned in *error.
  41. */
  42. SRC_STATE* src_new (int converter_type, int channels, int *error) ;
  43. /*
  44. ** Initilisation for callback based API : return an anonymous pointer to the
  45. ** internal state of the converter. Choose a converter from the enums below.
  46. ** The cb_data pointer can point to any data or be set to NULL. Whatever the
  47. ** value, when processing, user supplied function "func" gets called with
  48. ** cb_data as first parameter.
  49. */
  50. SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
  51. int *error, void* cb_data) ;
  52. /*
  53. ** Cleanup all internal allocations.
  54. ** Always returns NULL.
  55. */
  56. SRC_STATE* src_delete (SRC_STATE *state) ;
  57. /*
  58. ** Standard processing function.
  59. ** Returns non zero on error.
  60. */
  61. int src_process (SRC_STATE *state, SRC_DATA *data) ;
  62. /*
  63. ** Callback based processing function. Read up to frames worth of data from
  64. ** the converter int *data and return frames read or -1 on error.
  65. */
  66. long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
  67. /*
  68. ** Simple interface for performing a single conversion from input buffer to
  69. ** output buffer at a fixed conversion ratio.
  70. ** Simple interface does not require initialisation as it can only operate on
  71. ** a single buffer worth of audio.
  72. */
  73. int src_simple (SRC_DATA *data, int converter_type, int channels) ;
  74. /*
  75. ** This library contains a number of different sample rate converters,
  76. ** numbered 0 through N.
  77. **
  78. ** Return a string giving either a name or a more full description of each
  79. ** sample rate converter or NULL if no sample rate converter exists for
  80. ** the given value. The converters are sequentially numbered from 0 to N.
  81. */
  82. const char *src_get_name (int converter_type) ;
  83. const char *src_get_description (int converter_type) ;
  84. const char *src_get_version (void) ;
  85. /*
  86. ** Set a new SRC ratio. This allows step responses
  87. ** in the conversion ratio.
  88. ** Returns non zero on error.
  89. */
  90. int src_set_ratio (SRC_STATE *state, double new_ratio) ;
  91. /*
  92. ** Get the current channel count.
  93. ** Returns negative on error, positive channel count otherwise
  94. */
  95. int src_get_channels (SRC_STATE *state) ;
  96. /*
  97. ** Reset the internal SRC state.
  98. ** Does not modify the quality settings.
  99. ** Does not free any memory allocations.
  100. ** Returns non zero on error.
  101. */
  102. int src_reset (SRC_STATE *state) ;
  103. /*
  104. ** Return TRUE if ratio is a valid conversion ratio, FALSE
  105. ** otherwise.
  106. */
  107. int src_is_valid_ratio (double ratio) ;
  108. /*
  109. ** Return an error number.
  110. */
  111. int src_error (SRC_STATE *state) ;
  112. /*
  113. ** Convert the error number into a string.
  114. */
  115. const char* src_strerror (int error) ;
  116. /*
  117. ** The following enums can be used to set the interpolator type
  118. ** using the function src_set_converter().
  119. */
  120. enum
  121. {
  122. SRC_SINC_BEST_QUALITY = 0,
  123. SRC_SINC_MEDIUM_QUALITY = 1,
  124. SRC_SINC_FASTEST = 2,
  125. SRC_ZERO_ORDER_HOLD = 3,
  126. SRC_LINEAR = 4,
  127. } ;
  128. /*
  129. ** Extra helper functions for converting from short to float and
  130. ** back again.
  131. */
  132. void src_short_to_float_array (const short *in, float *out, int len) ;
  133. void src_float_to_short_array (const float *in, short *out, int len) ;
  134. void src_int_to_float_array (const int *in, float *out, int len) ;
  135. void src_float_to_int_array (const float *in, int *out, int len) ;
  136. #ifdef __cplusplus
  137. } /* extern "C" */
  138. #endif /* __cplusplus */
  139. #endif /* SAMPLERATE_H */