1 /* 2 * Copyright (c) 2019-2025 Allwinner Technology Co., Ltd. ALL rights reserved. 3 * 4 * Allwinner is a trademark of Allwinner Technology Co.,Ltd., registered in 5 * the the people's Republic of China and other countries. 6 * All Allwinner Technology Co.,Ltd. trademarks are used with permission. 7 * 8 * DISCLAIMER 9 * THIRD PARTY LICENCES MAY BE REQUIRED TO IMPLEMENT THE SOLUTION/PRODUCT. 10 * IF YOU NEED TO INTEGRATE THIRD PARTY’S TECHNOLOGY (SONY, DTS, DOLBY, AVS OR MPEGLA, ETC.) 11 * IN ALLWINNERS’SDK OR PRODUCTS, YOU SHALL BE SOLELY RESPONSIBLE TO OBTAIN 12 * ALL APPROPRIATELY REQUIRED THIRD PARTY LICENCES. 13 * ALLWINNER SHALL HAVE NO WARRANTY, INDEMNITY OR OTHER OBLIGATIONS WITH RESPECT TO MATTERS 14 * COVERED UNDER ANY REQUIRED THIRD PARTY LICENSE. 15 * YOU ARE SOLELY RESPONSIBLE FOR YOUR USAGE OF THIRD PARTY’S TECHNOLOGY. 16 * 17 * 18 * THIS SOFTWARE IS PROVIDED BY ALLWINNER"AS IS" AND TO THE MAXIMUM EXTENT 19 * PERMITTED BY LAW, ALLWINNER EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND, 20 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION REGARDING 21 * THE TITLE, NON-INFRINGEMENT, ACCURACY, CONDITION, COMPLETENESS, PERFORMANCE 22 * OR MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 23 * IN NO EVENT SHALL ALLWINNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS, OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 30 * OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef __AW_ALSA_LIB_PCM_RATE_H 34 #define __AW_ALSA_LIB_PCM_RATE_H 35 36 #include <aw-alsa-lib/pcm.h> 37 #include <sys/types.h> 38 #define SND_PCM_RATE_PLUGIN_VERSION 0x010002 39 40 #define SND_PCM_RATE_PLUGIN_ENTRY(name) _snd_pcm_rate_##name##_open 41 #define SND_PCM_RATE_PLUGIN_CONF_ENTRY(name) _snd_pcm_rate_##name##_open_conf 42 43 #define SND_PCM_PLUGIN_RATE_MIN 4000 44 #define SND_PCM_PLUGIN_RATE_MAX 192000 45 46 typedef struct _snd_pcm_rate snd_pcm_rate_t; 47 48 /** hw_params information for a single side */ 49 typedef struct snd_pcm_rate_side_info { 50 snd_pcm_format_t format; 51 unsigned int rate; 52 snd_pcm_uframes_t buffer_size; 53 snd_pcm_uframes_t period_size; 54 } snd_pcm_rate_side_info_t; 55 56 /** hw_params information */ 57 typedef struct snd_pcm_rate_info { 58 struct snd_pcm_rate_side_info in; 59 struct snd_pcm_rate_side_info out; 60 unsigned int channels; 61 } snd_pcm_rate_info_t; 62 63 /** Callback table of rate-converter */ 64 typedef struct snd_pcm_rate_ops { 65 /** 66 * close the converter; optional 67 */ 68 void (*close)(void *obj); 69 /** 70 * initialize the converter, called at hw_params 71 */ 72 int (*init)(void *obj, snd_pcm_rate_info_t *info); 73 /** 74 * free the converter; optional 75 */ 76 void (*free)(void *obj); 77 /** 78 * reset the converter, called at prepare; optional 79 */ 80 void (*reset)(void *obj); 81 /** 82 * adjust the pitch, called at sw_params; optional 83 */ 84 int (*adjust_pitch)(void *obj, snd_pcm_rate_info_t *info); 85 /** 86 * convert the data 87 */ 88 void (*convert)(void *obj, 89 const snd_pcm_channel_area_t *dst_areas, 90 snd_pcm_uframes_t dst_offset, unsigned int dst_frames, 91 const snd_pcm_channel_area_t *src_areas, 92 snd_pcm_uframes_t src_offset, unsigned int src_frames); 93 /** 94 * convert an s16 interleaved-data array; exclusive with convert 95 */ 96 void (*convert_s16)(void *obj, int16_t *dst, unsigned int dst_frames, 97 const int16_t *src, unsigned int src_frames); 98 99 void (*convert_s16_fix)(void *obj, int16_t *dst, unsigned int *dst_frames, 100 const int16_t *src, unsigned int *src_frames); 101 /** 102 * compute the frame size for input 103 */ 104 snd_pcm_uframes_t (*input_frames)(void *obj, snd_pcm_uframes_t frames); 105 /** 106 * compute the frame size for output 107 */ 108 snd_pcm_uframes_t (*output_frames)(void *obj, snd_pcm_uframes_t frames); 109 /** 110 * the protocol version the plugin supports; 111 * new field since version 0x010002 112 */ 113 unsigned int version; 114 /** 115 * return the supported min / max sample rates; 116 * new ops since version 0x010002 117 */ 118 int (*get_supported_rates)(void *obj, unsigned int *rate_min, 119 unsigned int *rate_max); 120 /** 121 * show some status messages for verbose mode; 122 * new ops since version 0x010002 123 */ 124 void (*dump)(void *obj); 125 } snd_pcm_rate_ops_t; 126 127 /** open function type */ 128 typedef int (*snd_pcm_rate_open_func_t)(unsigned int version, void **objp, 129 snd_pcm_rate_ops_t *opsp); 130 131 typedef struct { 132 const char *pcm; 133 snd_pcm_format_t format; 134 unsigned int rate; 135 } snd_pcm_rate_slave_config_t; 136 137 typedef struct { 138 const char *type; 139 snd_pcm_rate_slave_config_t slave; 140 const char *converter; 141 } snd_pcm_rate_config_t; 142 143 #endif /* __AW_ALSA_LIB_PCM_RATE_H */ 144