silk mpu
#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的更多相关文章
- mpu
#include "mpu.h" #include "mem.h" #include "my_errno.h" #include " ...
- silk与opencore-amr音频编码对比
silk与opencore-amr编码对比 在采样率8000 单声道 16位采样精度情况下 silk的压缩率为 1/15 opencore-amr 1/17 对比图 原始的音频编码 opencore- ...
- CPU MPU MCU SOC SOPC关系及区别
在嵌入式开过程,会经常接触到一些缩写术语概念,这些概念在嵌入式行业中使用率非常高,下面我们就解释一下这些概念之间的关系和区别: 1.CPU(Central Processing Unit),是一台计算 ...
- CPU,MPU,MCU,SOC,SOPC联系与差别
转自CPU,MPU,MCU,SOC,SOPC联系与差别 1.CPU(Central Processing Unit),是一台计算机的运算核心和控制核心.CPU由运算器.控制器和寄存器及实现它们之间联系 ...
- Silk Mobile – 缩短移动应用的测试周期
Micro Focus已将从Borland接管的Silk Mobile™投放到市场,作为一种新的强大的移动应用测试解决方案,它将使企业能够开发出更先进更可靠的移动商业软件. 作为市场上最完整的移动应用 ...
- 小程序API录音后Silk格式转码MP3
问题 客户端使用小程序,需要录音功能然后到后台页面播放,由于微信提供的录音API压缩后的格式为 .silk格式的,但是这个格式其他播放器都是播放不了的,更何况html页面的audio标签更是不可能播放 ...
- 微信小程序语音识别服务搭建全过程解析(https api开放,支持新接口mp3录音、老接口silk录音)
silk v3(或新录音接口mp3)录音转olami语音识别和语义处理的api服务(ubuntu16.04服务器上实现) 重要的写在前面 重要事项一: 所有相关更新,我优先更新到我个人博客中,其它地方 ...
- 微信小程序语音识别开发过程记录 微信小程序silk转mp3 silk转wav 以及ffmpeg使用
说说最近在开发微信小程序语音识别遇到的问题吧 最先使用微信小程序录音控件可以拿到silk格式,后来微信官方又支持mp3格式了 但是我们拿到这些格式以后,都还不能直接使用,做语音识别,因为目前百度的语音 ...
- 小程序语音红包中遇到的 语音识别silk转wav格式 如何在线转 或者mp3转wav格式
公司在开发一个小程序语音红包,现在遇到的问题就是通过微信的小程序文档接口拿到的录音文件要么是silk格式的,要么是mp3格式的 但是呢,如果要调用百度的语音接口,又必须是wav格式的.也就是说通过微信 ...
随机推荐
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C
Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...
- windows下的c语言和linux 下的c语言以及C标准库和系统API
1.引出我们的问题? 标准c库都是一样的!大家想必都在windows下做过文件编程,在linux下也是一样的函数名,参数都一样.当时就有了疑问,因为我们非常清楚 其本质是不可能一样的,源于这是俩个操作 ...
- .net面试题集锦
1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. protected : 保护成 ...
- .NET蓝牙开源库:32feet.NET
在用C#调用蓝牙编程一文中我留个小悬念就是:InTheHand.Net.Personal.dll是怎么来的?这篇文章来解答这个问题,InTheHand.Net.Personal.dll就是来源于今天要 ...
- 微信小程序-表单
wxml <view> 按钮: <button size="{{buttom.size}}" type="{{buttom.type}}" p ...
- JavaScript数组类型
特点 动态长度 一个数组里面的元素可以是不同类型 数组的length属性不是只读属性,可通过length延长数组也可以删减数组的长度 定义数组两种方法 //方法一: var names = new A ...
- NuGet安装及使用教程
Nuget是一个.NET平台下的开源的项目,它是Visual Studio的扩展.在使用Visual Studio开发基于.NET Framework的应用时,Nuget能把在项目中添加.移除和更新引 ...
- Lua热更系统
1.介绍 使用脚本开发游戏业务逻辑其中一个好处就是代码可线上热更,不停机修复bug.而热更代码的写法与需要被热更的文件的代码又有着密切的关系,本文介绍一种热更方法. 2.热更原理 Lua提供一个叫re ...
- jquery总结06-动画事件01-基础显示和隐藏
动画事件 .hide(option) 动画隐藏 会保存元素的原始属性值 $("#a2").hide({ duration: 3000, complete: function() ...
- localhost访问错误Forbidden You don't have permission to access / on this server.解决办法(亲测)
在httpd.conf文件下找到这段: <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow D ...