#include <string.h>
#include "../include/asoundlib.h"
-void main( void )
+void main(void)
{
- int idx, idx1, cards, err;
- void *handle;
- struct snd_ctl_hw_info info;
- snd_pcm_info_t pcminfo;
- snd_mixer_info_t mixerinfo;
- char str[128];
-
- cards = snd_cards();
- printf( "Detected %i soundcard%s...\n", cards, cards > 1 ? "s" : "" );
- if ( cards <= 0 ) {
- printf( "Giving up...\n" );
- return;
- }
- for ( idx = 0; idx < cards; idx++ ) {
- if ( (err = snd_ctl_open( &handle, idx )) < 0 ) {
- printf( "Open error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( (err = snd_ctl_hw_info( handle, &info )) < 0 ) {
- printf( "HW info error: %s\n", snd_strerror( err ) );
- continue;
- }
- printf( "Soundcard #%i:\n", idx + 1 );
- printf( " type - %i\n", info.type );
- printf( " gcaps - 0x%x\n", info.gcaps );
- printf( " lcaps - 0x%x\n", info.lcaps );
- printf( " pcm devs - 0x%x\n", info.pcmdevs );
- printf( " mixer devs - 0x%x\n", info.mixerdevs );
- printf( " midi devs - 0x%x\n", info.mididevs );
- memset( str, 0, sizeof( str ) );
- strncpy( str, info.id, sizeof( info.id ) );
- printf( " id - '%s'\n", str );
- printf( " abbreviation - '%s'\n", info.abbreviation );
- printf( " name - '%s'\n", info.name );
- printf( " longname - '%s'\n", info.longname );
- for ( idx1 = 0; idx1 < info.pcmdevs; idx1++ ) {
- printf( "PCM info, device #%i:\n", idx1 );
- if ( (err = snd_ctl_pcm_info( handle, idx1, &pcminfo )) < 0 ) {
- printf( " PCM info error: %s\n", snd_strerror( err ) );
- continue;
- }
- printf( " type - %i\n", pcminfo.type );
- printf( " flags - 0x%x\n", pcminfo.flags );
- printf( " id - '%s'\n", pcminfo.id );
- printf( " name - '%s'\n", pcminfo.name );
- }
- for ( idx1 = 0; idx1 < info.mixerdevs; idx1++ ) {
- printf( "MIXER info, device #%i:\n", idx1 );
- if ( (err = snd_ctl_mixer_info( handle, idx1, &mixerinfo )) < 0 ) {
- printf( " MIXER info error: %s\n", snd_strerror( err ) );
- continue;
- }
- printf( " type - %i\n", mixerinfo.type );
- printf( " channels - %i\n", mixerinfo.channels );
- printf( " caps - 0x%x\n", mixerinfo.caps );
- printf( " id - '%s'\n", mixerinfo.id );
- printf( " name - '%s'\n", mixerinfo.name );
- }
- snd_ctl_close( handle );
- }
+ int idx, idx1, cards, err;
+ void *handle;
+ struct snd_ctl_hw_info info;
+ snd_pcm_info_t pcminfo;
+ snd_mixer_info_t mixerinfo;
+ char str[128];
+
+ cards = snd_cards();
+ printf("Detected %i soundcard%s...\n", cards, cards > 1 ? "s" : "");
+ if (cards <= 0) {
+ printf("Giving up...\n");
+ return;
+ }
+ for (idx = 0; idx < cards; idx++) {
+ if ((err = snd_ctl_open(&handle, idx)) < 0) {
+ printf("Open error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if ((err = snd_ctl_hw_info(handle, &info)) < 0) {
+ printf("HW info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ printf("Soundcard #%i:\n", idx + 1);
+ printf(" type - %i\n", info.type);
+ printf(" gcaps - 0x%x\n", info.gcaps);
+ printf(" lcaps - 0x%x\n", info.lcaps);
+ printf(" pcm devs - 0x%x\n", info.pcmdevs);
+ printf(" mixer devs - 0x%x\n", info.mixerdevs);
+ printf(" midi devs - 0x%x\n", info.mididevs);
+ memset(str, 0, sizeof(str));
+ strncpy(str, info.id, sizeof(info.id));
+ printf(" id - '%s'\n", str);
+ printf(" abbreviation - '%s'\n", info.abbreviation);
+ printf(" name - '%s'\n", info.name);
+ printf(" longname - '%s'\n", info.longname);
+ for (idx1 = 0; idx1 < info.pcmdevs; idx1++) {
+ printf("PCM info, device #%i:\n", idx1);
+ if ((err = snd_ctl_pcm_info(handle, idx1, &pcminfo)) < 0) {
+ printf(" PCM info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ printf(" type - %i\n", pcminfo.type);
+ printf(" flags - 0x%x\n", pcminfo.flags);
+ printf(" id - '%s'\n", pcminfo.id);
+ printf(" name - '%s'\n", pcminfo.name);
+ }
+ for (idx1 = 0; idx1 < info.mixerdevs; idx1++) {
+ printf("MIXER info, device #%i:\n", idx1);
+ if ((err = snd_ctl_mixer_info(handle, idx1, &mixerinfo)) < 0) {
+ printf(" MIXER info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ printf(" type - %i\n", mixerinfo.type);
+ printf(" channels - %i\n", mixerinfo.channels);
+ printf(" caps - 0x%x\n", mixerinfo.caps);
+ printf(" id - '%s'\n", mixerinfo.id);
+ printf(" name - '%s'\n", mixerinfo.name);
+ }
+ snd_ctl_close(handle);
+ }
}
static char *xitoa(int aaa)
{
static char str[12];
-
+
sprintf(str, "%i", aaa);
return str;
}
{
int err;
snd_pcm_format_t format;
-
+
bzero(&format, sizeof(format));
format.format = SND_PCM_SFMT_S16_LE;
format.channels = 2;
snd_pcm_record_info_t rinfo;
snd_pcm_playback_params_t pparams;
snd_pcm_record_params_t rparams;
-
+
if ((err = snd_pcm_playback_info(phandle, &pinfo)) < 0) {
printf("Playback info error: %s\n", snd_strerror(err));
exit(0);
step = rinfo.min_fragment_size;
while (step < 4096 &&
(step & pinfo.fragment_align) != 0 &&
- (step & rinfo.fragment_align) != 0) step++;
+ (step & rinfo.fragment_align) != 0)
+ step++;
if (*fragmentsize) {
*fragmentsize += step;
} else {
{
int err;
snd_pcm_playback_status_t pstatus;
-
+
if ((err = snd_pcm_playback_status(phandle, &pstatus)) < 0) {
printf("Playback status error: %s\n", snd_strerror(err));
exit(0);
{
struct sched_param sched_param;
- if (sched_getparam(0, &sched_param)<0) {
+ if (sched_getparam(0, &sched_param) < 0) {
printf("Scheduler getparam failed...\n");
return;
}
signed long l;
t1.tv_sec -= t2.tv_sec;
- l = (signed long)t1.tv_usec - (signed long)t2.tv_usec;
+ l = (signed long) t1.tv_usec - (signed long) t2.tv_usec;
if (l < 0) {
t1.tv_sec--;
l = -l;
int ridx, pidx, size, ok;
snd_pcm_playback_status_t pstatus;
snd_pcm_record_status_t rstatus;
-
+
setscheduler();
if ((err = snd_pcm_open(&phandle, pcard, pdevice, SND_PCM_OPEN_PLAYBACK)) < 0) {
printf("Playback open error: %s\n", snd_strerror(err));
return;
}
if ((err = snd_pcm_open(&rhandle, rcard, rdevice, SND_PCM_OPEN_RECORD)) < 0) {
- printf( "Record open error: %s\n", snd_strerror(err));
+ printf("Record open error: %s\n", snd_strerror(err));
return;
}
setformat(phandle, rhandle);
while (1) {
- if (setparams(phandle, rhandle, &fragmentsize)<0)
+ if (setparams(phandle, rhandle, &fragmentsize) < 0)
break;
ok = 1;
ridx = pidx = size = 0;
playfragment(phandle, buffer, pidx++, fragmentsize);
size += fragmentsize;
pidx %= 2;
- if (playbackunderrun(phandle)>0)
+ if (playbackunderrun(phandle) > 0)
ok = 0;
}
if ((err = snd_pcm_playback_status(phandle, &pstatus)) < 0) {
}
snd_pcm_flush_record(rhandle);
snd_pcm_flush_playback(phandle);
- if (ok && !playbackunderrun(phandle)>0) {
+ if (ok && !playbackunderrun(phandle) > 0) {
printf("Playback OK!!!\n");
printf("Playback time = %li.%i, Record time = %li.%i, diff = %li\n",
- pstatus.stime.tv_sec,
- pstatus.stime.tv_usec,
- rstatus.stime.tv_sec,
- rstatus.stime.tv_usec,
- timediff(pstatus.stime, rstatus.stime));
+ pstatus.stime.tv_sec,
+ pstatus.stime.tv_usec,
+ rstatus.stime.tv_sec,
+ rstatus.stime.tv_usec,
+ timediff(pstatus.stime, rstatus.stime));
break;
}
}
#include <string.h>
#include "../include/asoundlib.h"
-static void mixer_test( int card, int device )
+static void mixer_test(int card, int device)
{
- int err, channels;
- void *handle;
- snd_mixer_info_t info;
-
- if ( (err = snd_mixer_open( &handle, card, device)) < 0 ) {
- printf( "Mixer open error: %s\n", snd_strerror( err ) );
- return;
- }
- printf( "Mixer %i/%i open ok...\n", card, device );
- channels = snd_mixer_channels( handle );
- if ( channels < 0 ) {
- printf( "Mixer channels error: %s\n", snd_strerror( channels ) );
- return;
- }
- printf( " Mixer have %i channel%s.\n", channels, channels > 1 ? "s" : "" );
- if ( (err = snd_mixer_info( handle, &info )) < 0 ) {
- printf( "Mixer info error: %s\n", snd_strerror( err ) );
- return;
- }
- printf( " Info:\n" );
- printf( " type - %i\n", info.type );
- printf( " channels - %i\n", info.channels );
- printf( " caps - 0x%x\n", info.caps );
- printf( " id - '%s'\n", info.id );
- printf( " name - '%s'\n", info.name );
- snd_mixer_close( handle );
+ int err, channels;
+ void *handle;
+ snd_mixer_info_t info;
+
+ if ((err = snd_mixer_open(&handle, card, device)) < 0) {
+ printf("Mixer open error: %s\n", snd_strerror(err));
+ return;
+ }
+ printf("Mixer %i/%i open ok...\n", card, device);
+ channels = snd_mixer_channels(handle);
+ if (channels < 0) {
+ printf("Mixer channels error: %s\n", snd_strerror(channels));
+ return;
+ }
+ printf(" Mixer have %i channel%s.\n", channels, channels > 1 ? "s" : "");
+ if ((err = snd_mixer_info(handle, &info)) < 0) {
+ printf("Mixer info error: %s\n", snd_strerror(err));
+ return;
+ }
+ printf(" Info:\n");
+ printf(" type - %i\n", info.type);
+ printf(" channels - %i\n", info.channels);
+ printf(" caps - 0x%x\n", info.caps);
+ printf(" id - '%s'\n", info.id);
+ printf(" name - '%s'\n", info.name);
+ snd_mixer_close(handle);
}
-void main( void )
+void main(void)
{
- int idx, idx1, cards, err;
- void *handle;
- struct snd_ctl_hw_info info;
-
- cards = snd_cards();
- printf( "Detected %i soundcard%s...\n", cards, cards > 1 ? "s" : "" );
- if ( cards <= 0 ) {
- printf( "Giving up...\n" );
- return;
- }
- for ( idx = 0; idx < cards; idx++ ) {
- if ( (err = snd_ctl_open( &handle, idx )) < 0 ) {
- printf( "Open error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( (err = snd_ctl_hw_info( handle, &info )) < 0 ) {
- printf( "HW info error: %s\n", snd_strerror( err ) );
- continue;
- }
- for ( idx1 = 0; idx1 < info.mixerdevs; idx1++ )
- mixer_test( idx, idx1 );
- snd_ctl_close( handle );
- }
+ int idx, idx1, cards, err;
+ void *handle;
+ struct snd_ctl_hw_info info;
+
+ cards = snd_cards();
+ printf("Detected %i soundcard%s...\n", cards, cards > 1 ? "s" : "");
+ if (cards <= 0) {
+ printf("Giving up...\n");
+ return;
+ }
+ for (idx = 0; idx < cards; idx++) {
+ if ((err = snd_ctl_open(&handle, idx)) < 0) {
+ printf("Open error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if ((err = snd_ctl_hw_info(handle, &info)) < 0) {
+ printf("HW info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ for (idx1 = 0; idx1 < info.mixerdevs; idx1++)
+ mixer_test(idx, idx1);
+ snd_ctl_close(handle);
+ }
}
#define AU_FILE "/home/ftp/pub/audio/AlwaysOnTheRun.au"
-static void show_playback_status( void *handle )
+static void show_playback_status(void *handle)
{
- snd_pcm_playback_status_t pstatus;
+ snd_pcm_playback_status_t pstatus;
- if ( snd_pcm_playback_status( handle, &pstatus ) < 0 ) {
- perror( "playback status" );
- return;
- }
- printf( "PCM playback status:\n" );
- printf( " rate = %i\n", pstatus.rate );
- printf( " fragments = %i\n", pstatus.fragments );
- printf( " fragment_size = %i\n", pstatus.fragment_size );
- printf( " count = %i\n", pstatus.count );
- printf( " queue = %i\n", pstatus.queue );
- printf( " underrun = %i\n", pstatus.underrun );
- printf( " time = %i.%i\n", (int)pstatus.time.tv_sec, (int)pstatus.time.tv_usec );
- printf( " stime = %i.%i\n", (int)pstatus.stime.tv_sec, (int)pstatus.stime.tv_usec );
- printf( " scount = %i\n", pstatus.scount );
+ if (snd_pcm_playback_status(handle, &pstatus) < 0) {
+ perror("playback status");
+ return;
+ }
+ printf("PCM playback status:\n");
+ printf(" rate = %i\n", pstatus.rate);
+ printf(" fragments = %i\n", pstatus.fragments);
+ printf(" fragment_size = %i\n", pstatus.fragment_size);
+ printf(" count = %i\n", pstatus.count);
+ printf(" queue = %i\n", pstatus.queue);
+ printf(" underrun = %i\n", pstatus.underrun);
+ printf(" time = %i.%i\n", (int) pstatus.time.tv_sec, (int) pstatus.time.tv_usec);
+ printf(" stime = %i.%i\n", (int) pstatus.stime.tv_sec, (int) pstatus.stime.tv_usec);
+ printf(" scount = %i\n", pstatus.scount);
}
-void main( void )
+void main(void)
{
- int card = 0, device = 0, err, fd, count, count1, size, idx;
- void *handle;
- snd_pcm_format_t format;
- snd_pcm_playback_status_t status;
- char *buffer, *buffer1;
+ int card = 0, device = 0, err, fd, count, count1, size, idx;
+ void *handle;
+ snd_pcm_format_t format;
+ snd_pcm_playback_status_t status;
+ char *buffer, *buffer1;
- buffer = (char *)malloc( 512 * 1024 );
- if ( !buffer ) return;
- if ( (err = snd_pcm_open( &handle, card, device, SND_PCM_OPEN_PLAYBACK )) < 0 ) {
- fprintf( stderr, "open failed: %s\n", snd_strerror( err ) );
- return;
- }
- format.format = SND_PCM_SFMT_MU_LAW;
- format.rate = 8000;
- format.channels = 1;
- if ( (err = snd_pcm_playback_format( handle, &format )) < 0 ) {
- fprintf( stderr, "format setup failed: %s\n", snd_strerror( err ) );
- snd_pcm_close( handle );
- return;
- }
- if ( (err = snd_pcm_playback_status( handle, &status )) < 0 ) {
- fprintf( stderr, "status failed: %s\n", snd_strerror( err ) );
- snd_pcm_close( handle );
- return;
- }
- fd = open( AU_FILE, O_RDONLY );
- if ( fd < 0 ) {
- perror( "open file" );
- snd_pcm_close( handle );
- return;
- }
- idx = 0;
- count = read( fd, buffer, 512 * 1024 );
- if ( count <= 0 ) {
- perror( "read from file" );
- snd_pcm_close( handle );
- return;
- }
- close( fd );
- if ( !memcmp( buffer, ".snd", 4 ) ) {
- idx = (buffer[4]<<24)|(buffer[5]<<16)|(buffer[6]<<8)|(buffer[7]);
- if ( idx > 128 ) idx = 128;
- if ( idx > count ) idx = count;
- }
- buffer1 = buffer + idx;
- count -= idx;
- if ( count < 256 * 1024 ) {
- perror( "small count < 256k" );
- snd_pcm_close( handle );
- return;
- }
- count1 = status.fragment_size * 12;
- show_playback_status( handle );
- size = snd_pcm_write( handle, buffer1, count1 );
- sleep( 2 );
- show_playback_status( handle );
- printf( "Pause.. Bytes written %i from %i...\n", size, count1 );
- count -= count1;
- buffer1 += count1;
- snd_pcm_playback_pause( handle, 1 );
- show_playback_status( handle );
- sleep( 5 );
- printf( "Pause end..\n" );
- snd_pcm_playback_pause( handle, 0 );
- show_playback_status( handle );
- size = snd_pcm_write( handle, buffer1, count );
- printf( "Pause end.. Bytes written %i from %i...\n", size, count );
- snd_pcm_close( handle );
- free( buffer );
+ buffer = (char *) malloc(512 * 1024);
+ if (!buffer)
+ return;
+ if ((err = snd_pcm_open(&handle, card, device, SND_PCM_OPEN_PLAYBACK)) < 0) {
+ fprintf(stderr, "open failed: %s\n", snd_strerror(err));
+ return;
+ }
+ format.format = SND_PCM_SFMT_MU_LAW;
+ format.rate = 8000;
+ format.channels = 1;
+ if ((err = snd_pcm_playback_format(handle, &format)) < 0) {
+ fprintf(stderr, "format setup failed: %s\n", snd_strerror(err));
+ snd_pcm_close(handle);
+ return;
+ }
+ if ((err = snd_pcm_playback_status(handle, &status)) < 0) {
+ fprintf(stderr, "status failed: %s\n", snd_strerror(err));
+ snd_pcm_close(handle);
+ return;
+ }
+ fd = open(AU_FILE, O_RDONLY);
+ if (fd < 0) {
+ perror("open file");
+ snd_pcm_close(handle);
+ return;
+ }
+ idx = 0;
+ count = read(fd, buffer, 512 * 1024);
+ if (count <= 0) {
+ perror("read from file");
+ snd_pcm_close(handle);
+ return;
+ }
+ close(fd);
+ if (!memcmp(buffer, ".snd", 4)) {
+ idx = (buffer[4] << 24) | (buffer[5] << 16) | (buffer[6] << 8) | (buffer[7]);
+ if (idx > 128)
+ idx = 128;
+ if (idx > count)
+ idx = count;
+ }
+ buffer1 = buffer + idx;
+ count -= idx;
+ if (count < 256 * 1024) {
+ perror("small count < 256k");
+ snd_pcm_close(handle);
+ return;
+ }
+ count1 = status.fragment_size * 12;
+ show_playback_status(handle);
+ size = snd_pcm_write(handle, buffer1, count1);
+ sleep(2);
+ show_playback_status(handle);
+ printf("Pause.. Bytes written %i from %i...\n", size, count1);
+ count -= count1;
+ buffer1 += count1;
+ snd_pcm_playback_pause(handle, 1);
+ show_playback_status(handle);
+ sleep(5);
+ printf("Pause end..\n");
+ snd_pcm_playback_pause(handle, 0);
+ show_playback_status(handle);
+ size = snd_pcm_write(handle, buffer1, count);
+ printf("Pause end.. Bytes written %i from %i...\n", size, count);
+ snd_pcm_close(handle);
+ free(buffer);
}
#define BUFFER_SIZE 800000
-static char *xitoa( int aaa )
+static char *xitoa(int aaa)
{
- static char str[12];
-
- sprintf( str, "%i", aaa );
- return str;
+ static char str[12];
+
+ sprintf(str, "%i", aaa);
+ return str;
}
-void setformat( void *phandle, void *rhandle )
+void setformat(void *phandle, void *rhandle)
{
- int err;
- snd_pcm_format_t format;
-
- bzero(&format, sizeof(format));
- format.format = SND_PCM_SFMT_S16_LE;
- format.channels = 2;
- format.rate = 22050;
- if ( (err = snd_pcm_playback_format( phandle, &format )) < 0 ) {
- printf( "Playback format error: %s\n", snd_strerror( err ) );
- }
- if ( (err = snd_pcm_record_format( rhandle, &format )) < 0 ) {
- printf( "Record format error: %s\n", snd_strerror( err ) );
- }
+ int err;
+ snd_pcm_format_t format;
+
+ bzero(&format, sizeof(format));
+ format.format = SND_PCM_SFMT_S16_LE;
+ format.channels = 2;
+ format.rate = 22050;
+ if ((err = snd_pcm_playback_format(phandle, &format)) < 0) {
+ printf("Playback format error: %s\n", snd_strerror(err));
+ }
+ if ((err = snd_pcm_record_format(rhandle, &format)) < 0) {
+ printf("Record format error: %s\n", snd_strerror(err));
+ }
}
-void method1( void )
+void method1(void)
{
- void *phandle, *rhandle;
- char buffer[BUFFER_SIZE];
- 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;
- }
- setformat( phandle, rhandle );
- 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 *phandle, *rhandle;
+ char buffer[BUFFER_SIZE];
+ 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;
+ }
+ setformat(phandle, rhandle);
+ 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 method2(void)
{
- void *phandle, *rhandle;
- char buffer[BUFFER_SIZE];
- 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;
- }
- setformat( phandle, rhandle );
- 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 *phandle, *rhandle;
+ char buffer[BUFFER_SIZE];
+ 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;
+ }
+ setformat(phandle, rhandle);
+ 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 method3( void )
+void method3(void)
{
- void *handle;
- char buffer[BUFFER_SIZE];
- int err;
-
- if ( (err = snd_pcm_open( &handle, 0, 0, SND_PCM_OPEN_DUPLEX )) < 0 ) {
- printf( "Duplex open error: %s\n", snd_strerror( err ) );
- return;
- }
- setformat( handle, handle );
- printf( "Recording... " ); fflush( stdout );
- if ( (err = snd_pcm_read( handle, 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( handle )) < 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( handle, 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( handle )) < 0 ) {
- printf( "Playback flush error: %s\n", snd_strerror( err ) );
- return;
- }
- printf( "Playback flush done...\n" );
- snd_pcm_close( handle );
- printf( "Close...\n" );
+ void *handle;
+ char buffer[BUFFER_SIZE];
+ int err;
+
+ if ((err = snd_pcm_open(&handle, 0, 0, SND_PCM_OPEN_DUPLEX)) < 0) {
+ printf("Duplex open error: %s\n", snd_strerror(err));
+ return;
+ }
+ setformat(handle, handle);
+ printf("Recording... ");
+ fflush(stdout);
+ if ((err = snd_pcm_read(handle, 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(handle)) < 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(handle, 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(handle)) < 0) {
+ printf("Playback flush error: %s\n", snd_strerror(err));
+ return;
+ }
+ printf("Playback flush done...\n");
+ snd_pcm_close(handle);
+ printf("Close...\n");
}
-void main( void )
+void main(void)
{
- printf( ">>>>> METHOD 1\n" );
- method1();
- printf( ">>>>> METHOD 2\n" );
- method2();
- printf( ">>>>> METHOD 3\n" );
- method3();
+ printf(">>>>> METHOD 1\n");
+ method1();
+ printf(">>>>> METHOD 2\n");
+ method2();
+ printf(">>>>> METHOD 3\n");
+ method3();
}
#include <string.h>
#include "../include/asoundlib.h"
-const char *get_type( unsigned int type )
+const char *get_type(unsigned int type)
{
- switch ( type ) {
- case 0: return "Boolean";
- case 1: return "Byte";
- case 2: return "Word";
- case 3: return "DWord";
- case 4: return "User";
- default:
- return "Unknown";
- }
+ switch (type) {
+ case 0:
+ return "Boolean";
+ case 1:
+ return "Byte";
+ case 2:
+ return "Word";
+ case 3:
+ return "DWord";
+ case 4:
+ return "User";
+ default:
+ return "Unknown";
+ }
}
-void main( void )
+void main(void)
{
- int cards, card, device, direction, idx, count, err;
- void *handle, *chandle;
- struct snd_ctl_hw_info info;
- struct snd_ctl_switch ctl_switch;
- snd_mixer_switch_t mixer_switch;
- snd_pcm_info_t pcm_info;
- snd_pcm_switch_t pcm_switch;
- snd_rawmidi_switch_t rmidi_switch;
- snd_rawmidi_info_t rmidi_info;
-
- cards = snd_cards();
- printf( "Detected %i soundcard%s...\n", cards, cards > 1 ? "s" : "" );
- if ( cards <= 0 ) {
- printf( "Giving up...\n" );
- return;
- }
-
- /* control interface */
- for ( card = 0; card < cards; card++ ) {
- if ( (err = snd_ctl_open( &handle, card )) < 0 ) {
- printf( "CTL open error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( (err = snd_ctl_hw_info( handle, &info )) < 0 ) {
- printf( "CTL hw info error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( (count = snd_ctl_switches( handle )) < 0 ) {
- printf( "CTL switches error: %s\n", snd_strerror( count ) );
- continue;
- }
- for ( idx = 0; idx < count; idx++ ) {
- if ( (err = snd_ctl_switch_read( handle, idx, &ctl_switch )) < 0 ) {
- printf( "CTL switch read error: %s\n", snd_strerror( count ) );
- continue;
- }
- printf( "CTL switch: '%s' %s (%i-%i)\n", ctl_switch.name, get_type( ctl_switch.type ), ctl_switch.low, ctl_switch.high );
- if ( (err = snd_ctl_switch_write( handle, idx, &ctl_switch )) < 0 ) {
- printf( "CTL switch write error: %s\n", snd_strerror( count ) );
- continue;
- }
- }
- if ( count <= 0 )
- printf( "No CTL switches detected for soundcard #%i '%s'...\n", idx, info.name );
- snd_ctl_close( handle );
- }
+ int cards, card, device, direction, idx, count, err;
+ void *handle, *chandle;
+ struct snd_ctl_hw_info info;
+ struct snd_ctl_switch ctl_switch;
+ snd_mixer_switch_t mixer_switch;
+ snd_pcm_info_t pcm_info;
+ snd_pcm_switch_t pcm_switch;
+ snd_rawmidi_switch_t rmidi_switch;
+ snd_rawmidi_info_t rmidi_info;
- /* mixer interface */
- for ( card = 0; card < cards; card++ ) {
- if ( (err = snd_ctl_open( &handle, card )) < 0 ) {
- printf( "CTL open error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( (err = snd_ctl_hw_info( handle, &info )) < 0 ) {
- printf( "CTL hw info error: %s\n", snd_strerror( err ) );
- continue;
- }
- snd_ctl_close( handle );
- for ( device = 0; device < info.mixerdevs; device++ ) {
- if ( (err = snd_mixer_open( &handle, card, device )) < 0 ) {
- printf( "Mixer open error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( (count = snd_mixer_switches( handle )) < 0 ) {
- printf( "Mixer switches error: %s\n", snd_strerror( count ) );
- continue;
- }
- for ( idx = 0; idx < count; idx++ ) {
- if ( (err = snd_mixer_switch_read( handle, idx, &mixer_switch )) < 0 ) {
- printf( "Mixer switch read error: %s\n", snd_strerror( count ) );
- continue;
- }
- printf( "Mixer switch: '%s' %s (%i-%i)\n", mixer_switch.name, get_type( mixer_switch.type ), mixer_switch.low, mixer_switch.high );
- if ( (err = snd_mixer_switch_write( handle, idx, &mixer_switch )) < 0 ) {
- printf( "Mixer switch write error: %s\n", snd_strerror( count ) );
- continue;
- }
- }
- if ( count <= 0 )
- printf( "No mixer switches detected for soundcard #%i '%s'...\n", idx, info.name );
- snd_mixer_close( handle );
- }
- }
+ cards = snd_cards();
+ printf("Detected %i soundcard%s...\n", cards, cards > 1 ? "s" : "");
+ if (cards <= 0) {
+ printf("Giving up...\n");
+ return;
+ }
+ /* control interface */
+ for (card = 0; card < cards; card++) {
+ if ((err = snd_ctl_open(&handle, card)) < 0) {
+ printf("CTL open error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if ((err = snd_ctl_hw_info(handle, &info)) < 0) {
+ printf("CTL hw info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if ((count = snd_ctl_switches(handle)) < 0) {
+ printf("CTL switches error: %s\n", snd_strerror(count));
+ continue;
+ }
+ for (idx = 0; idx < count; idx++) {
+ if ((err = snd_ctl_switch_read(handle, idx, &ctl_switch)) < 0) {
+ printf("CTL switch read error: %s\n", snd_strerror(count));
+ continue;
+ }
+ printf("CTL switch: '%s' %s (%i-%i)\n", ctl_switch.name, get_type(ctl_switch.type), ctl_switch.low, ctl_switch.high);
+ if ((err = snd_ctl_switch_write(handle, idx, &ctl_switch)) < 0) {
+ printf("CTL switch write error: %s\n", snd_strerror(count));
+ continue;
+ }
+ }
+ if (count <= 0)
+ printf("No CTL switches detected for soundcard #%i '%s'...\n", idx, info.name);
+ snd_ctl_close(handle);
+ }
- /* pcm switches */
- for ( card = 0; card < cards; card++ ) {
- if ( (err = snd_ctl_open( &chandle, card )) < 0 ) {
- printf( "CTL open error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( (err = snd_ctl_hw_info( chandle, &info )) < 0 ) {
- printf( "CTL hw info error: %s\n", snd_strerror( err ) );
- continue;
- }
- for ( device = 0; device < info.pcmdevs; device++ ) {
- if ( (err = snd_ctl_pcm_info( chandle, device, &pcm_info )) < 0 ) {
- printf( "CTL PCM info error: %s\n", snd_strerror( err ) );
- continue;
- }
- for ( direction = 0; direction < 2; direction++ ) {
- int (*switches)( void *handle );
- int (*switch_read)( void *handle, int switchn, snd_pcm_switch_t *data );
- int (*switch_write)( void *handle, int switchn, snd_pcm_switch_t *data );
- char *str;
+ /* mixer interface */
+ for (card = 0; card < cards; card++) {
+ if ((err = snd_ctl_open(&handle, card)) < 0) {
+ printf("CTL open error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if ((err = snd_ctl_hw_info(handle, &info)) < 0) {
+ printf("CTL hw info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ snd_ctl_close(handle);
+ for (device = 0; device < info.mixerdevs; device++) {
+ if ((err = snd_mixer_open(&handle, card, device)) < 0) {
+ printf("Mixer open error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if ((count = snd_mixer_switches(handle)) < 0) {
+ printf("Mixer switches error: %s\n", snd_strerror(count));
+ continue;
+ }
+ for (idx = 0; idx < count; idx++) {
+ if ((err = snd_mixer_switch_read(handle, idx, &mixer_switch)) < 0) {
+ printf("Mixer switch read error: %s\n", snd_strerror(count));
+ continue;
+ }
+ printf("Mixer switch: '%s' %s (%i-%i)\n", mixer_switch.name, get_type(mixer_switch.type), mixer_switch.low, mixer_switch.high);
+ if ((err = snd_mixer_switch_write(handle, idx, &mixer_switch)) < 0) {
+ printf("Mixer switch write error: %s\n", snd_strerror(count));
+ continue;
+ }
+ }
+ if (count <= 0)
+ printf("No mixer switches detected for soundcard #%i '%s'...\n", idx, info.name);
+ snd_mixer_close(handle);
+ }
+ }
- if ( !(pcm_info.flags & (!direction ? SND_PCM_INFO_PLAYBACK : SND_PCM_INFO_RECORD)) ) continue;
- if ( (err = snd_pcm_open( &handle, card, device, !direction ? SND_PCM_OPEN_PLAYBACK : SND_PCM_OPEN_RECORD )) < 0 ) {
- printf( "PCM open error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( !direction ) {
- switches = snd_pcm_playback_switches;
- switch_read = snd_pcm_playback_switch_read;
- switch_write = snd_pcm_playback_switch_write;
- str = "playback";
- } else {
- switches = snd_pcm_record_switches;
- switch_read = snd_pcm_record_switch_read;
- switch_write = snd_pcm_record_switch_write;
- str = "record";
- }
- if ( (count = switches( handle )) < 0 ) {
- printf( "PCM %s switches error: %s\n", str, snd_strerror( count ) );
- continue;
- }
- for ( idx = 0; idx < count; idx++ ) {
- if ( (err = switch_read( handle, idx, &pcm_switch )) < 0 ) {
- printf( "PCM %s switch read error: %s\n", str, snd_strerror( count ) );
- continue;
- }
- printf( "PCM switch: '%s' %s (%i-%i)\n", pcm_switch.name, get_type( pcm_switch.type ), pcm_switch.low, pcm_switch.high );
- if ( (err = switch_write( handle, idx, &pcm_switch )) < 0 ) {
- printf( "PCM %s switch write error: %s\n", str, snd_strerror( count ) );
- continue;
- }
- }
- if ( count <= 0 )
- printf( "No PCM %s switches detected for soundcard #%i/#%i '%s'/'%s'...\n", str, idx, device, info.name, pcm_info.name );
- snd_pcm_close( handle );
- }
- }
- snd_ctl_close( chandle );
- }
+ /* pcm switches */
+ for (card = 0; card < cards; card++) {
+ if ((err = snd_ctl_open(&chandle, card)) < 0) {
+ printf("CTL open error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if ((err = snd_ctl_hw_info(chandle, &info)) < 0) {
+ printf("CTL hw info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ for (device = 0; device < info.pcmdevs; device++) {
+ if ((err = snd_ctl_pcm_info(chandle, device, &pcm_info)) < 0) {
+ printf("CTL PCM info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ for (direction = 0; direction < 2; direction++) {
+ int (*switches) (void *handle);
+ int (*switch_read) (void *handle, int switchn, snd_pcm_switch_t * data);
+ int (*switch_write) (void *handle, int switchn, snd_pcm_switch_t * data);
+ char *str;
- /* rawmidi switches */
- for ( card = 0; card < cards; card++ ) {
- if ( (err = snd_ctl_open( &chandle, card )) < 0 ) {
- printf( "CTL open error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( (err = snd_ctl_hw_info( chandle, &info )) < 0 ) {
- printf( "CTL hw info error: %s\n", snd_strerror( err ) );
- continue;
- }
- for ( device = 0; device < info.mididevs; device++ ) {
- if ( (err = snd_ctl_rawmidi_info( chandle, device, &rmidi_info )) < 0 ) {
- printf( "CTL RawMIDI info error: %s\n", snd_strerror( err ) );
- continue;
- }
- for ( direction = 0; direction < 2; direction++ ) {
- int (*switches)( void *handle );
- int (*switch_read)( void *handle, int switchn, snd_rawmidi_switch_t *data );
- int (*switch_write)( void *handle, int switchn, snd_rawmidi_switch_t *data );
- char *str;
+ if (!(pcm_info.flags & (!direction ? SND_PCM_INFO_PLAYBACK : SND_PCM_INFO_RECORD)))
+ continue;
+ if ((err = snd_pcm_open(&handle, card, device, !direction ? SND_PCM_OPEN_PLAYBACK : SND_PCM_OPEN_RECORD)) < 0) {
+ printf("PCM open error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if (!direction) {
+ switches = snd_pcm_playback_switches;
+ switch_read = snd_pcm_playback_switch_read;
+ switch_write = snd_pcm_playback_switch_write;
+ str = "playback";
+ } else {
+ switches = snd_pcm_record_switches;
+ switch_read = snd_pcm_record_switch_read;
+ switch_write = snd_pcm_record_switch_write;
+ str = "record";
+ }
+ if ((count = switches(handle)) < 0) {
+ printf("PCM %s switches error: %s\n", str, snd_strerror(count));
+ continue;
+ }
+ for (idx = 0; idx < count; idx++) {
+ if ((err = switch_read(handle, idx, &pcm_switch)) < 0) {
+ printf("PCM %s switch read error: %s\n", str, snd_strerror(count));
+ continue;
+ }
+ printf("PCM switch: '%s' %s (%i-%i)\n", pcm_switch.name, get_type(pcm_switch.type), pcm_switch.low, pcm_switch.high);
+ if ((err = switch_write(handle, idx, &pcm_switch)) < 0) {
+ printf("PCM %s switch write error: %s\n", str, snd_strerror(count));
+ continue;
+ }
+ }
+ if (count <= 0)
+ printf("No PCM %s switches detected for soundcard #%i/#%i '%s'/'%s'...\n", str, idx, device, info.name, pcm_info.name);
+ snd_pcm_close(handle);
+ }
+ }
+ snd_ctl_close(chandle);
+ }
- if ( !(pcm_info.flags & (!direction ? SND_RAWMIDI_INFO_OUTPUT : SND_RAWMIDI_INFO_INPUT)) ) continue;
- if ( (err = snd_rawmidi_open( &handle, card, device, !direction ? SND_RAWMIDI_OPEN_OUTPUT : SND_RAWMIDI_OPEN_INPUT )) < 0 ) {
- printf( "RawMIDI CTL open error: %s\n", snd_strerror( err ) );
- continue;
- }
- if ( !direction ) {
- switches = snd_rawmidi_output_switches;
- switch_read = snd_rawmidi_output_switch_read;
- switch_write = snd_rawmidi_output_switch_write;
- str = "output";
- } else {
- switches = snd_rawmidi_input_switches;
- switch_read = snd_rawmidi_input_switch_read;
- switch_write = snd_rawmidi_input_switch_write;
- str = "input";
- }
- if ( (count = switches( handle )) < 0 ) {
- printf( "RawMIDI %s switches error: %s\n", str, snd_strerror( count ) );
- continue;
- }
- for ( idx = 0; idx < count; idx++ ) {
- if ( (err = switch_read( handle, idx, &rmidi_switch )) < 0 ) {
- printf( "RawMIDI %s switch read error: %s\n", str, snd_strerror( count ) );
- continue;
- }
- printf( "RawMIDI switch: '%s' %s (%i-%i)\n", rmidi_switch.name, get_type( rmidi_switch.type ), rmidi_switch.low, rmidi_switch.high );
- if ( (err = switch_write( handle, idx, &rmidi_switch )) < 0 ) {
- printf( "RawMIDI %s switch write error: %s\n", str, snd_strerror( count ) );
- continue;
- }
- }
- if ( count <= 0 )
- printf( "No RawMIDI %s switches detected for soundcard #%i/#%i '%s'/'%s'...\n", str, idx, device, info.name, rmidi_info.name );
- snd_rawmidi_close( handle );
- }
- }
- snd_ctl_close( chandle );
- }
+ /* rawmidi switches */
+ for (card = 0; card < cards; card++) {
+ if ((err = snd_ctl_open(&chandle, card)) < 0) {
+ printf("CTL open error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if ((err = snd_ctl_hw_info(chandle, &info)) < 0) {
+ printf("CTL hw info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ for (device = 0; device < info.mididevs; device++) {
+ if ((err = snd_ctl_rawmidi_info(chandle, device, &rmidi_info)) < 0) {
+ printf("CTL RawMIDI info error: %s\n", snd_strerror(err));
+ continue;
+ }
+ for (direction = 0; direction < 2; direction++) {
+ int (*switches) (void *handle);
+ int (*switch_read) (void *handle, int switchn, snd_rawmidi_switch_t * data);
+ int (*switch_write) (void *handle, int switchn, snd_rawmidi_switch_t * data);
+ char *str;
+
+ if (!(pcm_info.flags & (!direction ? SND_RAWMIDI_INFO_OUTPUT : SND_RAWMIDI_INFO_INPUT)))
+ continue;
+ if ((err = snd_rawmidi_open(&handle, card, device, !direction ? SND_RAWMIDI_OPEN_OUTPUT : SND_RAWMIDI_OPEN_INPUT)) < 0) {
+ printf("RawMIDI CTL open error: %s\n", snd_strerror(err));
+ continue;
+ }
+ if (!direction) {
+ switches = snd_rawmidi_output_switches;
+ switch_read = snd_rawmidi_output_switch_read;
+ switch_write = snd_rawmidi_output_switch_write;
+ str = "output";
+ } else {
+ switches = snd_rawmidi_input_switches;
+ switch_read = snd_rawmidi_input_switch_read;
+ switch_write = snd_rawmidi_input_switch_write;
+ str = "input";
+ }
+ if ((count = switches(handle)) < 0) {
+ printf("RawMIDI %s switches error: %s\n", str, snd_strerror(count));
+ continue;
+ }
+ for (idx = 0; idx < count; idx++) {
+ if ((err = switch_read(handle, idx, &rmidi_switch)) < 0) {
+ printf("RawMIDI %s switch read error: %s\n", str, snd_strerror(count));
+ continue;
+ }
+ printf("RawMIDI switch: '%s' %s (%i-%i)\n", rmidi_switch.name, get_type(rmidi_switch.type), rmidi_switch.low, rmidi_switch.high);
+ if ((err = switch_write(handle, idx, &rmidi_switch)) < 0) {
+ printf("RawMIDI %s switch write error: %s\n", str, snd_strerror(count));
+ continue;
+ }
+ }
+ if (count <= 0)
+ printf("No RawMIDI %s switches detected for soundcard #%i/#%i '%s'/'%s'...\n", str, idx, device, info.name, rmidi_info.name);
+ snd_rawmidi_close(handle);
+ }
+ }
+ snd_ctl_close(chandle);
+ }
}