From: Jaroslav Kysela Date: Tue, 15 Sep 1998 09:28:50 +0000 (+0000) Subject: Initial version... X-Git-Tag: android-x86-9.0-r1~3636 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f2bb7cec378360cb917cef1f4d1c4ac2204350f2;p=android-x86%2Fexternal-alsa-lib.git Initial version... --- diff --git a/test/pcm.c b/test/pcm.c new file mode 100644 index 00000000..913466f2 --- /dev/null +++ b/test/pcm.c @@ -0,0 +1,93 @@ +#include +#include +#include "../include/asoundlib.h" + +static char *xitoa( int aaa ) +{ + static char str[12]; + + sprintf( str, "%i", aaa ); + return str; +} + +void method1( void ) +{ + void *phandle, *rhandle; + char buffer[80000]; + int err; + + if ( (err = snd_pcm_open( &phandle, 0, 0, SND_PCM_OPEN_PLAYBACK )) < 0 ) { + printf( "Playback open error: %s\n", snd_strerror( err ) ); + return; + } + if ( (err = snd_pcm_open( &rhandle, 0, 0, SND_PCM_OPEN_RECORD )) < 0 ) { + printf( "Record open error: %s\n", snd_strerror( err ) ); + return; + } + printf( "Recording... " ); fflush( stdout ); + if ( (err = snd_pcm_read( rhandle, buffer, sizeof( buffer ) )) != sizeof( buffer ) ) { + printf( "Read error: %s\n", err < 0 ? snd_strerror( err ) : xitoa( err ) ); + return; + } + printf( "done...\n" ); + printf( "Playback... " ); fflush( stdout ); + if ( (err = snd_pcm_write( phandle, buffer, sizeof( buffer ) )) != sizeof( buffer ) ) { + printf( "Write error: %s\n", err < 0 ? snd_strerror( err ) : xitoa( err ) ); + return; + } + printf( "done...\n" ); + snd_pcm_close( phandle ); + printf( "Playback close...\n" ); + snd_pcm_close( rhandle ); + printf( "Record close...\n" ); +} + +void method2( void ) +{ + void *phandle, *rhandle; + char buffer[80000]; + int err; + + if ( (err = snd_pcm_open( &phandle, 0, 0, SND_PCM_OPEN_PLAYBACK )) < 0 ) { + printf( "Playback open error: %s\n", snd_strerror( err ) ); + return; + } + if ( (err = snd_pcm_open( &rhandle, 0, 0, SND_PCM_OPEN_RECORD )) < 0 ) { + printf( "Record open error: %s\n", snd_strerror( err ) ); + return; + } + printf( "Recording... " ); fflush( stdout ); + if ( (err = snd_pcm_read( rhandle, buffer, sizeof( buffer ) )) != sizeof( buffer ) ) { + printf( "Read error: %s\n", err < 0 ? snd_strerror( err ) : xitoa( err ) ); + return; + } + printf( "done...\n" ); + if ( (err = snd_pcm_flush_record( rhandle )) < 0 ) { + printf( "Record flush error: %s\n", snd_strerror( err ) ); + return; + } + printf( "Record flush done...\n" ); + printf( "Playback... " ); fflush( stdout ); + if ( (err = snd_pcm_write( phandle, buffer, sizeof( buffer ) )) != sizeof( buffer ) ) { + printf( "Write error: %s\n", err < 0 ? snd_strerror( err ) : xitoa( err ) ); + return; + } + printf( "done...\n" ); + if ( (err = snd_pcm_flush_playback( phandle )) < 0 ) { + printf( "Playback flush error: %s\n", snd_strerror( err ) ); + return; + } + printf( "Playback flush done...\n" ); + snd_pcm_close( phandle ); + printf( "Playback close...\n" ); + snd_pcm_close( rhandle ); + printf( "Record close...\n" ); +} + +void main( void ) +{ + printf( ">>>>> METHOD 1\n" ); + method1(); + printf( ">>>>> METHOD 2\n" ); + method2(); +}