Initial revision

This commit is contained in:
Jaroslav Kysela 1998-08-13 15:42:56 +00:00
commit 5abac67626
47 changed files with 7915 additions and 0 deletions

74
src/Makefile Normal file
View file

@ -0,0 +1,74 @@
#
# Makefile for ALSA library
# Copyright (c) 1994-98 by Jaroslav Kysela <perex@jcu.cz>
#
include ../Makefile.conf
TARGET=../lib/libsound.a
STARGET=../lib/libsound.so
STARGETX=../lib/libsound.so.$(SND_LIB_VERSION)
STARGETO=../lib/libsound.so.$(SND_LIB_MAJOR)
TARGETS=$(TARGET) $(STARGET)
STATIC_LIBS= control/libcontrol.a \
mixer/libmixer.a \
pcm/libpcm.a
DYNAMIC_LIBS= control/libcontrol.Sa \
mixer/libmixer.Sa \
pcm/libpcm.Sa
OBJECTS=error.o
SOBJECTS=error.So
.SUFFIXES:
.SUFFIXES: .c .s .S .o .So .a .Sa
.c.o:
$(CC) $(COPTS) $(INCLUDE) -c -o $*.o $<
.c.So:
$(CC) $(COPTS) $(INCLUDE) -fPIC -c -o $*.So $<
all: $(TARGETS)
$(TARGET): .depend $(OBJECTS) $(STATIC_LIBS)
rm -f ../lib/libsound.a
$(LINKER) -r -o $(TARGET) $(STATIC_LIBS) $(OBJECTS)
$(STARGET): .depend $(SOBJECTS) $(DYNAMIC_LIBS)
rm -f ../lib/libsound*.so*
$(CC) -shared -Wl,-soname,libsound.so.$(SND_LIB_MAJOR) $(DYNAMIC_LIBS) $(SOBJECTS) -o $(STARGETX)
ln -s libsound.so.$(SND_LIB_VERSION) $(STARGET)
ln -s libsound.so.$(SND_LIB_VERSION) $(STARGETO)
control/libcontrol.a:
$(MAKE) -C control
control/libcontrol.sa:
$(MAKE) -C control
mixer/libmixer.a:
$(MAKE) -C mixer
mixer/libmixer.sa:
$(MAKE) -C mixer
pcm/libpcm.a:
$(MAKE) -C pcm
pcm/libpcm.sa:
$(MAKE) -C pcm
clean:
$(MAKE) -C control clean
$(MAKE) -C pcm clean
$(MAKE) -C mixer clean
rm -f core .depend *.o *.So *.orig *~
rm -f ../lib/libsound.*
.depend:
$(CPP) $(COPTS) $(INCLUDE) -M *.c > .depend
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif

42
src/control/Makefile Normal file
View file

@ -0,0 +1,42 @@
#
# Makefile for ALSA library
# Copyright (c) 1994-98 by Jaroslav Kysela <perex@jcu.cz>
#
include ../../Makefile.conf
TARGET=libcontrol.a
STARGET=libcontrol.Sa
OBJECTS=cards.o control.o
SOBJECTS=cards.So control.So
TARGETS=$(TARGET) $(STARGET)
.SUFFIXES:
.SUFFIXES: .c .s .S .o .So .a .Sa
.c.o:
$(CC) $(COPTS) $(INCLUDE) -c -o $*.o $<
.c.So:
$(CC) $(COPTS) $(INCLUDE) -fPIC -c -o $*.So $<
all: $(TARGETS)
$(TARGET): .depend $(OBJECTS)
$(LINKER) -r -o $@ $(OBJECTS)
$(STARGET): .depend $(SOBJECTS)
$(LINKER) -r -o $@ $(SOBJECTS)
clean:
rm -f core .depend *.o *.So *.a *.Sa *.orig *~
.depend:
$(CPP) $(COPTS) $(INCLUDE) -M *.c > .depend
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif

94
src/control/cards.c Normal file
View file

@ -0,0 +1,94 @@
/*
* Control Interface - main file
* Copyright (c) 1998 by Jaroslav Kysela <perex@jcu.cz>
*
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "soundlib.h"
#define SND_FILE_CONTROL "/dev/sndcontrol%i"
int snd_cards( void )
{
int idx, count;
unsigned int mask;
mask = snd_cards_mask();
for ( idx = 0, count = 0; idx < SND_CARDS; idx++ ) {
if ( mask & (1 << idx) ) count++;
}
return count;
}
/*
* this routine uses very ugly method...
* need to do...
*/
unsigned int snd_cards_mask( void )
{
int fd, idx;
unsigned int mask;
char filename[32];
for ( idx = 0, mask = 0; idx < SND_CARDS; idx++ ) {
sprintf( filename, SND_FILE_CONTROL, idx );
if ( (fd = open( filename, O_RDWR )) < 0 ) continue;
close( fd );
mask |= 1 << idx;
}
return mask;
}
int snd_card_name( const char *string )
{
int card, cards;
void *handle;
struct snd_ctl_hw_info info;
cards = snd_cards();
if ( cards <= 0 ) return -ENODEV;
if ( !string ) return -EINVAL;
if ( (isdigit( *string ) && *(string+1) == 0) ||
(isdigit( *string ) && isdigit( *(string+1) ) && *(string+2) == 0) ) {
sscanf( string, "%i", &card );
card--;
if ( card < 0 || card >= cards )
return -EINVAL;
return card;
}
for ( card = 0; card < cards; card++ ) {
if ( snd_ctl_open( &handle, card ) < 0 )
continue;
if ( snd_ctl_hw_info( handle, &info ) < 0 ) {
snd_ctl_close( handle );
continue;
}
snd_ctl_close( handle );
if ( !strcmp( info.id, string ) )
return card;
}
return -ENODEV;
}

146
src/control/control.c Normal file
View file

@ -0,0 +1,146 @@
/*
* Control Interface - main file
* Copyright (c) 1998 by Jaroslav Kysela <perex@jcu.cz>
*
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "soundlib.h"
#define SND_FILE_CONTROL "/dev/sndcontrol%i"
#define SND_CTL_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 0 )
typedef struct {
int card;
int fd;
} snd_ctl_t;
int snd_ctl_open( void **handle, int card )
{
int fd, ver;
char filename[32];
snd_ctl_t *ctl;
*handle = NULL;
if ( card < 0 || card >= SND_CARDS ) return -EINVAL;
sprintf( filename, SND_FILE_CONTROL, card );
if ( (fd = open( filename, O_RDWR )) < 0 ) return -errno;
if ( ioctl( fd, SND_CTL_IOCTL_PVERSION, &ver ) < 0 ) {
close( fd );
return -errno;
}
if ( ver > SND_CTL_VERSION_MAX ) return -SND_ERROR_UNCOMPATIBLE_VERSION;
ctl = (snd_ctl_t *)calloc( 1, sizeof( snd_ctl_t ) );
if ( ctl == NULL ) {
close( fd );
return -ENOMEM;
}
ctl -> card = card;
ctl -> fd = fd;
*handle = ctl;
return 0;
}
int snd_ctl_close( void *handle )
{
snd_ctl_t *ctl;
int res;
ctl = (snd_ctl_t *)handle;
if ( !ctl ) return -EINVAL;
res = close( ctl -> fd ) < 0 ? -errno : 0;
free( ctl );
return res;
}
int snd_ctl_file_descriptor( void *handle )
{
snd_ctl_t *ctl;
ctl = (snd_ctl_t *)handle;
if ( !ctl ) return -EINVAL;
return ctl -> fd;
}
int snd_ctl_hw_info( void *handle, struct snd_ctl_hw_info *info )
{
snd_ctl_t *ctl;
ctl = (snd_ctl_t *)handle;
if ( !ctl ) return -EINVAL;
if ( ioctl( ctl -> fd, SND_CTL_IOCTL_HW_INFO, info ) < 0 )
return -errno;
return 0;
}
int snd_ctl_pcm_info( void *handle, int dev, snd_pcm_info_t *info )
{
snd_ctl_t *ctl;
ctl = (snd_ctl_t *)handle;
if ( !ctl ) return -EINVAL;
if ( ioctl( ctl -> fd, SND_CTL_IOCTL_PCM_DEVICE, &dev ) < 0 )
return -errno;
if ( ioctl( ctl -> fd, SND_CTL_IOCTL_PCM_INFO, info ) < 0 )
return -errno;
return 0;
}
int snd_ctl_pcm_playback_info( void *handle, int dev, snd_pcm_playback_info_t *info )
{
snd_ctl_t *ctl;
ctl = (snd_ctl_t *)handle;
if ( !ctl ) return -EINVAL;
if ( ioctl( ctl -> fd, SND_CTL_IOCTL_PCM_DEVICE, &dev ) < 0 )
return -errno;
if ( ioctl( ctl -> fd, SND_CTL_IOCTL_PCM_PLAYBACK_INFO, info ) < 0 )
return -errno;
return 0;
}
int snd_ctl_pcm_record_info( void *handle, int dev, snd_pcm_record_info_t *info )
{
snd_ctl_t *ctl;
ctl = (snd_ctl_t *)handle;
if ( !ctl ) return -EINVAL;
if ( ioctl( ctl -> fd, SND_CTL_IOCTL_PCM_DEVICE, &dev ) < 0 )
return -errno;
if ( ioctl( ctl -> fd, SND_CTL_IOCTL_PCM_RECORD_INFO, info ) < 0 )
return -errno;
return 0;
}
int snd_ctl_mixer_info( void *handle, int dev, snd_mixer_info_t *info )
{
snd_ctl_t *ctl;
ctl = (snd_ctl_t *)handle;
if ( !ctl ) return -EINVAL;
if ( ioctl( ctl -> fd, SND_CTL_IOCTL_MIXER_DEVICE, &dev ) < 0 )
return -errno;
if ( ioctl( ctl -> fd, SND_CTL_IOCTL_MIXER_INFO, info ) < 0 )
return -errno;
return 0;
}

42
src/error.c Normal file
View file

@ -0,0 +1,42 @@
/*
* Error Routines
* Copyright (c) 1998 by Jaroslav Kysela <perex@jcu.cz>
*
* snd_strerror routine needs to be recoded for locale support
*
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "soundlib.h"
static const char *snd_error_codes[] = {
"Sound protocol isn't compatible"
};
const char *snd_strerror( int errnum )
{
if ( errnum < 0 ) errnum = -errnum;
if ( errnum < SND_ERROR_BEGIN )
return (const char *)strerror( errnum );
errnum -= SND_ERROR_BEGIN;
if ( errnum >= sizeof( snd_error_codes ) / sizeof( const char * ) )
return "Unknown error";
return snd_error_codes[ errnum ];
}

41
src/mixer/Makefile Normal file
View file

@ -0,0 +1,41 @@
#
# Makefile for ALSA library
# Copyright (c) 1994-98 by Jaroslav Kysela <perex@jcu.cz>
#
include ../../Makefile.conf
TARGET=libmixer.a
STARGET=libmixer.Sa
OBJECTS=mixer.o
SOBJECTS=mixer.So
TARGETS=$(TARGET) $(STARGET)
.SUFFIXES:
.SUFFIXES: .c .s .S .o .So .a .Sa
.c.o:
$(CC) $(COPTS) $(INCLUDE) -c -o $*.o $<
.c.So:
$(CC) $(COPTS) $(INCLUDE) -fPIC -c -o $*.So $<
all: $(TARGETS)
$(TARGET): .depend $(OBJECTS)
$(LINKER) -r -o $@ $(OBJECTS)
$(STARGET): .depend $(SOBJECTS)
$(LINKER) -r -o $@ $(SOBJECTS)
clean:
rm -f core .depend *.o *.So *.a *.Sa *.orig *~
.depend:
$(CPP) $(COPTS) $(INCLUDE) -M *.c > .depend
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif

224
src/mixer/mixer.c Normal file
View file

@ -0,0 +1,224 @@
/*
* Mixer Interface - main file
* Copyright (c) 1998 by Jaroslav Kysela <perex@jcu.cz>
*
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "soundlib.h"
#define SND_FILE_MIXER "/dev/sndmixer%i%i"
#define SND_CTL_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 0 )
typedef struct {
int card;
int device;
int fd;
} snd_mixer_t;
int snd_mixer_open( void **handle, int card, int device )
{
int fd, ver;
char filename[32];
snd_mixer_t *mixer;
*handle = NULL;
if ( card < 0 || card >= SND_CARDS ) return -EINVAL;
sprintf( filename, SND_FILE_MIXER, card, device );
if ( (fd = open( filename, O_RDWR )) < 0 ) return -errno;
if ( ioctl( fd, SND_MIXER_IOCTL_PVERSION, &ver ) < 0 ) {
close( fd );
return -errno;
}
if ( ver > SND_CTL_VERSION_MAX ) return -SND_ERROR_UNCOMPATIBLE_VERSION;
mixer = (snd_mixer_t *)calloc( 1, sizeof( snd_mixer_t ) );
if ( mixer == NULL ) {
close( fd );
return -ENOMEM;
}
mixer -> card = card;
mixer -> device = device;
mixer -> fd = fd;
*handle = mixer;
return 0;
}
int snd_mixer_close( void *handle )
{
snd_mixer_t *mixer;
int res;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
res = close( mixer -> fd ) < 0 ? -errno : 0;
free( mixer );
return res;
}
int snd_mixer_file_descriptor( void *handle )
{
snd_mixer_t *mixer;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
return mixer -> fd;
}
int snd_mixer_channels( void *handle )
{
snd_mixer_t *mixer;
int result;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_CHANNELS, &result ) < 0 )
return -errno;
return result;
}
int snd_mixer_info( void *handle, snd_mixer_info_t *info )
{
snd_mixer_t *mixer;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_INFO, info ) < 0 )
return -errno;
return 0;
}
int snd_mixer_exact_mode( void *handle, int enable )
{
snd_mixer_t *mixer;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_EXACT, &enable ) < 0 )
return -errno;
return 0;
}
int snd_mixer_channel( void *handle, const char *channel_id )
{
snd_mixer_t *mixer;
snd_mixer_channel_info_t info;
int idx, channels, err;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
/* bellow implementation isn't optimized for speed */
/* info about channels should be cached in the snd_mixer_t structure */
if ( (channels = snd_mixer_channels( handle )) < 0 )
return channels;
for ( idx = 0; idx < channels; idx++ ) {
if ( (err = snd_mixer_channel_info( handle, idx, &info )) < 0 )
return err;
if ( !strncmp( channel_id, info.name, sizeof( info.name ) ) )
return idx;
}
return -EINVAL;
}
int snd_mixer_channel_info( void *handle, int channel, snd_mixer_channel_info_t *info )
{
snd_mixer_t *mixer;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
info -> channel = channel;
if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_CHANNEL_INFO, info ) < 0 )
return -errno;
return 0;
}
int snd_mixer_channel_read( void *handle, int channel, snd_mixer_channel_t *data )
{
snd_mixer_t *mixer;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
data -> channel = channel;
if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_CHANNEL_READ, data ) < 0 )
return -errno;
return 0;
}
int snd_mixer_channel_write( void *handle, int channel, snd_mixer_channel_t *data )
{
snd_mixer_t *mixer;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
data -> channel = channel;
if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_CHANNEL_WRITE, data ) < 0 )
return -errno;
return 0;
}
int snd_mixer_special_read( void *handle, snd_mixer_special_t *special )
{
snd_mixer_t *mixer;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_SPECIAL_READ, special ) < 0 )
return -errno;
return 0;
}
int snd_mixer_special_write( void *handle, snd_mixer_special_t *special )
{
snd_mixer_t *mixer;
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_SPECIAL_WRITE, special ) < 0 )
return -errno;
return 0;
}
int snd_mixer_read( void *handle, snd_mixer_callbacks_t *callbacks )
{
snd_mixer_t *mixer;
int idx, result, count;
unsigned int cmd, tmp;
unsigned char buffer[ 64 ];
mixer = (snd_mixer_t *)handle;
if ( !mixer ) return -EINVAL;
count = 0;
while ( (result = read( mixer -> fd, &buffer, sizeof( buffer ))) > 0 ) {
if ( result & 7 ) return -EIO;
if ( !callbacks ) continue;
for ( idx = 0; idx < result; idx += 8 ) {
cmd = *(unsigned int *)&buffer[ idx ];
tmp = *(unsigned int *)&buffer[ idx + 4 ];
if ( cmd == 0 && callbacks -> channel_was_changed ) {
callbacks -> channel_was_changed( callbacks -> private_data, (int)tmp );
}
}
count += result >> 3; /* return only number of changes */
}
return result >= 0 ? count : -errno;
}

40
src/pcm/Makefile Normal file
View file

@ -0,0 +1,40 @@
#
# Makefile for ALSA library
# Copyright (c) 1994-98 by Jaroslav Kysela <perex@jcu.cz>
#
include ../../Makefile.conf
TARGET=libpcm.a
STARGET=libpcm.Sa
OBJECTS=pcm.o
SOBJECTS=pcm.So
TARGETS=$(TARGET) $(STARGET)
.SUFFIXES: .c .s .S .o .So .a .Sa
.c.o:
$(CC) $(COPTS) $(INCLUDE) -c -o $*.o $<
.c.So:
$(CC) $(COPTS) $(INCLUDE) -fPIC -c -o $*.So $<
all: $(TARGETS)
$(TARGET): .depend $(OBJECTS)
$(LINKER) -r -o $@ $(OBJECTS)
$(STARGET): .depend $(SOBJECTS)
$(LINKER) -r -o $@ $(SOBJECTS)
clean:
rm -f core .depend *.o *.So *.a *.Sa *.orig *~
.depend:
$(CPP) $(COPTS) $(INCLUDE) -M *.c > .depend
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif

265
src/pcm/pcm.c Normal file
View file

@ -0,0 +1,265 @@
/*
* PCM Interface - main file
* Copyright (c) 1998 by Jaroslav Kysela <perex@jcu.cz>
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "soundlib.h"
#define SND_FILE_PCM "/dev/sndpcm%i%i"
#define SND_CTL_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 0 )
typedef struct {
int card;
int device;
int fd;
} snd_pcm_t;
int snd_pcm_open( void **handle, int card, int device, int mode )
{
int fd, ver;
char filename[32];
snd_pcm_t *pcm;
*handle = NULL;
if ( card < 0 || card >= SND_CARDS ) return -EINVAL;
sprintf( filename, SND_FILE_PCM, card, device );
if ( (fd = open( filename, mode )) < 0 ) return -errno;
if ( ioctl( fd, SND_PCM_IOCTL_PVERSION, &ver ) < 0 ) {
close( fd );
return -errno;
}
if ( ver > SND_CTL_VERSION_MAX ) return -SND_ERROR_UNCOMPATIBLE_VERSION;
pcm = (snd_pcm_t *)calloc( 1, sizeof( snd_pcm_t ) );
if ( pcm == NULL ) {
close( fd );
return -ENOMEM;
}
pcm -> card = card;
pcm -> device = device;
pcm -> fd = fd;
*handle = pcm;
return 0;
}
int snd_pcm_close( void *handle )
{
snd_pcm_t *pcm;
int res;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
res = close( pcm -> fd ) < 0 ? -errno : 0;
free( pcm );
return res;
}
int snd_pcm_file_descriptor( void *handle )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
return pcm -> fd;
}
int snd_pcm_block_mode( void *handle, int enable )
{
snd_pcm_t *pcm;
long flags;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( fcntl( pcm -> fd, F_GETFL, &flags ) < 0 )
return -errno;
if ( enable )
flags |= O_NONBLOCK;
else
flags &= ~O_NONBLOCK;
if ( fcntl( pcm -> fd, F_SETFL, &flags ) < 0 )
return -errno;
return 0;
}
int snd_pcm_info( void *handle, snd_pcm_info_t *info )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_INFO, info ) < 0 )
return -errno;
return 0;
}
int snd_pcm_playback_info( void *handle, snd_pcm_playback_info_t *info )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_INFO, info ) < 0 )
return -errno;
return 0;
}
int snd_pcm_record_info( void *handle, snd_pcm_record_info_t *info )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_INFO, info ) < 0 )
return -errno;
return 0;
}
int snd_pcm_playback_format( void *handle, snd_pcm_format_t *format )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_FORMAT, format ) < 0 )
return -errno;
return 0;
}
int snd_pcm_record_format( void *handle, snd_pcm_format_t *format )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_FORMAT, format ) < 0 )
return -errno;
return 0;
}
int snd_pcm_playback_params( void *handle, snd_pcm_playback_params_t *params )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_PARAMS, params ) < 0 )
return -errno;
return 0;
}
int snd_pcm_record_params( void *handle, snd_pcm_record_params_t *params )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_PARAMS, params ) < 0 )
return -errno;
return 0;
}
int snd_pcm_playback_status( void *handle, snd_pcm_playback_status_t *status )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_STATUS, status ) < 0 )
return -errno;
return 0;
}
int snd_pcm_record_status( void *handle, snd_pcm_record_status_t *status )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_STATUS, status ) < 0 )
return -errno;
return 0;
}
int snd_pcm_drain_playback( void *handle )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_DRAIN_PLAYBACK ) < 0 )
return -errno;
return 0;
}
int snd_pcm_flush_playback( void *handle )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_FLUSH_PLAYBACK ) < 0 )
return -errno;
return 0;
}
int snd_pcm_flush_record( void *handle )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_FLUSH_RECORD ) < 0 )
return -errno;
return 0;
}
int snd_pcm_playback_time( void *handle, int enable )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_TIME, &enable ) < 0 )
return -errno;
return 0;
}
int snd_pcm_record_time( void *handle, int enable )
{
snd_pcm_t *pcm;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_TIME, &enable ) < 0 )
return -errno;
return 0;
}
ssize_t snd_pcm_write( void *handle, const void *buffer, size_t size )
{
snd_pcm_t *pcm;
ssize_t result;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
result = write( pcm -> fd, buffer, size );
if ( result < 0 ) return -errno;
return result;
}
ssize_t snd_pcm_read( void *handle, void *buffer, size_t size )
{
snd_pcm_t *pcm;
ssize_t result;
pcm = (snd_pcm_t *)handle;
if ( !pcm ) return -EINVAL;
result = read( pcm -> fd, buffer, size );
if ( result < 0 ) return -errno;
return result;
}