导航:首页 > 编程知识 > 怎么用c语言编程读音频

怎么用c语言编程读音频

发布时间:2024-05-13 14:23:03

❶ 如何写一个可以播放音乐的程序(用简单C语言编写,可以给出音频文件,只需要播放即可)

用VC++编译通过,代码如下(其中a.wav为自己给出):
#include<windows.h>
#pragma comment(lib,"winmm.lib")
void main()
{
PlaySound("C:\\a.wav",0,SND_FILENAME|SND_SYNC);
}

❷ C语言 怎么编程播放WAV音乐

可以使用PlaySound()函数播复放声制音文件,

该函数原型位于#include<mmsystem.h>中,

函数原型为:BOOLPlaySound(LPCSTRpszSound,HMODULEhmod,DWORDfdwSound);

参数pszSound是要播放声音的文件名,

只支持WAV等格式的文件

参数hmod是应用程序的实例句柄,一般传递NULL就可以;

参数fdwSound是标志的组合掩码,

可选值有SND_FILENAME、SND_ASYNC、SND_SYNC等。

SND_FILENAME表示pszSound参数指定的是文件名(pszSound还可以指定资源、内存音乐、系统音乐等等);

SND_ASYNC:用异步方式播放声音,PlaySound函数在开始播放后立即返回;

SND_SYNC:同步播放声音,在播放完后PlaySound函数才返回;

SND_LOOP一遍遍的重复播放声音,必须与SND_ASYNC标志一块使用。

【2、使用举例】
PlaySound(TEXT("C:\WINDOWS\Media\WindowsXP启动.wav"),NULL,SND_FILENAME|SND_SYNC);

❸ 怎么把歌曲用单片机C语言程序进行播放,急急急急~~~~~~

#include <reg51.h> //包括一个51标准内核的头文件
#define uchar unsigned char //定义一下方便使用
#define uint unsigned int

sbit BEEP=P3^6; //喇叭输出脚
uchar th0_f; //在中断中装载的T0的值高8位
uchar tl0_f; //在中断中装载的T0的值低8位

/***************** 延时 1ms *******************/
void delay_1ms(unsigned int t)
{
unsigned char i,j;
for(t;t>0;t--)
{
for(i=34;i>0;i--)
for(j=13;j>0;j--);
}
}

//T0的值,及输出频率对照表
static code freq[36][2] = {
0xA9,0xEF, //00220HZ ,1 //0
0x93,0xF0, //00233HZ ,1# //1
0x73,0xF1, //00247HZ ,2 //2
0x49,0xF2, //00262HZ ,2# //3
0x07,0xF3, //00277HZ ,3 //4
0xC8,0xF3, //00294HZ ,4 //5
0x73,0xF4, //00311HZ ,4# //6
0x1E,0xF5, //00330HZ ,5 //7
0xB6,0xF5, //00349HZ ,5# //8
0x4C,0xF6, //00370HZ ,6 //9
0xD7,0xF6, //00392HZ ,6# //10
0x5A,0xF7, //00415HZ ,7 //11
0xD8,0xF7, //00440HZ 1 //12
0x4D,0xF8, //00466HZ 1# //13
0xBD,0xF8, //00494HZ 2 //14
0x24,0xF9, //00523HZ 2# //15
0x87,0xF9, //00554HZ 3 //16
0xE4,0xF9, //00587HZ 4 //17
0x3D,0xFA, //00622HZ 4# //18
0x90,0xFA, //00659HZ 5 //19
0xDE,0xFA, //00698HZ 5# //20
0x29,0xFB, //00740HZ 6 //21
0x6F,0xFB, //00784HZ 6# //22
0xB1,0xFB, //00831HZ 7 //23
0xEF,0xFB, //00880HZ `1 //24
0x2A,0xFC, //00932HZ `1# //25
0x62,0xFC, //00988HZ `2 //26
0x95,0xFC, //01046HZ `2# //27
0xC7,0xFC, //01109HZ `3 //28
0xF6,0xFC, //01175HZ `4 //29
0x22,0xFD, //01244HZ `4# //30
0x4B,0xFD, //01318HZ `5 //31
0x73,0xFD, //01397HZ `5# //32
0x98,0xFD, //01480HZ `6 //33
0xBB,0xFD, //01568HZ `6# //34
0xDC,0xFD, //01661HZ `7 //35
};

static code music1[464] = { // 《隐形的翅膀》
36,36,36,36,36,36,36,36,36,36,36,36,8,8,12,12, //每一
16,16,16,16,16,16,19,19,16,16,16,16,14,14,12,12, //次都在徘徊
12,12,12,12,12,12,9,9,8,8,8,36,9,9,12,12, //孤单中坚强 每一
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //次就算很受伤
19,19,16,16,14,14,12,12,14,14,14,36,21,21,19,19, //也不闪泪光 我知
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //道我一直有双
16,16,14,14,12,12,14,14,9,9,9,36,8,8,9,9, //隐形的翅膀 带我
12,12,12,12,12,12,16,16,14,14,14,14,16,14,14,14, //飞 飞过绝
12,12,12,12,12,12,12,12,12,12,12,36,8,8,12,12, //望 不去
16,16,16,16,16,16,19,19,16,16,16,16,14,14,12,12, //想他们拥有
12,12,12,12,12,12,9,9,8,8,8,36,8,8,12,12, //美丽的太阳 我看
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //见每天的夕阳
19,19,16,16,14,14,12,12,14,14,14,36,21,21,19,19, //也会有变化 我知
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //道我一直有双
16,16,14,14,12,12,14,14,9,9,9,36,8,8,9,9, //隐形的翅膀 带我
12,12,12,12,12,12,14,16,14,14,14,14,16,16,12,12, //飞 给我希
12,12,12,12,12,12,12,12,12,12,12,36,16,16,19,19, //望 我终
24,24,24,24,24,36,24,24,24,24,24,24,21,21,19,19, //于看到所有
21,21,24,24,16,16,14,14,12,12,12,36,12,12,12,12, //梦想都开花 追逐
12,12,24,24,24,24,21,21,19,19,16,16,14,14,12,12, //的年轻歌声多嘹
14,14,14,14,14,14,14,14,14,14,14,36,16,16,19,19, //亮 我终
24,24,24,24,24,36,24,24,24,24,24,24,21,21,19,19, //于翱翔用心
21,21,24,24,16,16,14,14,12,12,12,36,12,12,12,12, //凝望不害怕 哪里
12,12,24,24,24,24,21,21,19,19,16,16,14,14,12,12, //会有风就飞多远
12,12,12,12,12,12,12,12,12,12,36,36,16,16,19,19, //吧 隐形
24,24,24,24,24,36,24,24,23,23,23,23,21,21,19,19, //的翅膀让梦
21,21,24,24,16,16,14,14,12,12,12,36,12,12,12,12, //恒久比天长 留一
12,12,24,24,24,24,21,21,19,19,16,16,14,14,14,14, //个愿望让自己
14,14,14,14,12,12,12,12,12,12,12,12,12,12,12,36, //想象... ...
};

static code music2[336] = { // 《北京欢迎你》
16,16,19,19,16,16,14,14,16,16,14,14,16,16,16,36, //迎接另一个晨曦
16,16,14,14,9,9,12,12,16,16,14,14,14,14,14,36, //带来全新空气
14,14,12,12,9,9,12,12,14,14,16,16,19,19,14,14, //气息改变情味不变
16,16,21,21,19,19,9,9,14,14,12,12,12,12,12,36, //茶香飘满情谊
16,16,19,19,16,16,14,14,16,16,14,14,16,16,16,36, //我家大门常打开
16,16,14,14,9,9,12,12,16,16,14,14,14,14,14,36, //开放怀抱等你
14,14,12,12,9,9,12,12,14,14,16,16,19,19,14,14, //拥抱过就有了默契
16,16,21,21,19,19,9,9,14,14,12,12,12,12,12,36, //你会爱上这里
14,14,12,12,9,9,12,12,14,14,16,16,19,19,14,14, //不管远近都是客人
16,16,21,21,19,19,19,19,16,16,16,16,16,16,16,36, //请不用客气
14,14,16,16,14,14,12,12,19,19,21,21,14,14,14,36, //相约好了在一起
9,9,16,16,14,14,14,14,12,12,12,12,12,12,12,36, //我们欢迎你
36,36,36,36,36,36,36,36,16,16,16,16,19,19,19,19, //北京
24,24,19,19,21,21,21,21,36,36,21,21,19,19,16,16, //欢迎你 为你开
16,16,19,19,19,19,19,19,19,19,19,36,16,16,19,19, //天辟地 流动
21,21,24,24,26,26,24,24,19,19,16,16,14,14,19,19, //中的魅力充满着朝
16,16,16,16,16,16,16,16,16,16,16,36,16,16,19,19, //气 北京
24,24,19,19,21,21,21,21,36,36,24,24,26,26,24,24, //欢迎你 在太阳
19,19,16,16,19,19,23,23,21,21,21,21,36,36,16,16, //下分享呼吸 在
14,14,16,16,19,19,28,28,26,26,26,26,26,26,23,23, //黄土地刷新成
24,24,24,24,24,24,24,24,24,24,24,24,24,24,36,36, //绩
};

static code music3[444] = { // 《仙剑奇侠传》
28,28,26,26,28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
28,28,28,28,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,24,24,23,23,21,21,21,21,21,21,21,21,
21,21,21,21,28,28,26,26,36,36,36,36,28,28,26,26,
21,21,21,21,24,24,26,26,28,28,28,28,28,28,28,28,
28,28,31,31,28,28,24,24,26,26,26,26,26,26,26,26,
21,21,21,21,24,24,28,28,26,26,26,26,24,24,24,24,
21,21,21,21,21,21,21,21,21,21,21,21,36,36,36,36,
28,28,26,26,28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
28,28,28,28,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,28,24,23,23,21,21,21,21,21,21,21,21,
21,21,21,21,28,28,26,26,36,36,36,36,28,28,26,26,
28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
16,16,16,16,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,28,24,23,23,21,21,21,21,21,21,21,21,
21,21,21,21,23,23,23,23,23,23,23,23,23,23,23,23,
21,21,21,21,24,24,26,26,28,28,28,28,28,28,28,28,
31,33,31,31,28,28,24,24,26,26,26,26,26,26,26,26,
21,21,21,21,24,24,28,28,26,26,26,26,24,24,24,24,
21,21,21,21,21,21,21,21,21,21,21,21,36,36,36,36,
28,28,26,26,28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
28,28,28,28,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,28,24,23,23,21,21,21,21,21,21,21,21,
23,23,23,23,23,23,23,23,23,23,23,23,21,21,19,19,
21,21,21,21,21,21,21,21,36,36,36,36,36,36,36,36,
};

static code music4[448] = { // 《笑傲江湖》
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,16,16,19,19,21,21,16,16,16,16,16,16,16,36,
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,16,16,19,19,21,19,16,16,16,16,36,16,16,14,
12,12,12,12,14,14,16,16,14,14,14,14,14,14,14,12,
9,9,9,12,14,14,16,16,19,19,19,21,19,19,16,14,
12,12,12,14,14,14,16,16,14,14,14,14,14,12,12,12,
9,9,9,12,14,16,16,19,21,21,21,21,21,21,21,36,
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,16,16,19,19,21,19,16,16,16,16,16,16,16,36,
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,14,16,19,19,21,19,16,16,16,16,36,16,16,14,
12,12,12,12,14,14,16,16,14,14,14,14,14,14,14,12,
9,9,9,12,14,14,16,16,19,19,19,21,19,19,16,14,
12,12,12,14,14,14,16,16,14,14,14,14,14,12,12,12,
9,9,9,12,14,16,16,19,21,21,21,21,21,21,21,36,
14,14,14,14,14,16,16,14,12,12,12,12,12,9,9,12,
14,14,14,14,14,16,16,14,12,12,9,9,36,12,9,12,
14,14,14,14,14,16,16,14,12,12,12,12,36,12,9,12,
14,14,14,14,14,19,19,16,16,16,16,16,16,16,16,36,
9,9,9,9,36,9,9,9,14,14,14,14,14,14,16,14,
12,12,12,12,36,12,12,14,9,9,9,9,9,9,7,7,
9,9,9,9,36,9,7,7,4,4,4,4,36,4,7,7,
2,2,2,2,36,2,2,2,4,4,4,4,4,4,4,36,
9,9,9,9,9,9,9,9,14,14,14,14,14,14,16,16,
12,12,12,12,12,12,14,14,9,9,9,9,12,9,
7,7,7,7,7,7,9,9,4,4,4,2,4,4,7,7,
9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
};

//定时中断0,用于产生唱歌频率
timer0() interrupt 1
{
TL0=tl0_f;TH0=th0_f; //调入预定时值
BEEP=~BEEP; //取反音乐输出IO
P2=~P2;
}

//音阶声音自动输出试验
void main(void) // 主程序
{
uint i;
TMOD = 0x01; //使用定时器0的16位工作模式
TR0 = 1;
ET0 = 1;
EA = 1;
while(1)
{
for(i=0;i<336;i++) //播放音乐
{
if(music2[i] == 36) //空音
{
TR0 = 0;
delay_1ms(190);
TR0 = 1;
}
else
{
tl0_f=freq[music2[i]][0]; //置一个音符的值
th0_f=freq[music2[i]][1];
delay_1ms(190);
}
}
TR0 = 0;
delay_1ms(3000);
TR0 = 1;
}
}

❹ 如何在C语言的编程中插入音乐

一.在程序中直接播放声音文件x0dx0a在VC++ 中的多媒体动态连接库中提供了一组与音频设备有关的函数。利用这些函数可以方便地播放声音。最简单的播放声音方法就是直接调用VC++中提供的声音播放函数BOOL sndPlaySound ( LPCSTR lpszSound,UINT fuSound ); 或BOOL PlaySound( LPCSTR lpszSound, HMODULE hmod, DWORD fuSound );其中参数lpszSound是需要播放声音的.W***文件的路径和文件名, hmod在这里为NULL,fuSound是播放声音的标志,详细说明请参考VC++中的帮助。 例如播放C:soundmusic.wav可以用sndPlaySound ("c:\sound\music.wav",SND_ASYNC);或PlaySound("c:\sound\music.wav",NULL, SND_ASYNC|SND_NODEFAULT );如果没有找到music.wav文件,第一种格式将播放系统默认的声音,第二种格式不会播放系统默认的声音。x0dx0ax0dx0a二.将声音文件加入到程序中x0dx0a在VC++的程序设计中,可以利用各种标准的资源,如位图,菜单,对话框等。同时VC++也允许用户自定义资源,因此我们可以将声音文件作为用户自定义资源加入程序资源文件中,经过编译连接生成EXE文件,实现无.W***文件的声音播放。要实现作为资源的声音文件的播放,首先要在资源管理器中加入待播放的声音文件。x0dx0a具体步骤入下:x0dx0a1.获得包含资源的模块句柄:x0dx0aHMODULE hmod=AfxGetResourceHandle();x0dx0a2.检索资源块信息:x0dx0aHRSRC hSndResource=FindResource(hmod,MAKEINTRESOURCE(IDR_W***E1),_T("W***E"));x0dx0a3. 装载资源数据并加锁:x0dx0aHGLOBAL hGlobalMem=LoadResource(hmod,hSndResource);x0dx0aLPCTSTR lpMemSound=(LPCSTR)LockResource(hGlobalMem);x0dx0a4.播放声音文件:x0dx0asndPlaySound(lpMemSound,SND_MEMORY));x0dx0a5.释放资源句柄:x0dx0aFreeResource(hGlobalMem);

❺ C语言程序里面怎么循环播放声音

编译器 MS VC++ 6.0
已有 音频文件,例如 zzd.wav (允许带路径,例如: "L:\\Li\\prog\\zzd.wav" )
在程序开始播放音乐
在 while (1) { 这里 添 自己的程序 ,含程序结束的控制;}
例子:
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
int main()
{

PlaySound (TEXT("zzd.wav"), NULL, SND_ASYNC | SND_NODEFAULT);

while (1)
{
printf("program is running... here\n");
Sleep(1000);
}
return 0;
}

❻ C语言编程mp3的播放,求解怎么实现通过调用mp3的解码源程序

1.你说的解码程序一般是作为库存在的,也就是xx.dll
2.c语言调用库可以参考msdn或者网络,其实都很容易实现。
3.一般成熟的库都会有官方说明,看看官方说明就会知道需要的函数在什么dll里面。
4.你现在的问题主要是入门不太会,搞懂了第一第二两个方面,后面几乎不涉及算法,还是比较容易制作的。
祝你好运,不懂留言给我。

❼ 如何用c语言编出能用键盘敲出音乐的的程序

下面用beep函数发音,按键 1,2,3,4,5,6,7,8 对应 多来米发少。。。
按换行键结束。0.3秒一个音,不要按得太快。

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

void main()
{
char p;
int i=0;
printf("input 12345678..\n");
while ( i < 50 ){
p = getch();
if (p == '\r') break;
switch(p-'0'){
case 1: Beep(523,300);break;
case 2: Beep(587,300);break;
case 3: Beep(659,300);break;
case 4: Beep(698,300);break;
case 5: Beep(784,300);break;
case 6: Beep(880,300);break;
case 7: Beep(980,300);break;
case 8: Beep(1060,300);break;
default: break;
}
i++;
}
exit(0);
}

❽ 怎样用C语言编程打开一个文件(比如mp3,mp4)

可以使用PlaySound()函数播放mp3音频,该函数原型位于windows.h。

PlaySound函数的声明为:
BOOL PlaySound(LPCSTR pszSound, HMODULE hwnd,DWORD fdwSound);
参数pszSound是指定了要播放声音的字符串。
参数hwnd是应用程序的实例句柄,除非pszSound的指向一个资源标识符(即fdwSound被定义为SND_RESOURCE),否则必须设置为NULL。
参数fdwSound是标志的组合,如下表所示。若成功则函数返回TRUE,否则返回FALSE。
使用PlaySound函数时需要在#include<windows.h>后面加上(注意:不能加在前面):
例程:

CFileDialog dlg(TRUE, "mp3", "*.mp3", OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, "mp3文件(*.mp3)|*.mp3|");
/*创建选择对话框,让用户从文件夹中选取一个MP3文件*/
int iRet = dlg.DoModal();//获得对话框返回值
if(IDOK == iRet) //如果返回值成功,表明成功获取一个MP3文件
{
CString pathName= dlg.GetPathName(); //得到文件的路径名称
PlaySound( pathName , NULL, SND_FILENAME | SND_ASYNC);//用playsound函数播放该文件
}

阅读全文

与怎么用c语言编程读音频相关的资料

热点内容
模具部程序文件管理规范 浏览:817
ps下载画笔文件的后缀 浏览:989
手机木马制作教程 浏览:646
pdf文件翻译价钱 浏览:436
互联网数据库设计 浏览:777
群发文件app哪个好 浏览:455
qq域名防报毒工具 浏览:259
微信上面的图片看不到 浏览:289
基层财务数据库怎么建立 浏览:262
加密狗检测工具下载 浏览:889
智慧灯app怎么使用 浏览:617
tcl手机升级程序 浏览:188
跳出了icloud密码重置 浏览:110
哪里能查信用卡数据 浏览:191
结婚请柬哪个app靠谱 浏览:932
qq无法阅读pdf文件 浏览:284
ai导出pdf文件有轮廓线 浏览:819
刷机时数据线插台式电脑哪里 浏览:432
手机qq怎样隐身登陆 浏览:339
cdelete导致程序崩溃 浏览:783

友情链接