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