Linux环境下用c语言写的播放wav文件的小程序
本程序可以读取.wav文件,然后进行播放。
确认方法:cat /etc/sndstat,如果显示无此设备,则没有安装驱动。
#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sys/ioctl.h>#include <stdlib.h>#include <stdio.h>#include <linux/soundcard.h>/* 下面的三个参数是跟具体文件相关的,文件什么样,就要设置成什么样 */
int main(){ int fd; int wavfd; //wav文件的描述符
if (fd < 0) { printf("open of /dev/dsp failed"); exit(1);} wavfd = open("12193767609.wav",O_RDONLY); if (wavfd < 0) { printf("open of wav failed"); exit(1); }
/* .......... */ arg = CHANNELS; status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg); if (status == -1) perror("SOUND_PCM_WRITE_CHANNELS ioctl failed"); if (arg != CHANNELS) perror("unable to set number of channels");
/* 从wav文件中读buf大小的内容,然后写入/etc/dsp中,直到文件结束 */ int time = 0; //动态显示播放时间用
/*status = ioctl(fd, SOUND_PCM_SYNC, 0);
}}本程序中需要一个.wav文件才能播放,你可以到百度mp3上去搜索一个.wav文件,放到程序目录下。然后,把程序中的文件名改成该音频的文件名。
相关文档:
1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI) 就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......
【例10.21】用选择法对10个整数排序。
main()
{int *p,i,a[10]={3,7,9,11,0,6,7,5,4,2};
printf("The original array:\n");
for(i=0;i<10;i++)
printf("%d,",a[i]);
printf("\n");
p=a;
sort(p,10);
for(p=a,i=0;i<10;i++)
{printf("%d ",*p);p++;}
printf("\n");
}
sort(int x[],int n)
......
原文
Python和C分别有着各自的优缺点,用Python开发程序速度快,可靠性高,并且有许多现成模块可供使用,但执行速度相对较慢;C语言则正好相反,其执行速度快,但开发效率低。为了充分利用两种语言各自的优点,比较好的做法是用Python开发整个软件框架,而用C语言实现其关键模块。本文介绍如何利用C语言来扩展Python的功 ......