【蓝牙sbc协议】sbc源码阅读笔记(二)——sbc_struct详解(下)
sbc_struct结构详解
*priv、*priv_alloc_base
priv指针与priv_alloc_base指针。
在初始化过程sbc_init(&sbc, 0L)
中,给两个指针分配空间:
/* sbc.c */
// sbc
SBC_EXPORT int sbc_init(sbc_t *sbc, unsigned long flags)
{if (!sbc)return -EIO;memset(sbc, 0, sizeof(sbc_t));// struct sbc_priv 见下方sbc->priv_alloc_base = malloc(sizeof(struct sbc_priv) + SBC_ALIGN_MASK);if (!sbc->priv_alloc_base)return -ENOMEM;// typedef unsigned long uintptr_t;// m&~n 为m/n所剩余数据的起始位置// SBC_ALIGN_MASK 为15sbc->priv = (void *) (((uintptr_t) sbc->priv_alloc_base +SBC_ALIGN_MASK) & ~((uintptr_t) SBC_ALIGN_MASK));memset(sbc->priv, 0, sizeof(struct sbc_priv));sbc_set_defaults(sbc, flags);return 0;
}
SBC_ALIGN_MASK
:
/* sbc_tables.h */ /** Enforce 16 byte alignment for the data, which is supposed to be used* with SIMD optimized code.*/#define SBC_ALIGN_BITS 4 #define SBC_ALIGN_MASK ((1 << (SBC_ALIGN_BITS)) - 1)#ifdef __GNUC__ #define SBC_ALIGNED __attribute__((aligned(1 << (SBC_ALIGN_BITS)))) #else #define SBC_ALIGNED #endif
sbc_priv
的定义:
/* sbc.c */ // 各个属性详细信息见下方 struct sbc_priv {bool init;bool msbc;struct SBC_ALIGNED sbc_frame frame;struct SBC_ALIGNED sbc_decoder_state dec_state;struct SBC_ALIGNED sbc_encoder_state enc_state; // 两个函数指针int (*unpack_frame)(const uint8_t *data, struct sbc_frame *frame,size_t len);ssize_t (*pack_frame)(uint8_t *data, struct sbc_frame *frame,size_t len, int joint); };
// sbc_frame /* This structure contains an unpacked SBC frame.Yes, there is probably quite some unused space herein */ struct sbc_frame {uint8_t frequency;uint8_t block_mode;uint8_t blocks;enum {MONO = SBC_MODE_MONO,DUAL_CHANNEL = SBC_MODE_DUAL_CHANNEL,STEREO = SBC_MODE_STEREO,JOINT_STEREO = SBC_MODE_JOINT_STEREO} mode;uint8_t channels;enum {LOUDNESS = SBC_AM_LOUDNESS,SNR = SBC_AM_SNR} allocation;uint8_t subband_mode;uint8_t subbands;uint8_t bitpool;uint16_t codesize;uint16_t length;/* bit number x set means joint stereo has been used in subband x */uint8_t joint;/* only the lower 4 bits of every element are to be used */uint32_t SBC_ALIGNED scale_factor[2][8];/* raw integer subband samples in the frame */int32_t SBC_ALIGNED sb_sample_f[16][2][8];/* modified subband samples */int32_t SBC_ALIGNED sb_sample[16][2][8];/* original pcm audio samples */int16_t SBC_ALIGNED pcm_sample[2][16*8]; };
// sbc_decoder_state struct sbc_decoder_state {int subbands;int32_t V[2][170];int offset[2][16]; };
// sbc_encoder_state struct sbc_encoder_state {int position;// 编码器处理的连续块数/* Number of consecutive blocks handled by the encoder */uint8_t increment;int16_t SBC_ALIGNED X[2][SBC_X_BUFFER_SIZE];// 4子带多项滤波器/* Polyphase analysis filter for 4 subbands configuration,* it handles "increment" blocks at once */void (*sbc_analyze_4s)(struct sbc_encoder_state *state,int16_t *x, int32_t *out, int out_stride);// 8子带多项滤波器/* Polyphase analysis filter for 8 subbands configuration,* it handles "increment" blocks at once */void (*sbc_analyze_8s)(struct sbc_encoder_state *state,int16_t *x, int32_t *out, int out_stride);// 根据子带数量和输入数据字节顺序,处理输入数据(逐行扫描、尾数转换、重新排序)/* Process input data (deinterleave, endian conversion, reordering),* depending on the number of subbands and input data byte order */int (*sbc_enc_process_input_4s_le)(int position,const uint8_t *pcm, int16_t X[2][SBC_X_BUFFER_SIZE],int nsamples, int nchannels);int (*sbc_enc_process_input_4s_be)(int position,const uint8_t *pcm, int16_t X[2][SBC_X_BUFFER_SIZE],int nsamples, int nchannels);int (*sbc_enc_process_input_8s_le)(int position,const uint8_t *pcm, int16_t X[2][SBC_X_BUFFER_SIZE],int nsamples, int nchannels);int (*sbc_enc_process_input_8s_be)(int position,const uint8_t *pcm, int16_t X[2][SBC_X_BUFFER_SIZE],int nsamples, int nchannels);// 计算比例因子/* Scale factors calculation */void (*sbc_calc_scalefactors)(int32_t sb_sample_f[16][2][8],uint32_t scale_factor[2][8],int blocks, int channels, int subbands);// 联合立体声的比例因子计算/* Scale factors calculation with joint stereo support */int (*sbc_calc_scalefactors_j)(int32_t sb_sample_f[16][2][8],uint32_t scale_factor[2][8],int blocks, int subbands);const char *implementation_info; };
// unpack_frame、pack_frame static void sbc_set_defaults(sbc_t *sbc, unsigned long flags) {···if (priv->msbc) {priv->pack_frame = msbc_pack_frame;priv->unpack_frame = msbc_unpack_frame;} else {priv->pack_frame = sbc_pack_frame;priv->unpack_frame = sbc_unpack_frame;}··· }
以上完成了两个指针的初始化。
待补充内容:
- 数据写入过程
【蓝牙sbc协议】sbc源码阅读笔记(二)——sbc_struct详解(下)相关推荐
- werkzeug源码阅读笔记(二) 下
wsgi.py----第二部分 pop_path_info()函数 先测试一下这个函数的作用: >>> from werkzeug.wsgi import pop_path_info ...
- STL源码剖析---红黑树原理详解下
转载请标明出处,原文地址:http://blog.csdn.net/hackbuteer1/article/details/7760584 算法导论书上给出的红黑树的性质如下,跟STL源码 ...
- tidb mysql 协议_TiDB源码阅读(二) TiDB中的MySQL协议
当 SQL 通过上一篇所描述的路径来到这里, dispatch 这个函数如它的名字一样,对不同类型的 SQL 语句 case 到不同的函数中,那咱们来看看这个函数吧,在这里: server/conn. ...
- ThreadPoolExecutor源码阅读笔记(二)FutureTask
BlockingQueue: 队列他决定了任务的调度方式,我们主要关注BlockingQueue的offer, poll,take三个方法 offer往队列里面添加任务如果队列已经满了话返回false ...
- [Linux] USB-Storage驱动 源码阅读笔记(一)
USB-Storage驱动 源码阅读笔记--从USB子系统开始 最近在研究U盘的驱动,遇到很多难以理解的问题,虽然之前也参考过一些很不错的书籍如:<USB那些事>,但最终还是觉得下载一份最 ...
- Transformers包tokenizer.encode()方法源码阅读笔记
Transformers包tokenizer.encode()方法源码阅读笔记_天才小呵呵的博客-CSDN博客_tokenizer.encode
- 源码阅读笔记 BiLSTM+CRF做NER任务 流程图
源码阅读笔记 BiLSTM+CRF做NER任务(二) 源码地址:https://github.com/ZhixiuYe/NER-pytorch 本篇正式进入源码的阅读,按照流程顺序,一一解剖. 一.流 ...
- 代码分析:NASM源码阅读笔记
NASM源码阅读笔记 NASM(Netwide Assembler)的使用文档和代码间的注释相当齐全,这给阅读源码 提供了很大的方便.按作者的说法,这是一个模块化的,可重用的x86汇编器, 而且能够被 ...
- CI框架源码阅读笔记4 引导文件CodeIgniter.php
到了这里,终于进入CI框架的核心了.既然是"引导"文件,那么就是对用户的请求.参数等做相应的导向,让用户请求和数据流按照正确的线路各就各位.例如,用户的请求url: http:// ...
- Yii源码阅读笔记 - 日志组件
2015-03-09 一 By youngsterxyf 使用 Yii框架为开发者提供两个静态方法进行日志记录: Yii::log($message, $level, $category); Yii: ...
最新文章
- MySql5.7环境搭建
- linux命令之cpio
- php Reportico 开源报表
- CentOS 安装与优化
- Java 关键字 transient
- 内存spd规范_C语言内存泄露很严重,如何应对?
- 敏捷开发之团队级经验分享
- 在设计DJANGO用户更改密码时,出现NoReverseMatch at /account/password-change/这种妖精如何办?...
- mysql (mariadb)数据库使用 mysqldump 备份全部数据库,并自动按当前时间名保存文件
- 土耳其央行行长当得不容易 | 经济学人早报精选
- python dict.get 用法
- 关于深拷贝与浅拷贝的问题?
- oracle怎么看今天星期几,oracle 判断今天是星期几
- mysql弱口令加强,Mysql弱口令取得系统权限(续)
- 数字图像处理(MATLAB版)学习笔记(1)——第1章 绪言
- P1719 最大加权矩形(最大连续子段和+矩形二维降一维+前缀和)
- 周易哲学(一):干支纪年法和四柱八字
- Windows显示与隐藏文件扩展名
- git删除本地代码库文件后同步到远程仓库同时删除远程仓库文件
- 高德地图覆盖物改为闪烁点样式