00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <errno.h>
00004
00005 #include <korebot/korebot.h>
00006
00007 int main(int argc, char * argv[])
00008 {
00009 WAV wav;
00010 int rc;
00011 snd_t snd;
00012 short *buf;
00013 unsigned int size = 2048;
00014
00015
00016 if(argc < 2)
00017 {
00018 printf("usage: soundtest <file.wav>\r\n");
00019 return 1;
00020 }
00021
00022 buf = kb_alloc( size );
00023
00024 kb_snd_init(&snd , "/dev/sound/dsp", "/dev/sound/mixer");
00025
00026 if ( kb_snd_open(&snd ) < 0 ) {
00027 printf("cannot open sound devices\r\n");
00028 return 1;
00029 }
00030
00031 kb_wav_init( &wav );
00032
00033 if ((rc = kb_wav_open( &wav , argv[1], 1 )) == -1 ) {
00034 printf("cannot open %s\r\n",argv[1]);
00035 return 1;
00036 }
00037
00038 if ( wav.fmt.bit_per_sample != 16 && wav.fmt.nb_channel != 2 ) {
00039 printf("wrong bit_per_sample or nb_channel in wav file\r\n");
00040 return 1;
00041 }
00042
00043
00044 if ( kb_snd_setSampleRate( &snd, wav.fmt.sample_rate ) == -1 ) {
00045 printf("unable to set sample rate\r\n");
00046 return 1;
00047 }
00048
00049 for (;;) {
00050 rc = kb_wav_read_data( &wav , buf , size);
00051 if ( rc <= 0 ) {
00052 if ( rc < 0 )
00053 printf( "i/o error in reading file '%s' !" , argv[1]);
00054 break;
00055 }
00056
00057 do {
00058 rc = kb_snd_play( &snd , buf , size );
00059 if ( rc < 0 ) {
00060 if ( errno != EAGAIN ) {
00061 printf( "error in playing sample errno=%d", errno );
00062 break;
00063 }
00064 continue;
00065 }
00066 }
00067 while (0);
00068 }
00069
00070 kb_free( buf );
00071 kb_wav_close( &wav );
00072 }