6 typedef struct pcm_reader_t pcm_reader_t
;
8 typedef struct pcm_reader_vtbl_t
{
9 const pcm_sample_description_t
*(*get_format
)(pcm_reader_t
*);
10 int64_t (*get_length
)(pcm_reader_t
*);
11 int64_t (*get_position
)(pcm_reader_t
*);
12 int (*read_frames
)(pcm_reader_t
*, void *, unsigned);
13 void (*teardown
)(pcm_reader_t
**);
17 pcm_reader_vtbl_t
*vtbl
;
20 typedef int (*pcm_read_callback
)(void *cookie
, void *data
, uint32_t count
);
21 typedef int (*pcm_seek_callback
)(void *cookie
, int64_t off
, int whence
);
22 typedef int64_t (*pcm_tell_callback
)(void *cookie
);
24 typedef struct pcm_io_vtbl_t
{
25 pcm_read_callback read
;
26 pcm_seek_callback seek
;
27 pcm_tell_callback tell
;
30 typedef struct pcm_io_context_t
{
36 const pcm_sample_description_t
*pcm_get_format(pcm_reader_t
*r
)
38 return r
->vtbl
->get_format(r
);
42 int64_t pcm_get_length(pcm_reader_t
*r
)
44 return r
->vtbl
->get_length(r
);
48 int64_t pcm_get_position(pcm_reader_t
*r
)
50 return r
->vtbl
->get_position(r
);
54 int64_t pcm_read_frames(pcm_reader_t
*r
, void *data
, unsigned nframes
)
56 return r
->vtbl
->read_frames(r
, data
, nframes
);
60 void pcm_teardown(pcm_reader_t
**r
)
62 (*r
)->vtbl
->teardown(r
);
66 uint32_t bitcount(uint32_t bits
)
68 bits
= (bits
& 0x55555555) + (bits
>> 1 & 0x55555555);
69 bits
= (bits
& 0x33333333) + (bits
>> 2 & 0x33333333);
70 bits
= (bits
& 0x0f0f0f0f) + (bits
>> 4 & 0x0f0f0f0f);
71 bits
= (bits
& 0x00ff00ff) + (bits
>> 8 & 0x00ff00ff);
72 return (bits
& 0x0000ffff) + (bits
>>16 & 0x0000ffff);
75 #define TRY_IO(expr) \
77 if ((expr)) goto FAIL; \
80 #define ENSURE(expr) \
82 if (!(expr)) goto FAIL;\
85 int pcm_read(pcm_io_context_t
*io
, void *buffer
, uint32_t size
);
86 int pcm_skip(pcm_io_context_t
*io
, int64_t count
);
88 static inline int pcm_seek(pcm_io_context_t
*io
, int64_t off
, int whence
)
90 return io
->vtbl
->seek
? io
->vtbl
->seek(io
->cookie
, off
, whence
) : -1;
93 static inline int64_t pcm_tell(pcm_io_context_t
*io
)
95 return io
->vtbl
->tell
? io
->vtbl
->tell(io
->cookie
) : -1;
98 int pcm_read16le(pcm_io_context_t
*io
, uint16_t *value
);
99 int pcm_read16be(pcm_io_context_t
*io
, uint16_t *value
);
100 int pcm_read32le(pcm_io_context_t
*io
, uint32_t *value
);
101 int pcm_read32be(pcm_io_context_t
*io
, uint32_t *value
);
102 int pcm_read64le(pcm_io_context_t
*io
, uint64_t *value
);
103 int pcm_read64be(pcm_io_context_t
*io
, uint64_t *value
);
104 int pcm_scanl(pcm_io_context_t
*io
, const char *fmt
, ...);
105 int pcm_scanb(pcm_io_context_t
*io
, const char *fmt
, ...);
107 int apple_chan_chunk(pcm_io_context_t
*io
, uint32_t chunk_size
,
108 pcm_sample_description_t
*fmt
, uint8_t *mapping
);
110 pcm_reader_t
*pcm_open_sint16_converter(pcm_reader_t
*reader
);
112 pcm_reader_t
*extrapolater_open(pcm_reader_t
*reader
);