#include "mpu.h"
#include "mbuf.h"
#include "media_buffer.h"
#include "my_errno.h"
#include "mem.h"
#include "silk.h"
#include "interface/SKP_Silk_SDK_API.h" struct silk_codec {
void* obj;
SKP_SILK_SDK_DecControlStruct control;
uint64_t seq[2], pts; audio_format* fmt_out;
intptr_t mbuf_handle;
uint32_t bytes;
}; static void* silk_open(fourcc** in, fourcc** out)
{
SKP_int32 size;
SKP_int n = SKP_Silk_SDK_Get_Decoder_Size(&size);
if (n != 0) {
errno = EFAULT;
return NULL;
} struct silk_codec* codec = (struct silk_codec *) my_malloc(size + sizeof(struct silk_codec));
if (codec == NULL) {
errno = ENOMEM;
return NULL;
}
codec->obj = (void *) (codec + 1); n = SKP_Silk_SDK_InitDecoder(codec->obj);
if (n != 0) {
my_free(codec);
errno = EFAULT;
return NULL;
} codec->seq[0] = codec->seq[1] = codec->pts = 0;
codec->fmt_out = to_audio_format(out);
codec->control.API_sampleRate = codec->fmt_out->pcm->samrate;
fraction frac = pcm_bytes_from_ms(codec->fmt_out->pcm, 1);
codec->bytes = silk_mpf * frac.num / frac.den;
codec->mbuf_handle = mbuf_hget(sizeof(media_buffer) + codec->bytes, 8, 1);
return codec;
} static struct my_buffer* pcm_buffer_alloc(struct my_buffer* mbuf,
uint32_t ms, media_buffer* stream, struct silk_codec* codec)
{
if (mbuf == NULL) {
if (__builtin_expect(codec->mbuf_handle == -1, 0)) {
uint32_t bytes = sizeof(media_buffer) + codec->bytes;
codec->mbuf_handle = mbuf_hget(bytes, 8, 1);
if (codec->mbuf_handle == -1) {
mbuf = mbuf_alloc_2(bytes);
}
} else {
mbuf = mbuf_alloc_1(codec->mbuf_handle);
} if (mbuf == NULL) {
return NULL;
}
mbuf->length = codec->bytes;
mbuf->ptr[1] = mbuf->ptr[0] + sizeof(media_buffer);
} media_buffer* media = (media_buffer *) mbuf->ptr[0];
memset(media->vp, 0, sizeof(media->vp));
media->frametype = 0;
media->angle = 0;
media->fragment[0] = 0;
media->fragment[1] = 1;
media->pptr_cc = &codec->fmt_out->cc;
media->pts = stream->pts + ms;
media->iden = stream->iden;
media->seq = codec->seq[0]++;
media->vp[0].ptr = mbuf->ptr[1];
media->vp[0].stride = (uint32_t) mbuf->length;
media->vp[0].height = 1;
return mbuf;
} static uint32_t silk_muted(struct my_buffer* mbuf, uint32_t bytes)
{
uintptr_t nb = mbuf->length;
mbuf->length = bytes;
uint32_t muted = silk_frame_muted(mbuf);
mbuf->length = nb;
return muted;
} static int32_t conceal_lost(media_buffer* stream, struct silk_codec* codec, struct list_head* head)
{
int32_t nr = (int32_t) (stream->seq - codec->seq[1]);
if (codec->seq[1] == 0 || __builtin_expect(nr <= 0 || nr > 24, 1)) {
return 0;
} SKP_int16 nr_samples;
uint64_t pts = stream->pts;
stream->pts = codec->pts;
uint32_t ms = 0, bytes = 0; for (int32_t i = 0; i < nr; ++i) {
struct my_buffer* buffer = pcm_buffer_alloc(NULL, ms, stream, codec);
if (buffer == NULL) {
break;
} SKP_Silk_SDK_Decode(codec->obj, &codec->control, 1,
NULL, 0, (SKP_int16 *) buffer->ptr[1], &nr_samples);
my_assert(nr_samples * 2 == buffer->length);
bytes += buffer->length;
list_add_tail(&buffer->head, head);
ms += silk_mpf;
} stream->pts = pts;
return bytes;
} static int32_t silk_write(void* handle, struct my_buffer* mbuf, struct list_head* head, int32_t* delay)
{
(void) delay;
if (__builtin_expect(mbuf == NULL, 0)) {
return 0;
} struct silk_codec* codec = (struct silk_codec *) handle;
media_buffer* stream = (media_buffer *) mbuf->ptr[0];
uint32_t ms = 0;
SKP_int16 nr_samples;
int32_t bytes = conceal_lost(stream, codec, head); while (mbuf->length > 0) {
struct my_buffer* buffer = NULL;
uint32_t muted = silk_muted(mbuf, silk_frame_leading); uint16_t len = silk_read_frame_bytes(mbuf->ptr[1]);
mbuf->ptr[1] += silk_frame_leading;
if (muted) {
buffer = codec->fmt_out->ops->muted_frame_get(codec->fmt_out, silk_mpf);
if (__builtin_expect(buffer != NULL, 1)) {
my_assert(buffer->length == codec->bytes);
bytes += buffer->length; buffer = pcm_buffer_alloc(buffer, ms, stream, codec);
list_add_tail(&buffer->head, head);
}
} else {
buffer = pcm_buffer_alloc(buffer, ms, stream, codec);
if (__builtin_expect(buffer != NULL, 1)) {
SKP_Silk_SDK_Decode(codec->obj, &codec->control, 0,
(const SKP_uint8 *) mbuf->ptr[1], (const SKP_int) len,
(SKP_int16 *) buffer->ptr[1], &nr_samples);
bytes += nr_samples * 2;
list_add_tail(&buffer->head, head);
}
} mbuf->ptr[1] += len;
mbuf->length -= (len + silk_frame_leading);
ms += silk_mpf;
} codec->seq[1] = stream->seq + 1;
codec->pts = stream->pts + ms;
my_assert(mbuf->length == 0);
mbuf->mop->free(mbuf);
return bytes;
} static void silk_close(void* handle)
{
struct silk_codec* codec = (struct silk_codec *) handle;
if (codec->mbuf_handle != -1) {
mbuf_reap(codec->mbuf_handle);
}
my_free(codec);
} static mpu_operation silk_ops = {
silk_open,
silk_write,
silk_close
}; media_process_unit silk_dec_16k16b1 = {
&silk_16k16b1.cc,
&pcm_16k16b1.cc,
&silk_ops,
1,
mpu_decoder,
"silk_dec_16k16b1"
}; media_process_unit silk_dec_8k16b1 = {
&silk_8k16b1.cc,
&pcm_8k16b1.cc,
&silk_ops,
1,
mpu_decoder,
"silk_dec_8k16b1"
};

silk mpu的更多相关文章

  1. mpu

    #include "mpu.h" #include "mem.h" #include "my_errno.h" #include " ...

  2. silk与opencore-amr音频编码对比

    silk与opencore-amr编码对比 在采样率8000 单声道 16位采样精度情况下 silk的压缩率为 1/15 opencore-amr 1/17 对比图 原始的音频编码 opencore- ...

  3. CPU MPU MCU SOC SOPC关系及区别

    在嵌入式开过程,会经常接触到一些缩写术语概念,这些概念在嵌入式行业中使用率非常高,下面我们就解释一下这些概念之间的关系和区别: 1.CPU(Central Processing Unit),是一台计算 ...

  4. CPU,MPU,MCU,SOC,SOPC联系与差别

    转自CPU,MPU,MCU,SOC,SOPC联系与差别 1.CPU(Central Processing Unit),是一台计算机的运算核心和控制核心.CPU由运算器.控制器和寄存器及实现它们之间联系 ...

  5. Silk Mobile – 缩短移动应用的测试周期

    Micro Focus已将从Borland接管的Silk Mobile™投放到市场,作为一种新的强大的移动应用测试解决方案,它将使企业能够开发出更先进更可靠的移动商业软件. 作为市场上最完整的移动应用 ...

  6. 小程序API录音后Silk格式转码MP3

    问题 客户端使用小程序,需要录音功能然后到后台页面播放,由于微信提供的录音API压缩后的格式为 .silk格式的,但是这个格式其他播放器都是播放不了的,更何况html页面的audio标签更是不可能播放 ...

  7. 微信小程序语音识别服务搭建全过程解析(https api开放,支持新接口mp3录音、老接口silk录音)

    silk v3(或新录音接口mp3)录音转olami语音识别和语义处理的api服务(ubuntu16.04服务器上实现) 重要的写在前面 重要事项一: 所有相关更新,我优先更新到我个人博客中,其它地方 ...

  8. 微信小程序语音识别开发过程记录 微信小程序silk转mp3 silk转wav 以及ffmpeg使用

    说说最近在开发微信小程序语音识别遇到的问题吧 最先使用微信小程序录音控件可以拿到silk格式,后来微信官方又支持mp3格式了 但是我们拿到这些格式以后,都还不能直接使用,做语音识别,因为目前百度的语音 ...

  9. 小程序语音红包中遇到的 语音识别silk转wav格式 如何在线转 或者mp3转wav格式

    公司在开发一个小程序语音红包,现在遇到的问题就是通过微信的小程序文档接口拿到的录音文件要么是silk格式的,要么是mp3格式的 但是呢,如果要调用百度的语音接口,又必须是wav格式的.也就是说通过微信 ...

随机推荐

  1. javascirpt对象运用与JS变量

    abcdefghijklmnopqrstuvwyz String 对象方法 charAt() 方法可返回指定位置的字符.stringObject.charAt(index)(index从0开始)[ht ...

  2. log4j日志配置

    #debug#日志权限配置log4j.rootLogger=info,error,stdout#控制台输出log4j.appender.stdout=org.apache.log4j.ConsoleA ...

  3. FTP命令

    linux下常用FTP命令 1. 连接ftp服务器   1. 连接ftp服务器 格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1 ...

  4. FPGA重要设计思想

    FPGA重要设计思想   1.速度和面积互换原则.以面积换速度可以实现很高的数据吞吐率,其实串/并转换.就是一种以面积换速度的思想 2.乒乓操作. 3.串/并转换的思想. 高速数据处理的重要技巧之一. ...

  5. 第三天的学习知识HTML5常用的重要单词

    a:   a:猫     address:地址     alt:替用(一般是图片显示不出的提示) b:   b:粗体     br:换行     background:背景     border:边框 ...

  6. Ext5实现树形下拉框ComboBoxTree

    最近为了实现一个属性下拉框被Ext框架折腾了好几天.. 所以,首先要说的是,不管你要做什么系统.强烈建议你不要选择Ext.据我这几天的搜索,应该这个框架现在用的人也很少了. Ext框架的缺陷:框架沉重 ...

  7. CSS 选择器

    1.  .   ==> class选择器 2.  #  ==> id选择器 3.  *  ==>选择所有元素 4.<p>  ==>选择所有<p>标签的元 ...

  8. Maven 配置 Selenium + testNG + reportNG 运行环境

    .markdown-preview:not([data-use-github-style]) { padding: 2em; font-size: 1.2em; color: rgb(56, 58, ...

  9. The integer promotion.

    Usual Arithmetic Conversion: The integer promotions are performed on both operands. Then the followi ...

  10. jquery ajax的error错误信息

    项目开发中ajax的异常处理起来算是比较头疼的,因为是异步请求,所以即使ajax异常程序依然会继续执行,导致找ajax的异常比较麻烦. 今天处理ajax异常时搜到一篇文章,提到error可以返回aja ...