1 /* Copyright (c) 2012 Xiph.Org Foundation
2 Written by Jean-Marc Valin */
3 /*
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28
29 #ifndef OPUS_PRIVATE_H
30 #define OPUS_PRIVATE_H
31
32 #include "arch.h"
33 #include "opus.h"
34 #include "celt.h"
35
36 struct OpusRepacketizer {
37 unsigned char toc;
38 int nb_frames;
39 const unsigned char *frames[48];
40 opus_int16 len[48];
41 int framesize;
42 };
43
44 typedef struct ChannelLayout {
45 int nb_channels;
46 int nb_streams;
47 int nb_coupled_streams;
48 unsigned char mapping[256];
49 } ChannelLayout;
50
51 int validate_layout(const ChannelLayout *layout);
52 int get_left_channel(const ChannelLayout *layout, int stream_id, int prev);
53 int get_right_channel(const ChannelLayout *layout, int stream_id, int prev);
54 int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev);
55
56
57
58 #define MODE_SILK_ONLY 1000
59 #define MODE_HYBRID 1001
60 #define MODE_CELT_ONLY 1002
61
62 #define OPUS_SET_VOICE_RATIO_REQUEST 11018
63 #define OPUS_GET_VOICE_RATIO_REQUEST 11019
64
65 /** Configures the encoder's expected percentage of voice
66 * opposed to music or other signals.
67 *
68 * @note This interface is currently more aspiration than actuality. It's
69 * ultimately expected to bias an automatic signal classifier, but it currently
70 * just shifts the static bitrate to mode mapping around a little bit.
71 *
72 * @param[in] x <tt>int</tt>: Voice percentage in the range 0-100, inclusive.
73 * @hideinitializer */
74 #define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x)
75 /** Gets the encoder's configured voice ratio value, @see OPUS_SET_VOICE_RATIO
76 *
77 * @param[out] x <tt>int*</tt>: Voice percentage in the range 0-100, inclusive.
78 * @hideinitializer */
79 #define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x)
80
81
82 #define OPUS_SET_FORCE_MODE_REQUEST 11002
83 #define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, __opus_check_int(x)
84
85 typedef void (*downmix_func)(const void *, opus_val32 *, int, int, int, int, int);
86 void downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
87 void downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
88
89 int optimize_framesize(const opus_val16 *x, int len, int C, opus_int32 Fs,
90 int bitrate, opus_val16 tonality, opus_val32 *mem, int buffering,
91 downmix_func downmix);
92
93 int encode_size(int size, unsigned char *data);
94
95 opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs);
96
97 opus_int32 compute_frame_size(const void *analysis_pcm, int frame_size,
98 int variable_duration, int C, opus_int32 Fs, int bitrate_bps,
99 int delay_compensation, downmix_func downmix, opus_val32 *subframe_mem);
100
101 opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
102 unsigned char *data, opus_int32 out_data_bytes, int lsb_depth,
103 const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, int analysis_channels, downmix_func downmix);
104
105 int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len,
106 opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited,
107 int *packet_offset, int soft_clip);
108
109 /* Make sure everything's aligned to sizeof(void *) bytes */
align(int i)110 static inline int align(int i)
111 {
112 return (i+(int)sizeof(void *)-1)&-(int)sizeof(void *);
113 }
114
115 opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen, int self_delimited);
116
117 #endif /* OPUS_PRIVATE_H */
118