虽然都是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声音系统简介及其比较。
Allwinner 硬件平台R6, R7s, R11, R16, R18, R30, R58, R328, R332, R333, R311, MR133, T7, R329, MR813, R818, R818B, R528, H133, V853, F133。
参考文章: https://blog.csdn.net/xiaolong1126626497/article/details/104916277
PCM是英文Pulse-code modulation的缩写,中文译名是脉冲编码调制。我们知道在现实生活中,人耳听到的声音是模拟信号,PCM就是要把声音从模拟转换成数字信号的一种技术,他的原理简单地说就是利用一个固定的频率对模拟信号进行采样,采样后的信号在波形上看就像一串连续的幅值不一的脉冲,把这些脉冲的幅值按一定的精度进行量化,这些量化后的数值被连续地输出、传输、处理或记录到存储介质中,所有这些组成了数字音频的产生过程。
我们知道,asoc框架里面主要包含machine codec platform 这三大部分:
随着汽车工业的飞速发展和智能化技术的不断突破,车载导航系统作为现代汽车不可或缺的一部分,在人们的日常生活中扮演着越来越重要的角色。它不仅能够提供精确的路线导航,还能提供丰富的地理信息和娱乐服务,为驾驶者带来了极大的便利和乐趣。
采样就是把模拟信号数字化的过程,不仅仅是音频需要采样,所有的模拟信号都需要通过采样转换为可以用0101来表示的数字信号,示意图如下所示:
三.交叉编译alsa-lib和alsa-utils (alsa-utils是一系列的音频设备控制工具,而alsa-lib是alsa-utils依赖的库,所以先将alsa-lib编译好)
此项目只不过是之前大三刚学python就想做点好玩的项目试试看(因此技术含量不高),后来这个成为毕业设计的一部分,长期看博客上访问量也不错,就发布出来,希望有想入门python 的朋友可以参考写来玩玩,用项目练技术,用成果获取编码的乐趣。
针对音箱日常工作项目开展的前期,需要快速的适配音频子模块,方便项目的声学评估和开展,期间遇到不少的问题,其中有一些细节往往会忽略掉,然而正好是问题的所在。在此背景下,遇到问题一步一步梳理,方便快速的定位出问题所在 。
ASoC--ALSA System on Chip ,是建立在标准ALSA驱动层上,为了更好地支持嵌入式处理器和移动设备中的音频Codec的一套软件体系。在ASoc出现之前,内核对于SoC中的音频已经有部分的支持,不过会有一些局限性:
在ASOC在Platform部分,主要是平台相关的DMA操作和音频管理。大概流程先将音频数据从内存通过DMA方式传输到CPU侧的dai接口,然后通过CPU的dai接口(通过I2S总线)将数据从达到Codec中,数据会在Codec侧会解码的操作,最终输出到耳机/音箱中。依然已下图作为参考:
pcm(Pulse-code modulation)脉冲编码调制,是将模拟信号转化为数字信号的一种方法。声音的转化的过程为,先对连续的模拟信号按照固定频率周期性采样,将采样到的数据按照一定的精度进行量化,量化后的信号和采样后的信号差值叫做量化误差,将量化后的数据进行最后的编码存储,最终模拟信号变化为数字信号。
MAD (libmad)是一个开源的高精度 MPEG 音频解码库,支持 MPEG-1(Layer I, Layer II 和 LayerIII(也就是 MP3)。LIBMAD 提供 24 -bit 的 PCM 输出,完全是定点计算,非常适合没有浮点支持的平台上使用。使用 libmad 提供的一系列 API,就可以非常简单地实现 MP3 数据解码工作。
/*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
使用ffmpeg实现一个播放器?是不是没什么新意,不过一直使用ffmpeg程序,还没有用ffmpeg代码接口实现播放器,并且还需要使用linux的alsa接口播放出声音,所以做出来还是觉得有点意思;
产品: 硬件:主控 + audio +tp9930 软件:tina + audio/ai 其他:客户需要调试6路mic,其中2路为v853内部audio codec mic,四路为tp9930 外部i2s mic,且其中一路audio mic与lineout硬件相连,作为aec回声消除。
FFmpeg是一款开源软件,用于生成处理多媒体数据的各类库和程序。FFmpeg可以转码、处理视频和图 片(调整视频、图片大小,去噪等)、打包、传输及播放视频。作为最受欢迎的视频和图像处理软件, 早已经被各行各业的不同公司所广泛使用。
本计划全部放在一篇中,后来发现太长。 因此截取成四篇,一口气看800多行,确实够烦的!
lsmod命令用于显示已经加载到内核中的模块的状态信息。执行lsmod命令后会列出所有已载入系统的模块。Linux操作系统的核心具有模块化的特性,应此在编译核心时,务须把全部的功能都放入核心。您可以将这些功能编译成一个个单独的模块,待需要时再分别载入。
在ASOC小节中描述了整个ASOC的架构,其中Machine是ASOC架构中的关键部件,没有Machine部件,单独的Codec和Platform是无法工作的。因此本节则先从Machine部分开始,那应该如何开始呢? 答案当然是从代码入手,先进入ASOC在kernel中的位置: kernel/sound/soc下
ALSA由许多声卡的声卡驱动程序组成,同时它也提供一个称为libasound的API库。
它是缓冲区不足或溢出,X代表不足或溢出。在这两种情况下,都表明系统速度不够快,未能及时处理来自ALSA音频缓冲区的数据,因此丢失了一些数据。当我们以非常小的缓冲区大小运行时,声卡应该非常快地处理传入缓冲区的数据,否则就溢出overrun了。有些芯片无法适应较小的缓冲区大小,因此我们必须增加缓冲区长度以减轻声音芯片的工作量。通常,xruns可以听到爆裂声或爆裂声。
由于底层识别使用的是pcm,因此推荐直接上传pcm文件。如果上传其它格式,会在服务器端转码成pcm,调用接口的耗时会增加。
参考 【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
行车记录这个设备相信大家应该都不陌生,它的功能主要是记录车辆行驶途中的影像及声音。
(前段时间在做嵌入式的课程设计,特将学习心得整理如下) 一、开发工具及环境介绍 1、ARM处理器 ARM处理器是一个32位元精简指令集(RISC)处理器架构,其广泛地使用在许多嵌入式系统设计。 ARM处理器特点: 体积小、低功耗、低成本、高性能; 支持Thumb(16位)/ARM(32位)双指令集,能很好的兼容8位/16位器件; 大量使用寄存器,指令执行速度更快; 大多数数据操作都在寄存器中完成; 寻址方式灵活简单,执行效率高; 指令长度固定。 2、交叉编译环境 2.1、交叉编译 交叉编译(cross-co
项目Github地址:https://github.com/alsa-project/alsa-lib
WAV文件格式是Microsoft的RIFF规范的一个子集,用于存储多媒体文件。WAV(RIFF)文件由若干个Chunk组成,分别为: RIFF WAVE Chunk,Format Chunk,Fact Chunk(可选),Data Chunk。具体格式如下:
项目开发过程中,由于Broadcom平台音频数字接口比较少,所以采用模拟麦克风作为输入端,经顺芯ES7210 ADC 转换送至Broadcom PCM 数字音频接口。
以上就是通过libmad将mp3先解码成pcm,然后将pcm直接扔到/ dev/dsp音频设备中,但dsp音频设备属于oss架构,已经逐渐被alsa驱动取代,后续会介绍基于alsa驱动架构的mp3播放器
1 OSS(Open Sound System)是unix平台上一个统一的音频接口。
在安装audiotoolsmake install出现问题 running build_ext building 'audiotools.pcm' extension creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/src gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -
一直在做的一个功能是实现系统内部的SoftWare Loopback, 过程中需要学习ALSA相关的知识,包括驱动 / 应用都需要去了解.而ALSA的官方文档感觉很久没有维护,不怎么好理解,只能边看文档变结合源代码去分析问题.而ALSA这部分从驱动到应用,从原理到实践涉及到的知识比较多,并不是这边文章所能讲述清楚的,只能把最近遇到的问题具体分析. 这样写起来更有目标.
3、和PCM相比,I2S更适合立体声系统。当然,I2S的变体也支持多通道的时分复用,因此可以支持多声道。
今天我们来分享一个开源的音频采集代码,现在大部分音频采集都是通过ALSA框架去采集,如果大家把ALSA采集代码学懂,那么大部分的音频采集都可以搞定。这个代码是用ALSA进行音频PCM的采集并保存到本地文件。
ASoC被分为Machine、Platform和Codec三大部分,其中的Machine驱动负责Platform和Codec之间的耦合以及部分和设备或板子特定的代码,再次引用上一节的内容:Machine驱动负责处理机器特有的一些控件和音频事件(例如,当播放音频时,需要先行打开一个放大器);单独的Platform和Codec驱动是不能工作的,它必须由Machine驱动把它们结合在一起才能完成整个设备的音频处理工作。 ASoC的一切都从Machine驱动开始,包括声卡的注册,绑定Platform和Codec驱动
项目基于BCM6755平台为基础,通过一系列的语音算法完成实现语音交互场景。这次遇到的问题主要是AEC效果差,如上图所示,设备播放音乐的场景,会出现唤醒困难的想象。实际的抓取录音数据发现录音和回采之间的数据延迟高达100ms,远远超过算法要求<30ms的要求。接下来需要定位延迟的问题。
Control接口主要让用户空间的应用程序(alsa-lib)可以访问和控制音频codec芯片中的多路开关,滑动控件等。对于Mixer(混音)来说,Control接口显得尤为重要,从ALSA 0.9.x版本开始,所有的mixer工作都是通过control接口的API来实现的。
所谓声学回声消除,是为了解决VoIP(网络电话)中这样一个问题:即A与B进行通话,A端有麦克风和扬声器分别用来采集A的声音和播放B的声音,B端有麦克风和扬声器分别用来采集B的声音和播放A的声音,很明显,由于声音传播的特性,A端的麦克风在采集A的声音的同时,也采集到了A端扬声器播放的来自B的声音,也就是A端采集到的声音是一个混合的声音,这个声音通过网络发给B时,B就不仅能听到A的声音,也能听见B前几秒自己的声音,这就是在B端听到了B自己的回声,同理在A端也可以听到A自己的回声,这显然不是我们想要的。
/*modify by hfl 20140216*/ #define ALSA_PCM_NEW_HW_PARAMS_API # include <stdio.h> # include <unistd.h> # include <sys/stat.h> # include <sys/mman.h> # include "mad.h" #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<stdlib.h> #include <sys/ioctl.h> #include <sys/soundcard.h> #include <alsa/asoundlib.h> /* * This is perhaps the simplest example use of the MAD high-level API. * Standard input is mapped into memory via mmap(), then the high-level API * is invoked with three callbacks: input, output, and error. The output * callback converts MAD's high-resolution PCM samples to 16 bits, then * writes them to standard output in little-endian, stereo-interleaved * format. */ //#define printf static Get_file_length(char *PATH); static int init_dsp(); static int Uninit_dsp(); static int decode(unsigned char const *, unsigned long); static enum mad_flow outputplay(void *data, struct mad_header const *header, struct mad_pcm *pcm); int main(int argc, char *argv[]) { printf("The main is start!\n"); struct stat stat; void *fdm; int fd; //char buffer1[80000]; printf("###The input file is %s ! the arc=%d###\n",argv[1],argc); if (argc == 1) { printf("The argc is wrong!\n"); return 1; } #if 0 if (fstat(STDIN_FILENO, &stat) == -1 || stat.st_size == 0) return 2; #endif fd =open(argv[1],O_RDWR); if(-1==fd) { printf("sorry,The file open is faild!\n"); } else { printf("The file open is sucessed!\n"); } //read(fd,buffer1,sizeof(buffer1)); //printf("%s", buffer1); stat.st_size = Get_file_length(argv[1]); printf("The file size is %d\n",stat.st_size ); printf("The Map is begin ok!\n"); fdm = mmap(0, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); if (fdm == MAP_FAILED) { printf("mmap is failed\n"); return 3; } decode(fdm, stat.st_size); if (munmap(fdm, stat.st
【新智元导读】众所周知,目前将深度神经网络和生物神经网络进行匹配的研究正处于瓶颈期。而近期,IBM公司Irem Boybat等人在《Nature Communication》中发表的文章,有望改善此难题:他们设计了多记忆突触结构(multi-memristive synaptic architecture),能够在不增加功率密度的情况下提高突触的精度,并在一个拥有100多万台相变存储器(PCM)器件的脉冲神经网络(SNN)中对多记忆突触结构进行了实验演示。
参考这里: FFMPEG开发: Linux下采集摄像头数据录制成MP4视频保存到本: 地https://blog.csdn.net/xiaolong1126626497/article/details/104919095
# include <stdio.h> # include <unistd.h> # include <sys/stat.h> # include <sys/mman.h> # include "mad.h" #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<stdlib.h> /* * This is perhaps the simplest example use of the MAD high-level API. * Standard input is mapped into memory via mmap(), then the high-level API * is invoked with three callbacks: input, output, and error. The output * callback converts MAD's high-resolution PCM samples to 16 bits, then * writes them to standard output in little-endian, stereo-interleaved * format. */ #define printf static Get_file_length(char *PATH); static int decode(unsigned char const *, unsigned long); int main(int argc, char *argv[]) { printf("The main is start!\n"); struct stat stat; void *fdm; int fd; //char buffer1[80000]; printf("###The input file is %s ! the arc=%d###\n",argv[1],argc); if (argc == 1) { printf("The argc is wrong!\n"); return 1; } #if 0 if (fstat(STDIN_FILENO, &stat) == -1 || stat.st_size == 0) return 2; #endif fd =open(argv[1],O_RDWR); if(-1==fd) { printf("sorry,The file open is faild!\n"); } else { printf("The file open is sucessed!\n"); } //read(fd,buffer1,sizeof(buffer1)); //printf("%s", buffer1); stat.st_size = Get_file_length(argv[1]); printf("The file size is %d\n",stat.st_size ); printf("The Map is begin!\n"); fdm = mmap(0, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); if (fdm == MAP_FAILED) { printf("mmap is failed\n"); return 3; } decode(fdm, stat.st_size); if (munmap(fdm, stat.st_size) == -1) return 4; return 0; } /* * This is a private message structure. A generic pointer to this structure * is passed to each of the callback functions. Put here any data you need * to access from within the callbacks. */ struct buffer { unsigned char const *start; unsigned long length; }; /* * This is the input callback. The purpose of this callback is to
领取专属 10元无门槛券
手把手带您无忧上云