虽然都是linux,芯片也是基于同样的架构,同样的指令集,但是考虑到芯片的实现毕竟是不同的,于是所有涉及到硬件交互的软件部分,也会有所差异,最终会导致了有些应用层面的接口,不能按照普通linux的通常用法去使用。
项目主页下载地址:https://www.alsa-project.org/wiki/Main_Page
音频信号是一种连续变化的模拟信号,但计算机只能处理和记录二进制的数字信号,由自然音源得到的音频信号必须经过一定的变换,成为数字音频信号之后,才能送到计算机中作进一步的处理。
如果是在其他发行版linux系统上或者需要在嵌入式linux系统上使用alsa-lib库,可以下载alsa-lib源码包,自行编译。
ALSA(Advanced Linux Sound Architecture)是linux上主流的音频结构,在没有出现ALSA架构之前,一直使用的是OSS(Open Sound System)音频架构。关于OSS的退出以及ALSA的出现,可以看 Linux音频驱动-OSS和ALSA声音系统简介及其比较。
参考文章: https://blog.csdn.net/xiaolong1126626497/article/details/104916277
Allwinner 硬件平台R6, R7s, R11, R16, R18, R30, R58, R328, R332, R333, R311, MR133, T7, R329, MR813, R818, R818B, R528, H133, V853, F133。
采样就是把模拟信号数字化的过程,不仅仅是音频需要采样,所有的模拟信号都需要通过采样转换为可以用0101来表示的数字信号,示意图如下所示:
我们知道,asoc框架里面主要包含machine codec platform 这三大部分:
PCM是英文Pulse-code modulation的缩写,中文译名是脉冲编码调制。我们知道在现实生活中,人耳听到的声音是模拟信号,PCM就是要把声音从模拟转换成数字信号的一种技术,他的原理简单地说就是利用一个固定的频率对模拟信号进行采样,采样后的信号在波形上看就像一串连续的幅值不一的脉冲,把这些脉冲的幅值按一定的精度进行量化,这些量化后的数值被连续地输出、传输、处理或记录到存储介质中,所有这些组成了数字音频的产生过程。
ASoC--ALSA System on Chip ,是建立在标准ALSA驱动层上,为了更好地支持嵌入式处理器和移动设备中的音频Codec的一套软件体系。在ASoc出现之前,内核对于SoC中的音频已经有部分的支持,不过会有一些局限性:
随着汽车工业的飞速发展和智能化技术的不断突破,车载导航系统作为现代汽车不可或缺的一部分,在人们的日常生活中扮演着越来越重要的角色。它不仅能够提供精确的路线导航,还能提供丰富的地理信息和娱乐服务,为驾驶者带来了极大的便利和乐趣。
针对音箱日常工作项目开展的前期,需要快速的适配音频子模块,方便项目的声学评估和开展,期间遇到不少的问题,其中有一些细节往往会忽略掉,然而正好是问题的所在。在此背景下,遇到问题一步一步梳理,方便快速的定位出问题所在 。
在ASOC在Platform部分,主要是平台相关的DMA操作和音频管理。大概流程先将音频数据从内存通过DMA方式传输到CPU侧的dai接口,然后通过CPU的dai接口(通过I2S总线)将数据从达到Codec中,数据会在Codec侧会解码的操作,最终输出到耳机/音箱中。依然已下图作为参考:
/*modify by hfl 2014-2-16*/ /* Use the newer ALSA API */ #define ALSA_PCM_NEW_HW_PARAMS_API #include <alsa/asoundlib.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> int main(int argc, char *argv[]) { long loops; int rc; int size; snd_pcm_t *handle; snd_pcm_hw_params_t *params; unsigned int val; int dir; snd_pcm_uframes_t frames; printf("222133\n"); char buffer[20*2];/*size=frame*channles*byte persaple*/ int fd,i; if (argc != 2) { fprintf (stderr, "usage: %s <filename>!\n", argv[0]); exit ( -1 ) ; } if ( ( fd = open (argv[1],O_RDONLY))<0) { fprintf ( stderr, " Can't open sound file!\n"); exit (-1 ); } /* Open PCM device for playback. */ rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); if (rc < 0) { fprintf(stderr, "unable to open pcm device: %s\n", snd_strerror(rc)); exit(1); } /* Allocate a hardware parameters object. */ snd_pcm_hw_params_alloca(¶ms); /* Fill it in with default values. */ snd_pcm_hw_params_any(handle, params); /* Set the desired hardware parameters. */ /* Interleaved mode */ snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); /* Signed 16-bit little-endian format */ snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE); /* Two channels (stereo) */ snd_pcm_hw_params_set_channels(handle, params, 1); /* 44100 bits/second sampling rate (CD quality) */ val = 16000; snd_pcm_hw_params_set_rate_near(handle, params, &val, &dir); /* Set period size to 32 frames. */ frames =20;/*一次送人的帧太少,会下溢冲(至少15帧)*/ // snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir); /* Write the parameters to the driver */ rc = snd_pc
ALSA由许多声卡的声卡驱动程序组成,同时它也提供一个称为libasound的API库。
使用ffmpeg实现一个播放器?是不是没什么新意,不过一直使用ffmpeg程序,还没有用ffmpeg代码接口实现播放器,并且还需要使用linux的alsa接口播放出声音,所以做出来还是觉得有点意思;
3、和PCM相比,I2S更适合立体声系统。当然,I2S的变体也支持多通道的时分复用,因此可以支持多声道。
在ASOC小节中描述了整个ASOC的架构,其中Machine是ASOC架构中的关键部件,没有Machine部件,单独的Codec和Platform是无法工作的。因此本节则先从Machine部分开始,那应该如何开始呢? 答案当然是从代码入手,先进入ASOC在kernel中的位置: kernel/sound/soc下
项目Github地址:https://github.com/alsa-project/alsa-lib
项目开发过程中,由于Broadcom平台音频数字接口比较少,所以采用模拟麦克风作为输入端,经顺芯ES7210 ADC 转换送至Broadcom PCM 数字音频接口。
产品: 硬件:主控 + audio +tp9930 软件:tina + audio/ai 其他:客户需要调试6路mic,其中2路为v853内部audio codec mic,四路为tp9930 外部i2s mic,且其中一路audio mic与lineout硬件相连,作为aec回声消除。
行车记录这个设备相信大家应该都不陌生,它的功能主要是记录车辆行驶途中的影像及声音。
1 OSS(Open Sound System)是unix平台上一个统一的音频接口。
pcm(Pulse-code modulation)脉冲编码调制,是将模拟信号转化为数字信号的一种方法。声音的转化的过程为,先对连续的模拟信号按照固定频率周期性采样,将采样到的数据按照一定的精度进行量化,量化后的信号和采样后的信号差值叫做量化误差,将量化后的数据进行最后的编码存储,最终模拟信号变化为数字信号。
三.交叉编译alsa-lib和alsa-utils (alsa-utils是一系列的音频设备控制工具,而alsa-lib是alsa-utils依赖的库,所以先将alsa-lib编译好)
lsmod命令用于显示已经加载到内核中的模块的状态信息。执行lsmod命令后会列出所有已载入系统的模块。Linux操作系统的核心具有模块化的特性,应此在编译核心时,务须把全部的功能都放入核心。您可以将这些功能编译成一个个单独的模块,待需要时再分别载入。
Control接口主要让用户空间的应用程序(alsa-lib)可以访问和控制音频codec芯片中的多路开关,滑动控件等。对于Mixer(混音)来说,Control接口显得尤为重要,从ALSA 0.9.x版本开始,所有的mixer工作都是通过control接口的API来实现的。
一直在做的一个功能是实现系统内部的SoftWare Loopback, 过程中需要学习ALSA相关的知识,包括驱动 / 应用都需要去了解.而ALSA的官方文档感觉很久没有维护,不怎么好理解,只能边看文档变结合源代码去分析问题.而ALSA这部分从驱动到应用,从原理到实践涉及到的知识比较多,并不是这边文章所能讲述清楚的,只能把最近遇到的问题具体分析. 这样写起来更有目标.
此项目只不过是之前大三刚学python就想做点好玩的项目试试看(因此技术含量不高),后来这个成为毕业设计的一部分,长期看博客上访问量也不错,就发布出来,希望有想入门python 的朋友可以参考写来玩玩,用项目练技术,用成果获取编码的乐趣。
前言 相关文章: 使用VideoToolbox硬编码H.264 使用VideoToolbox硬解码H.264 使用AudioToolbox编码AAC 使用AudioToolbox播放AAC HLS点播实现(H.264和AAC码流) HLS推流的实现(iOS和OS X系统) iOS在线音频流播放 Audio Unit播放PCM文件 Audio Unit录音(播放伴奏+耳返) Audio Unit播放aac/m4a/mp3等文件 Audio Unit和ExtendedAudioFile播放
由于底层识别使用的是pcm,因此推荐直接上传pcm文件。如果上传其它格式,会在服务器端转码成pcm,调用接口的耗时会增加。
MAD (libmad)是一个开源的高精度 MPEG 音频解码库,支持 MPEG-1(Layer I, Layer II 和 LayerIII(也就是 MP3)。LIBMAD 提供 24 -bit 的 PCM 输出,完全是定点计算,非常适合没有浮点支持的平台上使用。使用 libmad 提供的一系列 API,就可以非常简单地实现 MP3 数据解码工作。
此处还需引入之前说过的话: 新事物的出现必然是为了解决旧事物中的不足。这句话在现实生活中和程序世界中道理一样。ASOC的出现就是为了解决ALSA无法解决的问题。ALSA到底存在什么问题? 以及ASOC会以怎样的方式去解决ALSA存在的问题?
参考这里: FFMPEG开发: Linux下采集摄像头数据录制成MP4视频保存到本: 地https://blog.csdn.net/xiaolong1126626497/article/details/104919095
项目基于BCM6755平台为基础,通过一系列的语音算法完成实现语音交互场景。这次遇到的问题主要是AEC效果差,如上图所示,设备播放音乐的场景,会出现唤醒困难的想象。实际的抓取录音数据发现录音和回采之间的数据延迟高达100ms,远远超过算法要求<30ms的要求。接下来需要定位延迟的问题。
FFmpeg是一款开源软件,用于生成处理多媒体数据的各类库和程序。FFmpeg可以转码、处理视频和图 片(调整视频、图片大小,去噪等)、打包、传输及播放视频。作为最受欢迎的视频和图像处理软件, 早已经被各行各业的不同公司所广泛使用。
参考这篇文章: https://blog.csdn.net/xiaolong1126626497/article/details/104919095
本计划全部放在一篇中,后来发现太长。 因此截取成四篇,一口气看800多行,确实够烦的!
iOS/Android 客户端开发同学如果想要开始学习音视频开发,最丝滑的方式是对音视频基础概念知识有一定了解后,再借助本地平台的音视频能力上手去实践音视频的采集 → 编码 → 封装 → 解封装 → 解码 → 渲染过程,并借助音视频工具来分析和理解对应的音视频数据。
1.先安装 1.madplay-0.15.2b.tar.gz 2.libmad-0.15.1b.tar.gz 3 libid3tag-0.15.1b.tar.gz 方法是:./configure sudo make sudo make install prefix = /usr/local 中prefix 为make install的安装目录,默认在/usr/loacl 如果希望安装到其他目录 ./configure --prefix=/安装目录路径 4.执行madplay 播放mp3 先加载动态库 :如 export LD_LIBRARY_PATH=/usr/local/lib 播放mp3 ./madplay 1.mp3 2.mp3 3.mp3 madpay功能很强求,可以实现多个节目循环播放,快进拖动播放,暂停,恢复,支持wav等格式输出等。 目前madplay还不支持网络播放.不过mp123支持网络播放。 madplay使用方法: 传入打印既可以使用短传入(-n ),也可以使用长传入(--abc),二者等效,下面只讲短传入 -v 获取播放时间 -q 不存在任何打印,但现实警告 -Q 不存在任何打印 --downsample 只采用一半数据 -i 忽略CRC校验错误 -o PATH/xx.wav 可以用来转码,将mp3转为wav 也可以是其他格式,见说明;.raw 表示是元素pcm,.hex等 -a 开启衰减音量 ,增加音量,衰减系统为-175~+18 (当然通过键盘+ —也可以调整音量) -A 同-a -1 -2 -m -S 分别指左声道,右声道,双声道,立体声 -s 用于seek播放 如:0:1:20:11 ,seek到1小时,2分钟,11秒时开始播放 -t 用于播放时间现在 0:1:20:11 ,播放到1小时,2分钟,11秒时就停止 -z 用于随机播放列表 -r, --repeat[=MAX] 循环播放无限次或Max次 --tty-control enable keyboard controls 默认是使能热键 --no-tty-control disable keyboard controls 热键使用 下一首歌曲; f,或ctrl+n 或者> 上一首歌曲 b ,或ctrl+p 或者< 退出:q, Q,获取ctrl+c 获取播放状态信息: i ? 调节音量: - + _ = 暂停恢复:p 停止:s Usage: ./madplay [OPTIONS] FILE [...] Decode and play MPEG audio FILE(s). Verbosity: -v, --verbose show status while decoding -q, --quiet be quiet but show warnings -Q, --very-quiet be quiet and do not show warnings --display-time=MODE use default verbose time display MODE (remaining, current, overall) Decoding: --downsample reduce sample rate 2:1 -i, --ignore-crc ignore CRC errors --ancillary-output=PATH write ancillary data to PATH Audio output: -o, --output=[TYPE:]PATH write output to PATH with format TYPE (below) -b, --bit-depth=DEPTH request DEPTH bits per sample -R, --sample-rate=HERTZ request HERTZ samples per second -d, --no-dither do not dither
概述 昨天想在Ubuntu上用一下HTK工具包来绘制语音信号的频谱图和提取MFCC的结果,但由于前段时间把Ubuntu升级到13.04,系统的声卡驱动是ALSA(Advanced Linux Soun
它是缓冲区不足或溢出,X代表不足或溢出。在这两种情况下,都表明系统速度不够快,未能及时处理来自ALSA音频缓冲区的数据,因此丢失了一些数据。当我们以非常小的缓冲区大小运行时,声卡应该非常快地处理传入缓冲区的数据,否则就溢出overrun了。有些芯片无法适应较小的缓冲区大小,因此我们必须增加缓冲区长度以减轻声音芯片的工作量。通常,xruns可以听到爆裂声或爆裂声。
这篇文章将会按照一般的需求开发流程,从需求、分析、开发,到总结,来给大家讲解一种“在 Android 设备上,播放视频的同时,获取实时音频流”的有效方案。
参考 【Android FFMPEG 开发】Android 中执行 FFMPEG 指令 博客 ;
系统移植过程中发现 # cat /proc/asound/cards 0 [Loopback ]: Loopback - Loopback Loopback 1 1 [wm8524audio ]: wm8524-audio - wm8524-audio wm8524-audio 2 [imxspdif ]: imx-spdif - imx-spdif
这篇文章简单介绍下移动端Android系统下利用OpenSL ES进行音频采集方法。
(前段时间在做嵌入式的课程设计,特将学习心得整理如下) 一、开发工具及环境介绍 1、ARM处理器 ARM处理器是一个32位元精简指令集(RISC)处理器架构,其广泛地使用在许多嵌入式系统设计。 ARM处理器特点: 体积小、低功耗、低成本、高性能; 支持Thumb(16位)/ARM(32位)双指令集,能很好的兼容8位/16位器件; 大量使用寄存器,指令执行速度更快; 大多数数据操作都在寄存器中完成; 寻址方式灵活简单,执行效率高; 指令长度固定。 2、交叉编译环境 2.1、交叉编译 交叉编译(cross-co
在上篇文章中,详细介绍了 FFmepg 的播放流程,以及抽象了解码流程框架,整合视频和音频解码流程的共同点,形成了 BaseDecoder 类。通过继承 BaseDecoder 实现了视频解码子类 VideoDeocder,并整合到了 Player 中,实现了视频的播放渲染。
领取专属 10元无门槛券
手把手带您无忧上云