]> iEval git - fdkaac.git/blame_incremental - src/pcm_reader.h
fix help message: show -I as shorthand for --ignorelength
[fdkaac.git] / src / pcm_reader.h
... / ...
CommitLineData
1#ifndef PCM_READER_H
2#define PCM_READER_H
3
4#include "lpcm.h"
5
6typedef struct pcm_reader_t pcm_reader_t;
7
8typedef 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 **);
14} pcm_reader_vtbl_t;
15
16struct pcm_reader_t {
17 pcm_reader_vtbl_t *vtbl;
18};
19
20typedef int (*pcm_read_callback)(void *cookie, void *data, uint32_t count);
21typedef int (*pcm_seek_callback)(void *cookie, int64_t off, int whence);
22typedef int64_t (*pcm_tell_callback)(void *cookie);
23
24typedef struct pcm_io_vtbl_t {
25 pcm_read_callback read;
26 pcm_seek_callback seek;
27 pcm_tell_callback tell;
28} pcm_io_vtbl_t;
29
30typedef struct pcm_io_context_t {
31 pcm_io_vtbl_t *vtbl;
32 void *cookie;
33} pcm_io_context_t;
34
35static inline
36const pcm_sample_description_t *pcm_get_format(pcm_reader_t *r)
37{
38 return r->vtbl->get_format(r);
39}
40
41static inline
42int64_t pcm_get_length(pcm_reader_t *r)
43{
44 return r->vtbl->get_length(r);
45}
46
47static inline
48int64_t pcm_get_position(pcm_reader_t *r)
49{
50 return r->vtbl->get_position(r);
51}
52
53static inline
54int64_t pcm_read_frames(pcm_reader_t *r, void *data, unsigned nframes)
55{
56 return r->vtbl->read_frames(r, data, nframes);
57}
58
59static inline
60void pcm_teardown(pcm_reader_t **r)
61{
62 (*r)->vtbl->teardown(r);
63}
64
65static inline
66uint32_t bitcount(uint32_t bits)
67{
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);
73}
74
75#define TRY_IO(expr) \
76 do { \
77 if ((expr)) goto FAIL; \
78 } while (0)
79
80#define ENSURE(expr) \
81 do { \
82 if (!(expr)) goto FAIL;\
83 } while (0)
84
85int pcm_read(pcm_io_context_t *io, void *buffer, uint32_t size);
86int pcm_skip(pcm_io_context_t *io, int64_t count);
87
88static int pcm_seek(pcm_io_context_t *io, int64_t off, int whence)
89{
90 return io->vtbl->seek ? io->vtbl->seek(io->cookie, off, whence) : -1;
91}
92
93static inline int64_t pcm_tell(pcm_io_context_t *io)
94{
95 return io->vtbl->tell ? io->vtbl->tell(io->cookie) : -1;
96}
97
98int pcm_read16le(pcm_io_context_t *io, uint16_t *value);
99int pcm_read16be(pcm_io_context_t *io, uint16_t *value);
100int pcm_read32le(pcm_io_context_t *io, uint32_t *value);
101int pcm_read32be(pcm_io_context_t *io, uint32_t *value);
102int pcm_read64le(pcm_io_context_t *io, uint64_t *value);
103int pcm_read64be(pcm_io_context_t *io, uint64_t *value);
104int pcm_scanl(pcm_io_context_t *io, const char *fmt, ...);
105int pcm_scanb(pcm_io_context_t *io, const char *fmt, ...);
106
107int apple_chan_chunk(pcm_io_context_t *io, uint32_t chunk_size,
108 pcm_sample_description_t *fmt, uint8_t *mapping);
109
110pcm_reader_t *pcm_open_sint16_converter(pcm_reader_t *reader);
111
112#endif
This page took 0.022123 seconds and 4 git commands to generate.