michael@0: /* Copyright (c) 2012 Xiph.Org Foundation
michael@0: Written by Jean-Marc Valin */
michael@0: /*
michael@0: Redistribution and use in source and binary forms, with or without
michael@0: modification, are permitted provided that the following conditions
michael@0: are met:
michael@0:
michael@0: - Redistributions of source code must retain the above copyright
michael@0: notice, this list of conditions and the following disclaimer.
michael@0:
michael@0: - Redistributions in binary form must reproduce the above copyright
michael@0: notice, this list of conditions and the following disclaimer in the
michael@0: documentation and/or other materials provided with the distribution.
michael@0:
michael@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
michael@0: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
michael@0: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
michael@0: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
michael@0: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0: */
michael@0:
michael@0:
michael@0: #ifndef OPUS_PRIVATE_H
michael@0: #define OPUS_PRIVATE_H
michael@0:
michael@0: #include "arch.h"
michael@0: #include "opus.h"
michael@0: #include "celt.h"
michael@0:
michael@0: struct OpusRepacketizer {
michael@0: unsigned char toc;
michael@0: int nb_frames;
michael@0: const unsigned char *frames[48];
michael@0: opus_int16 len[48];
michael@0: int framesize;
michael@0: };
michael@0:
michael@0: typedef struct ChannelLayout {
michael@0: int nb_channels;
michael@0: int nb_streams;
michael@0: int nb_coupled_streams;
michael@0: unsigned char mapping[256];
michael@0: } ChannelLayout;
michael@0:
michael@0: int validate_layout(const ChannelLayout *layout);
michael@0: int get_left_channel(const ChannelLayout *layout, int stream_id, int prev);
michael@0: int get_right_channel(const ChannelLayout *layout, int stream_id, int prev);
michael@0: int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev);
michael@0:
michael@0:
michael@0:
michael@0: #define MODE_SILK_ONLY 1000
michael@0: #define MODE_HYBRID 1001
michael@0: #define MODE_CELT_ONLY 1002
michael@0:
michael@0: #define OPUS_SET_VOICE_RATIO_REQUEST 11018
michael@0: #define OPUS_GET_VOICE_RATIO_REQUEST 11019
michael@0:
michael@0: /** Configures the encoder's expected percentage of voice
michael@0: * opposed to music or other signals.
michael@0: *
michael@0: * @note This interface is currently more aspiration than actuality. It's
michael@0: * ultimately expected to bias an automatic signal classifier, but it currently
michael@0: * just shifts the static bitrate to mode mapping around a little bit.
michael@0: *
michael@0: * @param[in] x int: Voice percentage in the range 0-100, inclusive.
michael@0: * @hideinitializer */
michael@0: #define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x)
michael@0: /** Gets the encoder's configured voice ratio value, @see OPUS_SET_VOICE_RATIO
michael@0: *
michael@0: * @param[out] x int*: Voice percentage in the range 0-100, inclusive.
michael@0: * @hideinitializer */
michael@0: #define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x)
michael@0:
michael@0:
michael@0: #define OPUS_SET_FORCE_MODE_REQUEST 11002
michael@0: #define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, __opus_check_int(x)
michael@0:
michael@0: typedef void (*downmix_func)(const void *, opus_val32 *, int, int, int, int, int);
michael@0: void downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
michael@0: void downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
michael@0:
michael@0: int optimize_framesize(const opus_val16 *x, int len, int C, opus_int32 Fs,
michael@0: int bitrate, opus_val16 tonality, float *mem, int buffering,
michael@0: downmix_func downmix);
michael@0:
michael@0: int encode_size(int size, unsigned char *data);
michael@0:
michael@0: opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs);
michael@0:
michael@0: opus_int32 compute_frame_size(const void *analysis_pcm, int frame_size,
michael@0: int variable_duration, int C, opus_int32 Fs, int bitrate_bps,
michael@0: int delay_compensation, downmix_func downmix
michael@0: #ifndef DISABLE_FLOAT_API
michael@0: , float *subframe_mem
michael@0: #endif
michael@0: );
michael@0:
michael@0: opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
michael@0: unsigned char *data, opus_int32 out_data_bytes, int lsb_depth,
michael@0: const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, int analysis_channels, downmix_func downmix);
michael@0:
michael@0: int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len,
michael@0: opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited,
michael@0: opus_int32 *packet_offset, int soft_clip);
michael@0:
michael@0: /* Make sure everything's aligned to sizeof(void *) bytes */
michael@0: static OPUS_INLINE int align(int i)
michael@0: {
michael@0: return (i+(int)sizeof(void *)-1)&-(int)sizeof(void *);
michael@0: }
michael@0:
michael@0: int opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
michael@0: int self_delimited, unsigned char *out_toc,
michael@0: const unsigned char *frames[48], opus_int16 size[48],
michael@0: int *payload_offset, opus_int32 *packet_offset);
michael@0:
michael@0: opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end,
michael@0: unsigned char *data, opus_int32 maxlen, int self_delimited, int pad);
michael@0:
michael@0: int pad_frame(unsigned char *data, opus_int32 len, opus_int32 new_len);
michael@0:
michael@0: #endif /* OPUS_PRIVATE_H */