blob: 83225f2b6c11b82c98b406c17910bbc473b6ca21 [file] [log] [blame]
Ralph Giles3a9b3542012-08-17 10:16:24 -07001/* Copyright (c) 2012 Xiph.Org Foundation
Jean-Marc Valin6696a142011-08-22 10:40:38 -04002 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
Jean-Marc Valincb05e7c2012-04-20 16:40:24 -040018 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Jean-Marc Valin6696a142011-08-22 10:40:38 -040020 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
Jean-Marc Valind4e93402011-08-27 00:52:26 -040032#include "arch.h"
33#include "opus.h"
Jean-Marc Valin51f4a322013-02-20 04:08:04 -050034#include "celt.h"
Jean-Marc Valind4e93402011-08-27 00:52:26 -040035
Jean-Marc Valinc8649d02011-10-27 22:25:33 -040036struct OpusRepacketizer {
37 unsigned char toc;
38 int nb_frames;
39 const unsigned char *frames[48];
Jean-Marc Valin35930692013-05-18 02:50:40 -040040 opus_int16 len[48];
Jean-Marc Valinc8649d02011-10-27 22:25:33 -040041 int framesize;
42};
43
Jean-Marc Valinae0e2ca2012-11-07 19:57:33 -050044typedef struct ChannelLayout {
45 int nb_channels;
46 int nb_streams;
47 int nb_coupled_streams;
48 unsigned char mapping[256];
49} ChannelLayout;
50
51int validate_layout(const ChannelLayout *layout);
52int get_left_channel(const ChannelLayout *layout, int stream_id, int prev);
53int get_right_channel(const ChannelLayout *layout, int stream_id, int prev);
54int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev);
55
56
Jean-Marc Valinc8649d02011-10-27 22:25:33 -040057
Jean-Marc Valin99774972011-08-28 15:49:32 -040058#define MODE_SILK_ONLY 1000
59#define MODE_HYBRID 1001
60#define MODE_CELT_ONLY 1002
61
Jean-Marc Valine6a0be82011-10-27 13:43:43 -040062#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
Jean-Marc Valin07dceb72011-09-08 13:53:20 -040082#define OPUS_SET_FORCE_MODE_REQUEST 11002
83#define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, __opus_check_int(x)
84
Jean-Marc Valin3ab03e02013-09-06 16:00:39 -040085typedef void (*downmix_func)(const void *, opus_val32 *, int, int, int, int, int);
86void downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
87void downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
Jean-Marc Valin10a34a52012-12-20 00:23:01 -050088
Jean-Marc Valin74483662012-12-17 16:23:42 -050089int optimize_framesize(const opus_val16 *x, int len, int C, opus_int32 Fs,
Jean-Marc Valin88481712013-11-13 11:57:31 -050090 int bitrate, opus_val16 tonality, float *mem, int buffering,
Jean-Marc Valin51f4a322013-02-20 04:08:04 -050091 downmix_func downmix);
Jean-Marc Valin07dceb72011-09-08 13:53:20 -040092
Jean-Marc Valin9f555bc2011-08-23 02:56:12 -040093int encode_size(int size, unsigned char *data);
94
Jean-Marc Valin51f4a322013-02-20 04:08:04 -050095opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs);
96
Jean-Marc Valinb90e63b2013-09-16 13:08:52 -040097opus_int32 compute_frame_size(const void *analysis_pcm, int frame_size,
98 int variable_duration, int C, opus_int32 Fs, int bitrate_bps,
Jean-Marc Valinc2b34412013-10-28 21:48:50 -040099 int delay_compensation, downmix_func downmix
100#ifndef DISABLE_FLOAT_API
Jean-Marc Valin88481712013-11-13 11:57:31 -0500101 , float *subframe_mem
Jean-Marc Valinc2b34412013-10-28 21:48:50 -0400102#endif
103 );
Jean-Marc Valinb90e63b2013-09-16 13:08:52 -0400104
Jean-Marc Valinb3eba242012-12-20 23:11:53 -0500105opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
Jean-Marc Valin91904a42013-09-05 21:34:43 -0400106 unsigned char *data, opus_int32 out_data_bytes, int lsb_depth,
Jean-Marc Valinb90e63b2013-09-16 13:08:52 -0400107 const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, int analysis_channels, downmix_func downmix);
Jean-Marc Valinb3eba242012-12-20 23:11:53 -0500108
Jean-Marc Valin59354a72012-03-08 12:19:07 -0500109int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len,
Jean-Marc Valin32c4a0c2013-03-01 15:18:23 -0500110 opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited,
Jean-Marc Valindabdb322013-10-14 13:58:51 -0400111 opus_int32 *packet_offset, int soft_clip);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400112
Gregory Maxwella403d5f2012-05-04 20:01:56 -0400113/* Make sure everything's aligned to sizeof(void *) bytes */
Gregory Maxwell7830cf12013-10-17 15:56:52 -0700114static OPUS_INLINE int align(int i)
Jean-Marc Valin6696a142011-08-22 10:40:38 -0400115{
Koen Vos0b00b312012-07-12 14:55:49 -0400116 return (i+(int)sizeof(void *)-1)&-(int)sizeof(void *);
Jean-Marc Valin6696a142011-08-22 10:40:38 -0400117}
118
Jean-Marc Valined463232013-10-11 18:06:00 -0400119int opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
120 int self_delimited, unsigned char *out_toc,
Jean-Marc Valin58042ad2013-10-14 13:45:58 -0400121 const unsigned char *frames[48], opus_int16 size[48],
Jean-Marc Valindabdb322013-10-14 13:58:51 -0400122 int *payload_offset, opus_int32 *packet_offset);
Jean-Marc Valined463232013-10-11 18:06:00 -0400123
Jean-Marc Valinc5635d22013-11-13 14:08:22 -0500124opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end,
125 unsigned char *data, opus_int32 maxlen, int self_delimited, int pad);
Jean-Marc Valin131d8882011-09-09 13:56:09 -0400126
Jean-Marc Valineab134c2013-10-14 15:01:36 -0400127int pad_frame(unsigned char *data, opus_int32 len, opus_int32 new_len);
128
Ralph Giles120800f2011-11-25 13:02:00 -0800129#endif /* OPUS_PRIVATE_H */