1 #include <stdio.h>
2 #include <opus_types.h>
3 #include <opusenc.h>
4 
5 #ifdef ENABLE_NLS
6 # include <libintl.h>
7 # define _(X) gettext(X)
8 #else
9 # define _(X) (X)
10 # define textdomain(X)
11 # define bindtextdomain(X, Y)
12 #endif
13 #ifdef gettext_noop
14 # define N_(X) gettext_noop(X)
15 #else
16 # define N_(X) (X)
17 #endif
18 
19 typedef long (*audio_read_func)(void *src, float *buffer, int samples);
20 
21 typedef struct
22 {
23     audio_read_func read_samples;
24     void *readdata;
25     opus_int64 total_samples_per_channel;
26     int rawmode;
27     int channels;
28     long rate;
29     int gain;
30     int samplesize;
31     int endianness;
32     int ignorelength;
33     OggOpusComments *comments;
34     int copy_comments;
35     int copy_pictures;
36 } oe_enc_opt;
37 
38 void setup_scaler(oe_enc_opt *opt, float scale);
39 void clear_scaler(oe_enc_opt *opt);
40 int setup_downmix(oe_enc_opt *opt, int out_channels);
41 void clear_downmix(oe_enc_opt *opt);
42 
43 typedef struct
44 {
45     int (*id_func)(unsigned char *buf, int len); /* Returns true if can load file */
46     int id_data_len; /* Amount of data needed to id whether this can load the file */
47     int (*open_func)(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen);
48     void (*close_func)(void *);
49     char *format;
50     char *description;
51 } input_format;
52 
53 typedef struct {
54     unsigned short format;
55     unsigned short channels;
56     unsigned int samplerate;
57     unsigned int bytespersec;
58     unsigned short align;
59     unsigned short samplesize;
60     unsigned int mask;
61 } wav_fmt;
62 
63 typedef struct {
64     unsigned short channels;
65     short samplesize;
66     opus_int64 totalsamples;
67     opus_int64 samplesread;
68     FILE *f;
69     short bigendian;
70     short unsigned8bit;
71     int *channel_permute;
72 } wavfile;
73 
74 typedef struct {
75     short channels;
76     unsigned int totalframes;
77     short samplesize;
78     double rate;
79     unsigned int offset;
80     unsigned int blocksize;
81 } aiff_fmt;
82 
83 typedef wavfile aifffile; /* They're the same */
84 
85 input_format *open_audio_file(FILE *in, oe_enc_opt *opt);
86 
87 int raw_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen);
88 int wav_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen);
89 int aiff_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen);
90 int wav_id(unsigned char *buf, int len);
91 int aiff_id(unsigned char *buf, int len);
92 void wav_close(void *);
93 void raw_close(void *);
94 
95 long wav_read(void *, float *buffer, int samples);
96 long wav_ieee_read(void *, float *buffer, int samples);
97