1885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org/* Copyright (c) 2012 Xiph.Org Foundation
2885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   Written by Jean-Marc Valin */
3885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org/*
4885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   Redistribution and use in source and binary forms, with or without
5885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   modification, are permitted provided that the following conditions
6885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   are met:
7885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
8885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   - Redistributions of source code must retain the above copyright
9885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   notice, this list of conditions and the following disclaimer.
10885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
11885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   - Redistributions in binary form must reproduce the above copyright
12885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   notice, this list of conditions and the following disclaimer in the
13885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   documentation and/or other materials provided with the distribution.
14885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
15885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org*/
27885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
28885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
29885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#ifndef OPUS_PRIVATE_H
30885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define OPUS_PRIVATE_H
31885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
32885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#include "arch.h"
33885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#include "opus.h"
34e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org#include "celt.h"
35885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
36885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgstruct OpusRepacketizer {
37885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   unsigned char toc;
38885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   int nb_frames;
39885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   const unsigned char *frames[48];
40e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org   opus_int16 len[48];
41885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org   int framesize;
42885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org};
43885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
44e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgtypedef struct ChannelLayout {
45e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org   int nb_channels;
46e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org   int nb_streams;
47e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org   int nb_coupled_streams;
48e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org   unsigned char mapping[256];
49e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org} ChannelLayout;
50e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org
51e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgint validate_layout(const ChannelLayout *layout);
52e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgint get_left_channel(const ChannelLayout *layout, int stream_id, int prev);
53e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgint get_right_channel(const ChannelLayout *layout, int stream_id, int prev);
54e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgint get_mono_channel(const ChannelLayout *layout, int stream_id, int prev);
55e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org
56e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org
57885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
58885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define MODE_SILK_ONLY          1000
59885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define MODE_HYBRID             1001
60885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define MODE_CELT_ONLY          1002
61885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
62885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define OPUS_SET_VOICE_RATIO_REQUEST         11018
63885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define OPUS_GET_VOICE_RATIO_REQUEST         11019
64885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
65885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org/** Configures the encoder's expected percentage of voice
66885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  * opposed to music or other signals.
67885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  *
68885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  * @note This interface is currently more aspiration than actuality. It's
69885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  * ultimately expected to bias an automatic signal classifier, but it currently
70885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  * just shifts the static bitrate to mode mapping around a little bit.
71885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  *
72885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  * @param[in] x <tt>int</tt>:   Voice percentage in the range 0-100, inclusive.
73885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  * @hideinitializer */
74885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x)
75885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org/** Gets the encoder's configured voice ratio value, @see OPUS_SET_VOICE_RATIO
76885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  *
77885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  * @param[out] x <tt>int*</tt>:  Voice percentage in the range 0-100, inclusive.
78885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org  * @hideinitializer */
79885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x)
80885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
81885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
82885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define OPUS_SET_FORCE_MODE_REQUEST    11002
83885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, __opus_check_int(x)
84885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
85e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgtypedef void (*downmix_func)(const void *, opus_val32 *, int, int, int, int, int);
86e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgvoid downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
87e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgvoid downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
88e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org
89e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgint optimize_framesize(const opus_val16 *x, int len, int C, opus_int32 Fs,
903c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com                int bitrate, opus_val16 tonality, float *mem, int buffering,
91e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org                downmix_func downmix);
92885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
93885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgint encode_size(int size, unsigned char *data);
94885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
95e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgopus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs);
96e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org
97e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgopus_int32 compute_frame_size(const void *analysis_pcm, int frame_size,
98e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org      int variable_duration, int C, opus_int32 Fs, int bitrate_bps,
993c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com      int delay_compensation, downmix_func downmix
1003c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com#ifndef DISABLE_FLOAT_API
1013c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com      , float *subframe_mem
1023c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com#endif
1033c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com      );
104e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org
105e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.orgopus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
106e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org      unsigned char *data, opus_int32 out_data_bytes, int lsb_depth,
107e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org      const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, int analysis_channels, downmix_func downmix);
108e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org
109885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.orgint opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len,
110e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org      opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited,
1113c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com      opus_int32 *packet_offset, int soft_clip);
112885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
113885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org/* Make sure everything's aligned to sizeof(void *) bytes */
1143c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.comstatic OPUS_INLINE int align(int i)
115885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org{
116e3ea049fcaee2247e45f0ce793d4313babb4ef69tlegrand@chromium.org    return (i+(int)sizeof(void *)-1)&-(int)sizeof(void *);
117885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org}
118885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
1193c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.comint opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
1203c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com      int self_delimited, unsigned char *out_toc,
1213c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com      const unsigned char *frames[48], opus_int16 size[48],
1223c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com      int *payload_offset, opus_int32 *packet_offset);
1233c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com
1243c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.comopus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end,
1253c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com      unsigned char *data, opus_int32 maxlen, int self_delimited, int pad);
1263c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.com
1273c3902f0ac13428394f14f78f0fab05ef3468d69tlegrand@google.comint pad_frame(unsigned char *data, opus_int32 len, opus_int32 new_len);
128885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org
129885f2ff5a7a7d6a73432d26a6c0ae9147e6b452sergeyu@chromium.org#endif /* OPUS_PRIVATE_H */
130