/* madplay.c */ #include<stdlib.h> #include<stdio.h> #include<sys/types.h> #include<sys/stat.h> #include <sys/ioctl.h> #include<fcntl.h> #include<unistd.h> #include<linux/soundcard.h> #define MAXLINE 4096 #define SIZE 16 /* 量化位数 */ #define CHANNELS 1 /* 声道数目 */ #define rate 8000 void madplay(FILE *de_fp) { int fd = open("/dev/dsp", O_WRONLY); if (fd==-1) { perror("open of /dev/dsp failed"); exit(1); } int arg; int status; /* 设置采样时的量化位数 */ arg = SIZE; status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg); if (status == -1) perror("SOUND_PCM_WRITE_BITS ioctl failed"); if (arg != SIZE) perror("unable to set sample size"); /* 设置采样时的声道数目 */ 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"); /* 设置采样时的采样频率 */ arg = rate; status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg); if (status == -1) perror("SOUND_PCM_WRITE_WRITE ioctl failed"); unsigned char buf[MAXLINE]; printf("open of soundcard success\n");//test while(!feof(de_fp)){ printf("madplaying\n"); int status=fread(buf,sizeof(unsigned char),MAXLINE,de_fp);//de_fp文件数据读入buf if(status==0){ printf("status==0\n"); } else if (status != MAXLINE) perror("read wrong number of bytes"); write(fd,buf,status);//buf数据写入声卡 } close(fd); }优化代码 
时间: 2023-05-27 11:03:11 浏览: 31
madplay.c 是一个程序文件的名称,它是一个用于播放MP3格式音频文件的开源软件。madplay.c 的实现基于mad音频解码器库,可以在 Linux、Unix、Windows 等操作系统中使用。其主要功能包括解码和播放 MP3 文件,支持循环、随机播放等操作。
相关问题
madplay函数的需要调用头文件(Linux音乐播放器)
在Linux中使用madplay函数进行音乐播放,需要调用以下头文件:
```c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>
#include <mad.h>
```
其中,`<mad.h>`是madplay所依赖的MPEG音频解码库的头文件。
linux madplay MP3
Madplay是一款可以在Linux系统上播放MP3音频文件的命令行工具。它具有轻量级、简单易用、高效稳定等特点,可以通过在终端输入命令来播放MP3文件。例如,在终端输入以下命令可以播放名为music.mp3的音频文件:
```
madplay music.mp3
```
同时,Madplay还支持一些其他的命令行参数,例如可以控制音量、选择播放通道等。你可以输入以下命令查看帮助文档:
```
madplay --help
```
希望这些信息能够对你有所帮助。
相关推荐







