初版
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
#ifndef AUDIO_DECODE_COMMON_API_H
|
||||
#define AUDIO_DECODE_COMMON_API_H
|
||||
|
||||
#include "cpu.h"
|
||||
/********************* DEC *********************/
|
||||
|
||||
//通用解码器配置信息
|
||||
#define PLAY_MOD_NORMAL 0x00
|
||||
#define PLAY_MOD_FF 0x01
|
||||
#define PLAY_MOD_FB 0x02
|
||||
#define SET_DECODE_MODE 0x80
|
||||
|
||||
typedef struct _AUDIO_DECODE_PARA {
|
||||
u32 mode;
|
||||
} AUDIO_DECODE_PARA;
|
||||
|
||||
typedef struct _deccfg_inf {
|
||||
u32 bitwidth; //16_24(s32)
|
||||
u32 channels; //最多支持的声道数
|
||||
u32 sr; //最大支持的采样率.
|
||||
} deccfg_inf;
|
||||
|
||||
typedef struct decoder_inf {
|
||||
u32 sr ; ///< sample rate
|
||||
u32 br ; ///< bit rate
|
||||
u32 nch ; ///<声道
|
||||
u32 total_time; ///<总时间
|
||||
} dec_inf_t ;
|
||||
|
||||
enum { //format_check 格式检查返回值, FORMAT_OK可继续调run,
|
||||
//sdk根据获取的解码信息位宽、采样率、声道数控制是否支持解码.
|
||||
FORMAT_OK = 0,
|
||||
FORMAT_OK_BUT_NO_SUPPORT, //格式正确不支持的其他参数.
|
||||
FORMAT_ERR,
|
||||
FORMAT_NOT_DETECTED,
|
||||
FORMAT_OK_UNSUPPORTED_BPS, //不支持的位宽.
|
||||
FORMAT_OK_UNSUPPORTED_NSR, //不支持的采样率.
|
||||
FORMAT_OK_UNSUPPORTED_NCH, //不支持的声道数.
|
||||
FORMAT_OK_UNSUPPORTED_BLK, //不支持的块长度.
|
||||
M4A_MEMORY_NOT_ENOUGH = 0x10,
|
||||
};
|
||||
|
||||
//编解码器错误的返回值
|
||||
enum {
|
||||
MAD_ERROR_FILE_END = 0x40, //文件结束
|
||||
MAD_ERROR_FILESYSTEM_ERR = 0x41,
|
||||
MAD_ERROR_DISK_ERR = 0x42,
|
||||
MAD_ERROR_SYNC_LIMIT = 0x43,
|
||||
MAD_ERROR_FF_FR_FILE_END = 0x44, //快进到文件结束了
|
||||
MAD_ERROR_FF_FR_END = 0x45,
|
||||
MAD_ERROR_FF_FR_FILE_START = 0x46, //快退到头
|
||||
MAD_ERROR_LIMIT = 0x47,
|
||||
MAD_ERROR_NODATA = 0x48, //读不到数了
|
||||
MAD_ERROR_UNKNOWN_REQ_INDEX_CODEBOOK = 0x49,
|
||||
MAD_ERROR_BLOCK_CODE_LOOKUP_FAILED = 0x4a,
|
||||
MAD_ERROR_SUBFRAME_COUNTER = 0x4b,
|
||||
MAD_ERROR_BITALLOC = 0x4c,
|
||||
MAD_ERROR_HEADER_CHECK = 0x4d,
|
||||
MAD_ERROR_FOOTER_CHECK = 0x4e,
|
||||
MAD_ERROR_SYNC = 0x4f,
|
||||
|
||||
MAD_ERROR_DSPBUSY = 0x50,
|
||||
|
||||
MAD_ERROR_FRLEN_OVFLOW = 0x60,
|
||||
MAD_ERROR_DEODE_ELSE_ERR = 0x61,
|
||||
BT_AAC_NODATA_OR_FRLEN_ERR = 0x62,
|
||||
|
||||
DECODER_ERR_OUT_SPACE = 0x80,
|
||||
DECODER_ERR_UNFINISH,
|
||||
};
|
||||
|
||||
|
||||
//通用解码器api
|
||||
struct if_decoder_io {
|
||||
void *priv ;
|
||||
int (*input)(void *priv, u32 addr, void *buf, int len, u8 type);
|
||||
/*
|
||||
priv -- 私有结构体,由初始化函数提供。
|
||||
addr -- 文件位置
|
||||
buf -- 读入地址
|
||||
len -- 读入长度 512 的整数倍
|
||||
type -- 0 --同步读(等到数据读回来,函数才返回) ,1 -- 异步读(不等数据读回来,函数就放回)
|
||||
|
||||
*/
|
||||
int (*check_buf)(void *priv, u32 addr, void *buf);
|
||||
int (*output)(void *priv, void *data, int len);
|
||||
u32(*get_lslen)(void *priv);
|
||||
u32(*store_rev_data)(void *priv, u32 addr, int len);
|
||||
int (*input_fr)(void *priv, void **buf);
|
||||
};
|
||||
|
||||
typedef struct if_decoder_io IF_DECODER_IO;
|
||||
|
||||
typedef struct __audio_decoder_ops {
|
||||
char *name; ///< 解码器名称
|
||||
u32(*open)(void *work_buf, void *stk_buf, const struct if_decoder_io *decoder_io, u8 *bk_point_ptr, void *dci); ///<打开解码器
|
||||
|
||||
u32(*format_check)(void *work_buf, void *stk_buf); ///<格式检查
|
||||
|
||||
u32(*run)(void *work_buf, u32 type, void *stk_buf); ///<主循环
|
||||
|
||||
dec_inf_t *(*get_dec_inf)(void *work_buf); ///<获取解码信息
|
||||
u32(*get_playtime)(void *work_buf); ///<获取播放时间
|
||||
u32(*get_bp_inf)(void *work_buf); ///<获取断点信息;返回断点信息存放的地址
|
||||
|
||||
//u32 (*need_workbuf_size)() ; ///<获取整个解码所需的buffer
|
||||
u32(*need_dcbuf_size)(void *dci); ///<获取解码需要的buffer
|
||||
u32(*need_skbuf_size)(void *dci); ///<获取解码过程中stack_buf的大小
|
||||
u32(*need_bpbuf_size)(void *dci); ///<获取保存断点信息需要的buffer的长度
|
||||
|
||||
//void (*set_dcbuf)(void* ptr); ///<设置解码buffer
|
||||
//void (*set_bpbuf)(void *work_buf,void* ptr); ///<设置断点保存buffer
|
||||
|
||||
void (*set_step)(void *work_buf, u32 step); ///<设置快进快进步长。
|
||||
void (*set_err_info)(void *work_buf, u32 cmd, u8 *ptr, u32 size); ///<设置解码的错误条件
|
||||
u32(*dec_config)(void *work_buf, u32 cmd, void *parm);
|
||||
} audio_decoder_ops, decoder_ops_t;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef AUDIO_ENCODE_COMMON_API_H
|
||||
#define AUDIO_ENCODE_COMMON_API_H
|
||||
|
||||
#include "cpu.h"
|
||||
|
||||
/*********************** ENC *************************/
|
||||
|
||||
typedef struct _EN_FILE_IO_ {
|
||||
void *priv;
|
||||
u16(*input_data)(void *priv, s16 *buf, u8 channel, u16 len);
|
||||
u32(*output_data)(void *priv, u8 *buf, u16 len);
|
||||
} EN_FILE_IO;
|
||||
|
||||
|
||||
|
||||
typedef struct _ENC_DATA_INFO_ {
|
||||
u16 sr; ///<sample rate
|
||||
u16 br; ///<mp2的时候它是bitrate,但是adpcm的时候,它是blockSize,一般配成256/512/1024/2048,超过2048会被限制成2048
|
||||
u32 nch;
|
||||
u8 bit_width;
|
||||
} ENC_DATA_INFO;
|
||||
|
||||
|
||||
typedef struct _ENC_OPS {
|
||||
u32(*need_buf)(u32 channel);
|
||||
void (*open)(void *ptr, EN_FILE_IO *audioIO);
|
||||
void (*set_info)(void *ptr, ENC_DATA_INFO *data_info);
|
||||
u32(*init)(void *ptr);
|
||||
u32(*run)(void *ptr);
|
||||
u8 *(*write_head)(void *ptr, u16 *len);
|
||||
u32(*get_time)(void *ptr);
|
||||
} ENC_OPS;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef OPUS_CODEC_API_H
|
||||
#define OPUS_CODEC_API_H
|
||||
|
||||
#include "audio_encode_common_api.h"
|
||||
#include "audio_decode_common_api.h"
|
||||
|
||||
|
||||
/******************* ENC *******************/
|
||||
|
||||
typedef struct _OPUS_EN_FILE_IO_ {
|
||||
void *priv;
|
||||
u16(*input_data)(void *priv, s16 *buf, u8 channel, u16 points); //short 2字节一个点.
|
||||
u32(*output_data)(void *priv, u8 *buf, u16 len); //bytes
|
||||
} OPUS_EN_FILE_IO;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************** DEC **********************/
|
||||
typedef struct _OPUS_ENC_PARA_ {
|
||||
int sr; //samplerate: fixed_16000.
|
||||
int br; //bitrate: old:16000/32000/64000. --->new:16000~80000.16~80kbps.
|
||||
u16 nch; //channels fixed_1. 仅支持单声道编码.
|
||||
u16 format_mode; //封装格式: 0:百度无头. 1:酷狗_eng+range. 2:ogg封装,pc软件可播放. 3:size+rangeFinal. 源码可兼容版本.
|
||||
u16 complexity; //0.1.2.3. 3质量最好.速度要求最高.
|
||||
u16 frame_ms; //20|40|60|80|100ms.
|
||||
} OPUS_ENC_PARA;
|
||||
typedef struct __OPUS_ENC_OPS {
|
||||
u32(*need_buf)(OPUS_ENC_PARA *para);
|
||||
u32(*open)(u8 *ptr, OPUS_EN_FILE_IO *audioIO, OPUS_ENC_PARA *para);
|
||||
u32(*run)(u8 *ptr);
|
||||
} OPUS_ENC_OPS;
|
||||
|
||||
extern OPUS_ENC_OPS *get_opus_enc_ops(void);
|
||||
|
||||
|
||||
typedef struct __OPUSLIB_DEC_OPS {
|
||||
u32(*need_buf)(int bitwidth);
|
||||
u32(*open)(u32 *ptr, int br_index, int bitwidth);
|
||||
u32(*run)(u32 *ptr, char *frame_data, short *frame_out);
|
||||
} opuslib_dec_ops;
|
||||
|
||||
typedef struct _BR_CONTEXT_ {
|
||||
int br_index;
|
||||
} BR_CONTEXT;
|
||||
|
||||
|
||||
#define SET_DEC_SR 0x91
|
||||
// ogg_opus 解码设置
|
||||
#define SET_OPUS_RAWDTF 0x90 //设置OPUS 为raw 数据. 带8字节packet头(4字节大端包长+4字节range校验值)
|
||||
#define SET_OPUS_CBR_PKTLEN 0x91 //设置OPUS 为raw 数据 + CBR_OPUS 包长,可能有多帧共用TOC. 返回0设置成功.
|
||||
|
||||
typedef struct _AUDIO_OPUS_PKTLEN {
|
||||
u32 opus_pkt_len; //SET_OPUS_CBR_PKTLEN
|
||||
} AUDIO_OPUS_PKTLEN;
|
||||
|
||||
|
||||
|
||||
extern opuslib_dec_ops *getopuslibdec_ops();
|
||||
|
||||
|
||||
#define OPUS_INDATA_SUPPORT_FILE 1 // 支持文件类型数据
|
||||
|
||||
|
||||
#define OPUS_SR_8000_OUT_POINTS (160)
|
||||
#define OPUS_SR_16000_OUT_POINTS (320)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
*
|
||||
* Bluetooth low-complexity, subband codec (SBC) library
|
||||
*
|
||||
* Copyright (C) 2008-2010 Nokia Corporation
|
||||
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
|
||||
* Copyright (C) 2004-2005 Henryk Ploetz <henryk@ploetzli.ch>
|
||||
* Copyright (C) 2005-2006 Brad Midgley <bmidgley@xmission.com>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __SBC_ENC_H
|
||||
#define __SBC_ENC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//typedef unsigned char uint8 ,u8 ,U8 ,uint8_t;
|
||||
//typedef unsigned short int uint16 ,UINT16 ,U16 ,u16 ,uint16_t;
|
||||
//typedef unsigned int uint32 ,UINT32,U32 ,u32 ,uint32_t ,uintptr_t;
|
||||
//typedef signed char sint8 ,s8 ,S8,int8 ,int8_t;
|
||||
//typedef signed short int sint16 ,SINT16 ,S16 ,s16,int16,INT16,int16_t ;
|
||||
//typedef signed int sint32 ,SINT32,S32 ,s32,int32 ,INT32;//,;
|
||||
//typedef unsigned int size_t,ssize_t;
|
||||
//typedef int int32_t ;
|
||||
//typedef unsigned __int64 int64_t;
|
||||
//typedef __int64 uint64_t ;
|
||||
|
||||
|
||||
//#include "typedef.h"
|
||||
//#include <stdint.h>
|
||||
//#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
#ifndef __GNUC__
|
||||
#define SBC_ENCODE
|
||||
#endif
|
||||
/* sampling frequency */
|
||||
#define SBC_FREQ_16000 0x00
|
||||
#define SBC_FREQ_32000 0x01
|
||||
#define SBC_FREQ_44100 0x02
|
||||
#define SBC_FREQ_48000 0x03
|
||||
|
||||
|
||||
/* blocks */
|
||||
#define SBC_BLK_4 0x00
|
||||
#define SBC_BLK_8 0x01
|
||||
#define SBC_BLK_12 0x02
|
||||
#define SBC_BLK_16 0x03
|
||||
|
||||
/* channel mode */
|
||||
#define SBC_MODE_MONO 0x00
|
||||
#define SBC_MODE_DUAL_CHANNEL 0x01
|
||||
#define SBC_MODE_STEREO 0x02
|
||||
#define SBC_MODE_JOINT_STEREO 0x03
|
||||
|
||||
/* allocation method */
|
||||
#define SBC_AM_LOUDNESS 0x00
|
||||
#define SBC_AM_SNR 0x01
|
||||
|
||||
/* subbands */
|
||||
#define SBC_SB_4 0x00
|
||||
#define SBC_SB_8 0x01
|
||||
|
||||
/* Data endianness */
|
||||
#define SBC_LE 0x00
|
||||
#define SBC_BE 0x01
|
||||
|
||||
typedef struct sbc_struct {
|
||||
unsigned int flags;
|
||||
|
||||
unsigned char frequency;
|
||||
unsigned char blocks;
|
||||
unsigned char subbands;
|
||||
unsigned char mode;
|
||||
unsigned char allocation;
|
||||
unsigned char bitpool;
|
||||
unsigned char endian;
|
||||
|
||||
void *priv;
|
||||
void *priv_alloc_base;
|
||||
} sbc_t;
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned int sbc_enc_query(void);
|
||||
int sbc_init(sbc_t *sbc, unsigned long flags, void *priv);
|
||||
int sbc_reinit(sbc_t *sbc, unsigned long flags);
|
||||
|
||||
unsigned int sbc_parse(sbc_t *sbc, const void *input, size_t input_len);
|
||||
|
||||
/* Decodes ONE input block into ONE output block */
|
||||
unsigned int sbc_decode(sbc_t *sbc, const void *input, size_t input_len,
|
||||
void *output, size_t output_len, size_t *written);
|
||||
|
||||
/* Encodes ONE input block into ONE output block */
|
||||
unsigned int sbc_encode(sbc_t *sbc, const void *input, size_t input_len,
|
||||
void *output, size_t output_len, unsigned int *written);
|
||||
|
||||
/* Returns the output block size in bytes */
|
||||
//size_t sbc_get_frame_length(sbc_t *sbc);
|
||||
|
||||
/* Returns the time one input/output block takes to play in msec*/
|
||||
unsigned sbc_get_frame_duration(sbc_t *sbc);
|
||||
|
||||
/* Returns the input block size in bytes */
|
||||
//size_t sbc_get_codesize(sbc_t *sbc);
|
||||
|
||||
const char *sbc_get_implementation_info(sbc_t *sbc);
|
||||
void sbc_finish(sbc_t *sbc);
|
||||
//#define htons(x) ( ( (((unsigned short)(x)) >>8) & 0xff) | ((((unsigned short)(x)) & 0xff)<<8) )
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
struct option {
|
||||
const char *name;
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
|
||||
#endif /* __SBC_ENC_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user