1 /* 2 * PCM - Common plugin code 3 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org> 4 * 5 * 6 * This library is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as 8 * published by the Free Software Foundation; either version 2.1 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * 20 */ 21 22 #include "pcm_generic.h" 23 24 typedef snd_pcm_uframes_t (*snd_pcm_slave_xfer_areas_func_t) 25 (snd_pcm_t *pcm, 26 const snd_pcm_channel_area_t *areas, 27 snd_pcm_uframes_t offset, 28 snd_pcm_uframes_t size, 29 const snd_pcm_channel_area_t *slave_areas, 30 snd_pcm_uframes_t slave_offset, 31 snd_pcm_uframes_t *slave_sizep); 32 33 typedef snd_pcm_sframes_t (*snd_pcm_slave_xfer_areas_undo_func_t) 34 (snd_pcm_t *pcm, 35 const snd_pcm_channel_area_t *res_areas, /* result areas */ 36 snd_pcm_uframes_t res_offset, /* offset of result areas */ 37 snd_pcm_uframes_t res_size, /* size of result areas */ 38 snd_pcm_uframes_t slave_undo_size); 39 40 typedef struct { 41 snd_pcm_generic_t gen; 42 snd_pcm_slave_xfer_areas_func_t read; 43 snd_pcm_slave_xfer_areas_func_t write; 44 snd_pcm_slave_xfer_areas_undo_func_t undo_read; 45 snd_pcm_slave_xfer_areas_undo_func_t undo_write; 46 int (*init)(snd_pcm_t *pcm); 47 snd_pcm_uframes_t appl_ptr, hw_ptr; 48 } snd_pcm_plugin_t; 49 50 /* make local functions really local */ 51 #define snd_pcm_plugin_init \ 52 snd1_pcm_plugin_init 53 #define snd_pcm_plugin_may_wait_for_avail_min \ 54 snd1_pcm_plugin_may_wait_for_avail_min 55 #define snd_pcm_plugin_fast_ops \ 56 snd1_pcm_plugin_fast_ops 57 #define snd_pcm_plugin_undo_read_generic \ 58 snd1_pcm_plugin_undo_read_generic 59 #define snd_pcm_plugin_undo_write_generic \ 60 snd1_pcm_plugin_undo_write_generic 61 #define snd_pcm_plugin_rewind \ 62 snd1_pcm_plugin_rewind 63 #define snd_pcm_plugin_forward \ 64 snd1_pcm_plugin_forward 65 66 void snd_pcm_plugin_init(snd_pcm_plugin_t *plugin); 67 snd_pcm_sframes_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames); 68 snd_pcm_sframes_t snd_pcm_plugin_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames); 69 int snd_pcm_plugin_may_wait_for_avail_min(snd_pcm_t *pcm, snd_pcm_uframes_t avail); 70 71 extern const snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops; 72 73 snd_pcm_sframes_t snd_pcm_plugin_undo_read_generic 74 (snd_pcm_t *pcm, 75 const snd_pcm_channel_area_t *res_areas, /* result areas */ 76 snd_pcm_uframes_t res_offset, /* offset of result areas */ 77 snd_pcm_uframes_t res_size, /* size of result areas */ 78 snd_pcm_uframes_t slave_undo_size); 79 80 snd_pcm_sframes_t snd_pcm_plugin_undo_write_generic 81 (snd_pcm_t *pcm, 82 const snd_pcm_channel_area_t *res_areas, /* result areas */ 83 snd_pcm_uframes_t res_offset, /* offset of result areas */ 84 snd_pcm_uframes_t res_size, /* size of result areas */ 85 snd_pcm_uframes_t slave_undo_size); 86 87 /* make local functions really local */ 88 #define snd_pcm_linear_get_index snd1_pcm_linear_get_index 89 #define snd_pcm_linear_put_index snd1_pcm_linear_put_index 90 #define snd_pcm_linear_convert_index snd1_pcm_linear_convert_index 91 #define snd_pcm_linear_convert snd1_pcm_linear_convert 92 #define snd_pcm_linear_getput snd1_pcm_linear_getput 93 #define snd_pcm_alaw_decode snd1_pcm_alaw_decode 94 #define snd_pcm_alaw_encode snd1_pcm_alaw_encode 95 #define snd_pcm_mulaw_decode snd1_pcm_mulaw_decode 96 #define snd_pcm_mulaw_encode snd1_pcm_mulaw_encode 97 #define snd_pcm_adpcm_decode snd1_pcm_adpcm_decode 98 #define snd_pcm_adpcm_encode snd1_pcm_adpcm_encode 99 100 int snd_pcm_linear_get_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format); 101 int snd_pcm_linear_put_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format); 102 int snd_pcm_linear_convert_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format); 103 104 void snd_pcm_linear_convert(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset, 105 const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset, 106 unsigned int channels, snd_pcm_uframes_t frames, 107 unsigned int convidx); 108 void snd_pcm_linear_getput(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset, 109 const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset, 110 unsigned int channels, snd_pcm_uframes_t frames, 111 unsigned int get_idx, unsigned int put_idx); 112 void snd_pcm_alaw_decode(const snd_pcm_channel_area_t *dst_areas, 113 snd_pcm_uframes_t dst_offset, 114 const snd_pcm_channel_area_t *src_areas, 115 snd_pcm_uframes_t src_offset, 116 unsigned int channels, snd_pcm_uframes_t frames, 117 unsigned int putidx); 118 void snd_pcm_alaw_encode(const snd_pcm_channel_area_t *dst_areas, 119 snd_pcm_uframes_t dst_offset, 120 const snd_pcm_channel_area_t *src_areas, 121 snd_pcm_uframes_t src_offset, 122 unsigned int channels, snd_pcm_uframes_t frames, 123 unsigned int getidx); 124 void snd_pcm_mulaw_decode(const snd_pcm_channel_area_t *dst_areas, 125 snd_pcm_uframes_t dst_offset, 126 const snd_pcm_channel_area_t *src_areas, 127 snd_pcm_uframes_t src_offset, 128 unsigned int channels, snd_pcm_uframes_t frames, 129 unsigned int putidx); 130 void snd_pcm_mulaw_encode(const snd_pcm_channel_area_t *dst_areas, 131 snd_pcm_uframes_t dst_offset, 132 const snd_pcm_channel_area_t *src_areas, 133 snd_pcm_uframes_t src_offset, 134 unsigned int channels, snd_pcm_uframes_t frames, 135 unsigned int getidx); 136 137 typedef struct _snd_pcm_adpcm_state { 138 int pred_val; /* Calculated predicted value */ 139 int step_idx; /* Previous StepSize lookup index */ 140 } snd_pcm_adpcm_state_t; 141 142 void snd_pcm_adpcm_decode(const snd_pcm_channel_area_t *dst_areas, 143 snd_pcm_uframes_t dst_offset, 144 const snd_pcm_channel_area_t *src_areas, 145 snd_pcm_uframes_t src_offset, 146 unsigned int channels, snd_pcm_uframes_t frames, 147 unsigned int putidx, 148 snd_pcm_adpcm_state_t *states); 149 void snd_pcm_adpcm_encode(const snd_pcm_channel_area_t *dst_areas, 150 snd_pcm_uframes_t dst_offset, 151 const snd_pcm_channel_area_t *src_areas, 152 snd_pcm_uframes_t src_offset, 153 unsigned int channels, snd_pcm_uframes_t frames, 154 unsigned int getidx, 155 snd_pcm_adpcm_state_t *states); 156