Home | History | Annotate | Download | only in pcm
      1 /*
      2  *  PCM - Common plugin code
      3  *  Copyright (c) 2000 by Abramo Bagnara <abramo (at) 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     19  *
     20  */
     21 
     22 #include "iatomic.h"
     23 #include "pcm_generic.h"
     24 
     25 typedef snd_pcm_uframes_t (*snd_pcm_slave_xfer_areas_func_t)
     26      (snd_pcm_t *pcm,
     27       const snd_pcm_channel_area_t *areas,
     28       snd_pcm_uframes_t offset,
     29       snd_pcm_uframes_t size,
     30       const snd_pcm_channel_area_t *slave_areas,
     31       snd_pcm_uframes_t slave_offset,
     32       snd_pcm_uframes_t *slave_sizep);
     33 
     34 typedef snd_pcm_sframes_t (*snd_pcm_slave_xfer_areas_undo_func_t)
     35      (snd_pcm_t *pcm,
     36       const snd_pcm_channel_area_t *res_areas,	/* result areas */
     37       snd_pcm_uframes_t res_offset,		/* offset of result areas */
     38       snd_pcm_uframes_t res_size,		/* size of result areas */
     39       snd_pcm_uframes_t slave_undo_size);
     40 
     41 typedef struct {
     42 	snd_pcm_generic_t gen;
     43 	snd_pcm_slave_xfer_areas_func_t read;
     44 	snd_pcm_slave_xfer_areas_func_t write;
     45 	snd_pcm_slave_xfer_areas_undo_func_t undo_read;
     46 	snd_pcm_slave_xfer_areas_undo_func_t undo_write;
     47 	snd_pcm_sframes_t (*client_frames)(snd_pcm_t *pcm, snd_pcm_sframes_t frames);
     48 	snd_pcm_sframes_t (*slave_frames)(snd_pcm_t *pcm, snd_pcm_sframes_t frames);
     49 	int (*init)(snd_pcm_t *pcm);
     50 	snd_pcm_uframes_t appl_ptr, hw_ptr;
     51 	snd_atomic_write_t watom;
     52 } snd_pcm_plugin_t;
     53 
     54 /* make local functions really local */
     55 #define snd_pcm_plugin_init \
     56 	snd1_pcm_plugin_init
     57 #define snd_pcm_plugin_fast_ops \
     58 	snd1_pcm_plugin_fast_ops
     59 #define snd_pcm_plugin_undo_read_generic \
     60 	snd1_pcm_plugin_undo_read_generic
     61 #define snd_pcm_plugin_undo_write_generic \
     62 	snd1_pcm_plugin_undo_write_generic
     63 
     64 void snd_pcm_plugin_init(snd_pcm_plugin_t *plugin);
     65 
     66 extern const snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops;
     67 
     68 snd_pcm_sframes_t snd_pcm_plugin_undo_read_generic
     69      (snd_pcm_t *pcm,
     70       const snd_pcm_channel_area_t *res_areas,	/* result areas */
     71       snd_pcm_uframes_t res_offset,		/* offset of result areas */
     72       snd_pcm_uframes_t res_size,		/* size of result areas */
     73       snd_pcm_uframes_t slave_undo_size);
     74 
     75 snd_pcm_sframes_t snd_pcm_plugin_undo_write_generic
     76      (snd_pcm_t *pcm,
     77       const snd_pcm_channel_area_t *res_areas,	/* result areas */
     78       snd_pcm_uframes_t res_offset,		/* offset of result areas */
     79       snd_pcm_uframes_t res_size,		/* size of result areas */
     80       snd_pcm_uframes_t slave_undo_size);
     81 
     82 /* make local functions really local */
     83 #define snd_pcm_linear_get_index	snd1_pcm_linear_get_index
     84 #define snd_pcm_linear_put_index	snd1_pcm_linear_put_index
     85 #define snd_pcm_linear_get32_index	snd1_pcm_linear_get32_index
     86 #define snd_pcm_linear_put32_index	snd1_pcm_linear_put32_index
     87 #define snd_pcm_linear_convert_index	snd1_pcm_linear_convert_index
     88 #define snd_pcm_linear_convert	snd1_pcm_linear_convert
     89 #define snd_pcm_linear_getput	snd1_pcm_linear_getput
     90 #define snd_pcm_alaw_decode	snd1_pcm_alaw_decode
     91 #define snd_pcm_alaw_encode	snd1_pcm_alaw_encode
     92 #define snd_pcm_mulaw_decode	snd1_pcm_mulaw_decode
     93 #define snd_pcm_mulaw_encode	snd1_pcm_mulaw_encode
     94 #define snd_pcm_adpcm_decode	snd1_pcm_adpcm_decode
     95 #define snd_pcm_adpcm_encode	snd1_pcm_adpcm_encode
     96 
     97 int snd_pcm_linear_get_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
     98 int snd_pcm_linear_put_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
     99 int snd_pcm_linear_get32_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
    100 int snd_pcm_linear_put32_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
    101 int snd_pcm_linear_convert_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
    102 
    103 void snd_pcm_linear_convert(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
    104 			    const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
    105 			    unsigned int channels, snd_pcm_uframes_t frames,
    106 			    unsigned int convidx);
    107 void snd_pcm_linear_getput(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
    108 			   const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
    109 			   unsigned int channels, snd_pcm_uframes_t frames,
    110 			   unsigned int get_idx, unsigned int put_idx);
    111 void snd_pcm_alaw_decode(const snd_pcm_channel_area_t *dst_areas,
    112 			 snd_pcm_uframes_t dst_offset,
    113 			 const snd_pcm_channel_area_t *src_areas,
    114 			 snd_pcm_uframes_t src_offset,
    115 			 unsigned int channels, snd_pcm_uframes_t frames,
    116 			 unsigned int putidx);
    117 void snd_pcm_alaw_encode(const snd_pcm_channel_area_t *dst_areas,
    118 			 snd_pcm_uframes_t dst_offset,
    119 			 const snd_pcm_channel_area_t *src_areas,
    120 			 snd_pcm_uframes_t src_offset,
    121 			 unsigned int channels, snd_pcm_uframes_t frames,
    122 			 unsigned int getidx);
    123 void snd_pcm_mulaw_decode(const snd_pcm_channel_area_t *dst_areas,
    124 			  snd_pcm_uframes_t dst_offset,
    125 			  const snd_pcm_channel_area_t *src_areas,
    126 			  snd_pcm_uframes_t src_offset,
    127 			  unsigned int channels, snd_pcm_uframes_t frames,
    128 			  unsigned int putidx);
    129 void snd_pcm_mulaw_encode(const snd_pcm_channel_area_t *dst_areas,
    130 			  snd_pcm_uframes_t dst_offset,
    131 			  const snd_pcm_channel_area_t *src_areas,
    132 			  snd_pcm_uframes_t src_offset,
    133 			  unsigned int channels, snd_pcm_uframes_t frames,
    134 			  unsigned int getidx);
    135 
    136 typedef struct _snd_pcm_adpcm_state {
    137 	int pred_val;		/* Calculated predicted value */
    138 	int step_idx;		/* Previous StepSize lookup index */
    139 } snd_pcm_adpcm_state_t;
    140 
    141 void snd_pcm_adpcm_decode(const snd_pcm_channel_area_t *dst_areas,
    142 			  snd_pcm_uframes_t dst_offset,
    143 			  const snd_pcm_channel_area_t *src_areas,
    144 			  snd_pcm_uframes_t src_offset,
    145 			  unsigned int channels, snd_pcm_uframes_t frames,
    146 			  unsigned int putidx,
    147 			  snd_pcm_adpcm_state_t *states);
    148 void snd_pcm_adpcm_encode(const snd_pcm_channel_area_t *dst_areas,
    149 			  snd_pcm_uframes_t dst_offset,
    150 			  const snd_pcm_channel_area_t *src_areas,
    151 			  snd_pcm_uframes_t src_offset,
    152 			  unsigned int channels, snd_pcm_uframes_t frames,
    153 			  unsigned int getidx,
    154 			  snd_pcm_adpcm_state_t *states);
    155