#define OPEN_DSP_FAILED 0x00000001/* Failed to open DSP!*/
#define Samplerate_status 0x00000002/*samplerate STATUS failed*/
#define Set_samplerate_failed 0x00000003/*set samplerate failed*/
#define Channels_status 0x00000004/*channels STATUS failed*/
#define SET_CHANNELS_FAILED 0x00000005/*set channels failed*/
#define Fmt_status 0x00000006/*fmt STATUS failed*/
#define Set_fmt_failed 0x00000007/*set FMT failed*/
#define Open_file_failed 0x00000008/*opem filed failed*/
int P8100_audio_play (char * pathname, int nsamplerate, int nchannels, int fmt)
{
int dsp_fd,mix_fd,status,arg;
DSP_FD = open ("/DEV/DSP", O_RDWR); /* Open DSP * *
if (DSP_FD < 0)
{
return open_dsp_failed;
}
arg = nsamplerate;
Status = IOCTL (Dsp_fd,sound_pcm_write_rate, & Arg); /* Set Samplerate * *
if (Status < 0)
{
Close (DSP_FD);
return samplerate_status;
}
if (Arg!= nsamplerate)
{
Close (DSP_FD);
return set_samplerate_failed;
}
arg = nchannels; /* Set Channels * *
Status = IOCTL (DSP_FD, Sound_pcm_write_channels, & Arg);
if (Status < 0)
{
Close (DSP_FD);
return channels_status;
}
if (Arg!= nchannels)
{
Close (DSP_FD);
return set_channels_failed;
}
arg = FMT; /* Set bit FMT * *
Status = IOCTL (DSP_FD, sound_pcm_write_bits, & Arg);
if (Status < 0)
{
Close (DSP_FD);
return fmt_status;
}
if (Arg!= FMT)
{
Close (DSP_FD);
return set_fmt_failed;
/* To this set all the parameters of the DSP * *
FILE * file_fd = fopen (Pathname, "R");
if (file_fd = NULL)
{
Close (DSP_FD);
return open_file_failed;
}
int num = 3 * nchannels * nsamplerate * FMT/8;
int get_num;
Char Buf[num];
while (feof (file_fd) = = 0)
{
Get_num = Fread (buf, 1, NUM,FILE_FD);
Write (Dsp_fd,buf,get_num);
if (get_num!= num)
{
Close (DSP_FD);
Fclose (FILE_FD);
return 0;
}
}
Close (DSP_FD);
Fclose (FILE_FD);
return 0;
}
/*
*test
*/
int main ()
{
int value;
Value = P8100_audio_play ("/windows/c/windows/media/windows startup.wav", 44100, 2, 16); Note the path of the file to play Oh ...
fprintf (stderr, "value is%d", value);
return 0;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.