2008-07-20 07:41:41 +02:00
|
|
|
/*
|
|
|
|
* libacm - Interplay ACM audio decoder.
|
|
|
|
*
|
2018-09-04 22:42:21 +02:00
|
|
|
* Copyright (c) 2004-2010, Marko Kreen
|
2008-07-20 07:41:41 +02:00
|
|
|
*
|
2018-09-04 22:42:21 +02:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
2008-07-20 07:41:41 +02:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LIBACM_H
|
|
|
|
#define __LIBACM_H
|
|
|
|
|
2018-09-04 22:42:21 +02:00
|
|
|
#define LIBACM_VERSION "1.1"
|
2008-07-20 07:41:41 +02:00
|
|
|
|
|
|
|
#define ACM_ID 0x032897
|
|
|
|
#define ACM_WORD 2
|
|
|
|
|
|
|
|
#define ACM_OK 0
|
|
|
|
#define ACM_ERR_OTHER -1
|
|
|
|
#define ACM_ERR_OPEN -2
|
|
|
|
#define ACM_ERR_NOT_ACM -3
|
|
|
|
#define ACM_ERR_READ_ERR -4
|
|
|
|
#define ACM_ERR_BADFMT -5
|
|
|
|
#define ACM_ERR_CORRUPT -6
|
|
|
|
#define ACM_ERR_UNEXPECTED_EOF -7
|
|
|
|
#define ACM_ERR_NOT_SEEKABLE -8
|
|
|
|
|
|
|
|
typedef struct ACMInfo {
|
2008-07-22 05:15:57 +02:00
|
|
|
unsigned channels;
|
|
|
|
unsigned rate;
|
|
|
|
unsigned acm_id;
|
|
|
|
unsigned acm_version;
|
2018-09-04 22:42:21 +02:00
|
|
|
unsigned acm_channels; /* channels from header (usually wrong) */
|
2008-07-22 05:15:57 +02:00
|
|
|
unsigned acm_level;
|
|
|
|
unsigned acm_cols; /* 1 << acm_level */
|
|
|
|
unsigned acm_rows;
|
2008-07-20 07:41:41 +02:00
|
|
|
} ACMInfo;
|
|
|
|
|
2018-09-04 22:42:21 +02:00
|
|
|
typedef struct {
|
|
|
|
/* read bytes */
|
|
|
|
int (*read_func)(void *ptr, int size, int n, void *datasrc);
|
|
|
|
/* optional, must support seeking into start*/
|
|
|
|
int (*seek_func)(void *datasrc, int offset, int whence);
|
|
|
|
/* optional, called on acm_close */
|
|
|
|
int (*close_func)(void *datasrc);
|
|
|
|
/* returns size in bytes*/
|
|
|
|
int (*get_length_func)(void *datasrc);
|
|
|
|
} acm_io_callbacks;
|
|
|
|
|
2008-07-20 07:41:41 +02:00
|
|
|
struct ACMStream {
|
|
|
|
ACMInfo info;
|
2008-07-22 05:15:57 +02:00
|
|
|
unsigned total_values;
|
2008-07-20 07:41:41 +02:00
|
|
|
|
|
|
|
/* acm data stream */
|
2018-09-04 22:42:21 +02:00
|
|
|
void *io_arg;
|
|
|
|
acm_io_callbacks io;
|
2008-07-22 05:15:57 +02:00
|
|
|
unsigned data_len;
|
2008-07-20 07:41:41 +02:00
|
|
|
|
|
|
|
/* acm stream buffer */
|
2018-09-04 22:42:21 +02:00
|
|
|
unsigned char *buf;
|
|
|
|
unsigned buf_max, buf_size, buf_pos, bit_avail;
|
2008-07-20 07:41:41 +02:00
|
|
|
unsigned bit_data;
|
|
|
|
unsigned buf_start_ofs;
|
|
|
|
|
|
|
|
/* block lengths (in samples) */
|
2008-07-22 05:15:57 +02:00
|
|
|
unsigned block_len;
|
|
|
|
unsigned wrapbuf_len;
|
2008-07-20 07:41:41 +02:00
|
|
|
/* buffers */
|
|
|
|
int *block;
|
|
|
|
int *wrapbuf;
|
|
|
|
int *ampbuf;
|
|
|
|
int *midbuf; /* pointer into ampbuf */
|
|
|
|
/* result */
|
2008-07-22 05:15:57 +02:00
|
|
|
unsigned block_ready:1;
|
|
|
|
unsigned file_eof:1;
|
2018-09-04 22:42:21 +02:00
|
|
|
unsigned wavc_file:1;
|
2008-07-22 05:15:57 +02:00
|
|
|
unsigned stream_pos; /* in words. absolute */
|
|
|
|
unsigned block_pos; /* in words, relative */
|
2008-07-20 07:41:41 +02:00
|
|
|
};
|
|
|
|
typedef struct ACMStream ACMStream;
|
|
|
|
|
|
|
|
/* decode.c */
|
2018-09-04 22:42:21 +02:00
|
|
|
int acm_open_decoder(ACMStream **res, void *io_arg, acm_io_callbacks io, int force_chans);
|
2008-07-22 05:15:57 +02:00
|
|
|
int acm_read(ACMStream *acm, void *buf, unsigned nbytes,
|
2008-07-20 07:41:41 +02:00
|
|
|
int bigendianp, int wordlen, int sgned);
|
|
|
|
void acm_close(ACMStream *acm);
|
2018-09-04 22:42:21 +02:00
|
|
|
|
|
|
|
/* util.c */
|
|
|
|
int acm_open_file(ACMStream **acm, const char *filename, int force_chans);
|
|
|
|
const ACMInfo *acm_info(ACMStream *acm);
|
|
|
|
int acm_seekable(ACMStream *acm);
|
|
|
|
unsigned acm_bitrate(ACMStream *acm);
|
|
|
|
unsigned acm_rate(ACMStream *acm);
|
|
|
|
unsigned acm_channels(ACMStream *acm);
|
|
|
|
unsigned acm_raw_total(ACMStream *acm);
|
|
|
|
unsigned acm_raw_tell(ACMStream *acm);
|
|
|
|
unsigned acm_pcm_total(ACMStream *acm);
|
|
|
|
unsigned acm_pcm_tell(ACMStream *acm);
|
|
|
|
unsigned acm_time_total(ACMStream *acm);
|
|
|
|
unsigned acm_time_tell(ACMStream *acm);
|
|
|
|
int acm_read_loop(ACMStream *acm, void *dst, unsigned len,
|
|
|
|
int bigendianp, int wordlen, int sgned);
|
|
|
|
int acm_seek_pcm(ACMStream *acm, unsigned pcm_pos);
|
|
|
|
int acm_seek_time(ACMStream *acm, unsigned pos_ms);
|
|
|
|
const char *acm_strerror(int err);
|
2008-07-20 07:41:41 +02:00
|
|
|
|
2008-07-20 09:28:17 +02:00
|
|
|
#endif
|
2018-09-04 22:42:21 +02:00
|
|
|
|