1 /* libSoX ADPCM codecs: IMA, OKI, CL. (c) 2007-8 robs@users.sourceforge.net 2 * 3 * This library is free software; you can redistribute it and/or modify it 4 * under the terms of the GNU Lesser General Public License as published by 5 * the Free Software Foundation; either version 2.1 of the License, or (at 6 * your option) any later version. 7 * 8 * This library is distributed in the hope that it will be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 11 * General Public License for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this library; if not, write to the Free Software Foundation, 15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 */ 17 18 typedef struct { 19 int max_step_index; 20 int sign; 21 int shift; 22 int const * steps; 23 int const * changes; 24 int mask; 25 } adpcm_setup_t; 26 27 typedef struct { 28 adpcm_setup_t setup; 29 int last_output; 30 int step_index; 31 int errors; 32 } adpcm_t; 33 34 void lsx_adpcm_init(adpcm_t * p, int type, int first_sample); 35 int lsx_adpcm_decode(int code, adpcm_t * p); 36 int lsx_adpcm_encode(int sample, adpcm_t * p); 37 38 typedef struct { 39 adpcm_t encoder; 40 struct { 41 uint8_t byte; /* write store */ 42 uint8_t flag; 43 } store; 44 sox_fileinfo_t file; 45 } adpcm_io_t; 46 47 /* Format methods */ 48 void lsx_adpcm_reset(adpcm_io_t * state, sox_encoding_t type); 49 int lsx_adpcm_oki_start(sox_format_t * ft, adpcm_io_t * state); 50 int lsx_adpcm_ima_start(sox_format_t * ft, adpcm_io_t * state); 51 size_t lsx_adpcm_read(sox_format_t * ft, adpcm_io_t * state, sox_sample_t *buffer, size_t len); 52 int lsx_adpcm_stopread(sox_format_t * ft, adpcm_io_t * state); 53 size_t lsx_adpcm_write(sox_format_t * ft, adpcm_io_t * state, const sox_sample_t *buffer, size_t length); 54 void lsx_adpcm_flush(sox_format_t * ft, adpcm_io_t * state); 55 int lsx_adpcm_stopwrite(sox_format_t * ft, adpcm_io_t * state); 56