Re: how to play 16k audio file
| Newsgroups | gmane.comp.handhelds.opie.devel |
|---|---|
| Message-ID | <[email protected]> |
Dear Korovkin, Please find attached hello_16k_mono.pcm and simplay.c for C example. #compile gcc simplay.c -o simplay #test simplay hello_16k_mono.pcm This example is not working under opie 0.82. If I modify line 32, and 33 to be nSampleRate = 16000; nChannels = 1; -> nSampleRate = 48000; nChannels = 2; It can play sampling rate 48000 stereo pcm file. I am wondering if I had to install extra drivers to make 16000 mono sound file able to play. Have a nice day Thanks and Best regards, Alan --- Dmitriy Korovkin <[email protected]> 說: > Alan, will you attach a sound file and describe how > we can reproduce the > problem you see, please. > > Dmitriy > > > > [email protected] wrote: > > >Hi all, > > > >Under opie 0.82, > >I found I can only configure /dev/audio > >to be 48000 sampling rate with stereo playback. > > > >Do I need more driver or patch to make > >16000 mono audio to play? > > > >Best regards, > > > >Alan > > > >___________________________________________________ > > > 最新版 Yahoo!奇摩即時通訊 > 7.0,免費網路電話任你打! > > http://messenger.yahoo.com.tw/ > >_______________________________________________ > > > >http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex > > > >Opie-devel mailing list > >[email protected] > >https://handhelds.org/mailman/listinfo/opie-devel > > > > > > > > ___________________________________________________ 最新版 Yahoo!奇摩即時通訊 7.0,免費網路電話任你打! http://messenger.yahoo.com.tw/ _______________________________________________ http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex Opie-devel mailing list [email protected] https://handhelds.org/mailman/listinfo/opie-devel
simplay.c
(text/plain, 1.3 KB)
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/soundcard.h>
#include <string.h>
#include <wait.h>
#define BUFFER_SIZE 320000 //10 seconds for 16k,16bit
int main(int argc, char **argv)
{
int nDevice, nFormat, nSampleRate, nChannels, nLen, nClose;
char szBuffer[BUFFER_SIZE];
FILE *fp;
if (argc<2) {
printf("usage: %s play_file\n", argv[0]);
return -1;
}
//playback
//open device
nDevice = open("/dev/dsp", O_WRONLY, 0);
printf("device open: %d\n",nDevice);
//io setting
nFormat = AFMT_S16_LE;
nSampleRate = 16000;
nChannels = 1;
printf("set record format : %d\n",ioctl(nDevice, SNDCTL_DSP_SETFMT, &nFormat));
printf("set sample rate : %d\n",ioctl(nDevice, SNDCTL_DSP_SPEED, &nSampleRate));
printf("set channels : %d\n",ioctl(nDevice, SNDCTL_DSP_STEREO, &nChannels));
//read data
fp = fopen(argv[1], "rb");
printf("playback ...\n");
while ( ( nLen=fread(szBuffer, sizeof(char), sizeof(szBuffer), fp) )>0 ) {
printf("play data : %d\n",write(nDevice, szBuffer, nLen));
}
fclose(fp);
//close device
nClose = 0;
printf("set close : %d\n",ioctl(nDevice, SNDCTL_DSP_SYNC, &nClose));
printf("device close: %d\n",close(nDevice));
return 0;
}
hello_16k_mono.pcm
(application/octet-stream, 9.4 KB) - not displayed