Better names for ALSA API. Added min_fragments, max_fragments.

This commit is contained in:
Abramo Bagnara 2000-05-27 16:52:17 +00:00
parent 4bb0a08bf9
commit 1a7f88d10e
26 changed files with 1938 additions and 1938 deletions

View file

@ -6,7 +6,7 @@
#include "../include/asoundlib.h"
#if 0
#define USE_BLOCK_MODE /* latency is twice more than for stream mode!!! */
#define USE_FRAGMENT_MODE /* latency is twice more than for frame mode!!! */
#endif
#define USED_RATE 48000
@ -28,18 +28,18 @@ static char *xitoa(int aaa)
static int syncro(snd_pcm_t *phandle, snd_pcm_t *chandle)
{
snd_pcm_channel_info_t pinfo, cinfo;
snd_pcm_stream_info_t pinfo, cinfo;
int err;
bzero(&pinfo, sizeof(pinfo));
bzero(&cinfo, sizeof(cinfo));
pinfo.channel = SND_PCM_CHANNEL_PLAYBACK;
cinfo.channel = SND_PCM_CHANNEL_CAPTURE;
if ((err = snd_pcm_channel_info(phandle, &pinfo)) < 0) {
pinfo.stream = SND_PCM_STREAM_PLAYBACK;
cinfo.stream = SND_PCM_STREAM_CAPTURE;
if ((err = snd_pcm_stream_info(phandle, &pinfo)) < 0) {
printf("Playback info error: %s\n", snd_strerror(err));
exit(0);
}
if ((err = snd_pcm_channel_info(chandle, &cinfo)) < 0) {
if ((err = snd_pcm_stream_info(chandle, &cinfo)) < 0) {
printf("Capture info error: %s\n", snd_strerror(err));
exit(0);
}
@ -70,19 +70,19 @@ static void syncro_id(snd_pcm_sync_t *sync)
int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue)
{
int err, again;
snd_pcm_channel_params_t params;
snd_pcm_channel_setup_t psetup, csetup;
snd_pcm_stream_params_t params;
snd_pcm_stream_setup_t psetup, csetup;
bzero(&params, sizeof(params));
params.channel = SND_PCM_CHANNEL_PLAYBACK;
params.stream = SND_PCM_STREAM_PLAYBACK;
#ifdef USE_BLOCK_MODE
params.mode = SND_PCM_MODE_BLOCK;
params.mode = SND_PCM_MODE_FRAGMENT;
#else
params.mode = SND_PCM_MODE_STREAM;
params.mode = SND_PCM_MODE_FRAME;
#endif
params.format.interleave = 1;
params.format.format = SND_PCM_SFMT_S16_LE;
params.format.voices = 2;
params.format.channels = 2;
params.format.rate = USED_RATE;
params.start_mode = SND_PCM_START_GO;
params.xrun_mode = SND_PCM_XRUN_DRAIN;
@ -100,7 +100,7 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue)
if (*queue > LATENCY_MAX)
return -1;
again = 0;
params.channel = SND_PCM_CHANNEL_PLAYBACK;
params.stream = SND_PCM_STREAM_PLAYBACK;
params.frag_size = *queue;
#ifdef USE_BLOCK_MODE
params.buffer_size = *queue * 2;
@ -109,24 +109,24 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue)
params.buffer_size = *queue;
params.buf.stream.bytes_min = 2;
#endif
if ((err = snd_pcm_channel_params(phandle, &params)) < 0) {
if ((err = snd_pcm_stream_params(phandle, &params)) < 0) {
printf("Playback params error: %s\n", snd_strerror(err));
exit(0);
}
params.channel = SND_PCM_CHANNEL_CAPTURE;
if ((err = snd_pcm_channel_params(chandle, &params)) < 0) {
params.stream = SND_PCM_STREAM_CAPTURE;
if ((err = snd_pcm_stream_params(chandle, &params)) < 0) {
printf("Capture params error: %s\n", snd_strerror(err));
exit(0);
}
bzero(&psetup, sizeof(psetup));
psetup.channel = SND_PCM_CHANNEL_PLAYBACK;
if ((err = snd_pcm_channel_setup(phandle, &psetup)) < 0) {
psetup.stream = SND_PCM_STREAM_PLAYBACK;
if ((err = snd_pcm_stream_setup(phandle, &psetup)) < 0) {
printf("Playback setup error: %s\n", snd_strerror(err));
exit(0);
}
bzero(&csetup, sizeof(csetup));
csetup.channel = SND_PCM_CHANNEL_CAPTURE;
if ((err = snd_pcm_channel_setup(chandle, &csetup)) < 0) {
csetup.stream = SND_PCM_STREAM_CAPTURE;
if ((err = snd_pcm_stream_setup(chandle, &csetup)) < 0) {
printf("Capture setup error: %s\n", snd_strerror(err));
exit(0);
}
@ -164,17 +164,17 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue)
return 0;
}
void showstat(snd_pcm_t *handle, int channel, snd_pcm_channel_status_t *rstatus, size_t bytes)
void showstat(snd_pcm_t *handle, int stream, snd_pcm_stream_status_t *rstatus, size_t bytes)
{
int err;
snd_pcm_channel_status_t status;
snd_pcm_stream_status_t status;
char *str;
str = channel == SND_PCM_CHANNEL_CAPTURE ? "Capture" : "Playback";
str = stream == SND_PCM_STREAM_CAPTURE ? "Capture" : "Playback";
bzero(&status, sizeof(status));
status.channel = channel;
if ((err = snd_pcm_channel_status(handle, &status)) < 0) {
printf("Channel %s status error: %s\n", str, snd_strerror(err));
status.stream = stream;
if ((err = snd_pcm_stream_status(handle, &status)) < 0) {
printf("Stream %s status error: %s\n", str, snd_strerror(err));
exit(0);
}
printf("%s:\n", str);
@ -233,7 +233,7 @@ long readbuf(snd_pcm_t *handle, char *buf, long len, size_t *bytes)
if (r > 0)
*bytes += r;
// printf("read = %li\n", r);
// showstat(handle, SND_PCM_CHANNEL_CAPTURE, NULL);
// showstat(handle, SND_PCM_STREAM_CAPTURE, NULL);
return r;
}
@ -250,7 +250,7 @@ long writebuf(snd_pcm_t *handle, char *buf, long len, size_t *bytes)
// printf("write = %li\n", r);
if (r < 0)
return r;
// showstat(handle, SND_PCM_CHANNEL_PLAYBACK, NULL);
// showstat(handle, SND_PCM_STREAM_PLAYBACK, NULL);
buf += r;
len -= r;
*bytes += r;
@ -268,7 +268,7 @@ int main(void)
int size, ok;
int sync;
snd_pcm_sync_t ssync;
snd_pcm_channel_status_t pstatus, cstatus;
snd_pcm_stream_status_t pstatus, cstatus;
ssize_t r;
size_t bytes_in, bytes_out;
@ -282,9 +282,9 @@ int main(void)
return 0;
}
#ifdef USE_BLOCK_MODE
printf("Using block mode...\n");
printf("Using fragment mode...\n");
#else
printf("Using stream mode...\n");
printf("Using frame mode...\n");
#endif
sync = syncro(phandle, chandle);
if (sync)
@ -330,8 +330,8 @@ int main(void)
if (r > 0 && writebuf(phandle, buffer, r, &bytes_out) < 0)
ok = 0;
}
showstat(phandle, SND_PCM_CHANNEL_PLAYBACK, &pstatus, bytes_out);
showstat(chandle, SND_PCM_CHANNEL_CAPTURE, &cstatus, bytes_in);
showstat(phandle, SND_PCM_STREAM_PLAYBACK, &pstatus, bytes_out);
showstat(chandle, SND_PCM_STREAM_CAPTURE, &cstatus, bytes_in);
snd_pcm_capture_flush(chandle);
snd_pcm_playback_flush(phandle);
if (ok) {

View file

@ -180,14 +180,14 @@ int main(int argc, char** argv)
bzero(&istat, sizeof(istat));
bzero(&ostat, sizeof(ostat));
istat.channel = SND_RAWMIDI_CHANNEL_INPUT;
ostat.channel = SND_RAWMIDI_CHANNEL_OUTPUT;
err = snd_rawmidi_channel_status(handle_in, &istat);
istat.stream = SND_RAWMIDI_STREAM_INPUT;
ostat.stream = SND_RAWMIDI_STREAM_OUTPUT;
err = snd_rawmidi_stream_status(handle_in, &istat);
if (err < 0)
fprintf(stderr, "input channel status error: %d\n", err);
err = snd_rawmidi_channel_status(handle_out, &ostat);
fprintf(stderr, "input stream status error: %d\n", err);
err = snd_rawmidi_stream_status(handle_out, &ostat);
if (err < 0)
fprintf(stderr, "output channel status error: %d\n", err);
fprintf(stderr, "output stream status error: %d\n", err);
printf("input.status.queue = %i\n", istat.queue);
printf("input.status.overrun = %i\n", istat.overrun);
printf("output.status.queue = %i\n", ostat.queue);

View file

@ -4,144 +4,144 @@
void info_channel(snd_pcm_t *handle, int channel, char *id)
{
snd_pcm_channel_info_t chninfo;
snd_pcm_stream_info_t stream_info;
int err;
bzero(&chninfo, sizeof(chninfo));
chninfo.channel = channel;
if ((err = snd_pcm_channel_info(handle, &chninfo))<0) {
bzero(&stream_info, sizeof(stream_info));
stream_info.channel = channel;
if ((err = snd_pcm_stream_info(handle, &stream_info))<0) {
fprintf(stderr, "channel info error: %s\n", snd_strerror(err));
return;
}
printf("%s INFO:\n", id);
printf(" subdevice : %i\n", chninfo.subdevice);
printf(" subname : '%s'\n", chninfo.subname);
printf(" channel : %i\n", chninfo.channel);
printf(" subdevice : %i\n", stream_info.subdevice);
printf(" subname : '%s'\n", stream_info.subname);
printf(" channel : %i\n", stream_info.channel);
printf(" mode : ");
switch (chninfo.mode) {
case SND_PCM_MODE_STREAM:
printf("stream\n");
switch (stream_info.mode) {
case SND_PCM_MODE_FRAME:
printf("frame\n");
break;
case SND_PCM_MODE_BLOCK:
printf("block\n");
case SND_PCM_MODE_FRAGMENT:
printf("fragment\n");
break;
default:
printf("unknown\n");
}
printf(" sync : 0x%x, 0x%x, 0x%x, 0x%x\n",
chninfo.sync.id32[0],
chninfo.sync.id32[1],
chninfo.sync.id32[2],
chninfo.sync.id32[3]);
stream_info.sync.id32[0],
stream_info.sync.id32[1],
stream_info.sync.id32[2],
stream_info.sync.id32[3]);
printf(" flags :");
if (chninfo.flags & SND_PCM_CHNINFO_MMAP)
if (stream_info.flags & SND_PCM_STREAM_INFO_MMAP)
printf(" mmap");
if (chninfo.flags & SND_PCM_CHNINFO_STREAM)
printf(" stream");
if (chninfo.flags & SND_PCM_CHNINFO_BLOCK)
printf(" block");
if (chninfo.flags & SND_PCM_CHNINFO_BATCH)
if (stream_info.flags & SND_PCM_STREAM_INFO_FRAME)
printf(" frame");
if (stream_info.flags & SND_PCM_STREAM_INFO_FRAGMENT)
printf(" fragment");
if (stream_info.flags & SND_PCM_STREAM_INFO_BATCH)
printf(" batch");
if (chninfo.flags & SND_PCM_CHNINFO_INTERLEAVE)
if (stream_info.flags & SND_PCM_STREAM_INFO_INTERLEAVE)
printf(" interleave");
if (chninfo.flags & SND_PCM_CHNINFO_NONINTERLEAVE)
if (stream_info.flags & SND_PCM_STREAM_INFO_NONINTERLEAVE)
printf(" noninterleave");
if (chninfo.flags & SND_PCM_CHNINFO_BLOCK_TRANSFER)
if (stream_info.flags & SND_PCM_STREAM_INFO_BLOCK_TRANSFER)
printf(" block_transfer");
if (chninfo.flags & SND_PCM_CHNINFO_OVERRANGE)
if (stream_info.flags & SND_PCM_STREAM_INFO_OVERRANGE)
printf(" overrange");
printf("\n");
printf(" formats :");
if (chninfo.formats & SND_PCM_FMT_MU_LAW)
if (stream_info.formats & SND_PCM_FMT_MU_LAW)
printf(" mu-Law");
if (chninfo.formats & SND_PCM_FMT_A_LAW)
if (stream_info.formats & SND_PCM_FMT_A_LAW)
printf(" a-Law");
if (chninfo.formats & SND_PCM_FMT_IMA_ADPCM)
if (stream_info.formats & SND_PCM_FMT_IMA_ADPCM)
printf(" IMA-ADPCM");
if (chninfo.formats & SND_PCM_FMT_U8)
if (stream_info.formats & SND_PCM_FMT_U8)
printf(" U8");
if (chninfo.formats & SND_PCM_FMT_S16_LE)
if (stream_info.formats & SND_PCM_FMT_S16_LE)
printf(" S16-LE");
if (chninfo.formats & SND_PCM_FMT_S16_BE)
if (stream_info.formats & SND_PCM_FMT_S16_BE)
printf(" S16-BE");
if (chninfo.formats & SND_PCM_FMT_S8)
if (stream_info.formats & SND_PCM_FMT_S8)
printf(" S8");
if (chninfo.formats & SND_PCM_FMT_U16_LE)
if (stream_info.formats & SND_PCM_FMT_U16_LE)
printf(" U16-LE");
if (chninfo.formats & SND_PCM_FMT_U16_BE)
if (stream_info.formats & SND_PCM_FMT_U16_BE)
printf(" U16-BE");
if (chninfo.formats & SND_PCM_FMT_MPEG)
if (stream_info.formats & SND_PCM_FMT_MPEG)
printf(" MPEG");
if (chninfo.formats & SND_PCM_FMT_GSM)
if (stream_info.formats & SND_PCM_FMT_GSM)
printf(" GSM");
if (chninfo.formats & SND_PCM_FMT_S24_LE)
if (stream_info.formats & SND_PCM_FMT_S24_LE)
printf(" S24-LE");
if (chninfo.formats & SND_PCM_FMT_S24_BE)
if (stream_info.formats & SND_PCM_FMT_S24_BE)
printf(" S24-BE");
if (chninfo.formats & SND_PCM_FMT_U24_LE)
if (stream_info.formats & SND_PCM_FMT_U24_LE)
printf(" U24-LE");
if (chninfo.formats & SND_PCM_FMT_U24_BE)
if (stream_info.formats & SND_PCM_FMT_U24_BE)
printf(" U24-BE");
if (chninfo.formats & SND_PCM_FMT_S32_LE)
if (stream_info.formats & SND_PCM_FMT_S32_LE)
printf(" S32-LE");
if (chninfo.formats & SND_PCM_FMT_S32_BE)
if (stream_info.formats & SND_PCM_FMT_S32_BE)
printf(" S32-BE");
if (chninfo.formats & SND_PCM_FMT_U32_LE)
if (stream_info.formats & SND_PCM_FMT_U32_LE)
printf(" U32-LE");
if (chninfo.formats & SND_PCM_FMT_U32_BE)
if (stream_info.formats & SND_PCM_FMT_U32_BE)
printf(" U32-BE");
if (chninfo.formats & SND_PCM_FMT_FLOAT)
if (stream_info.formats & SND_PCM_FMT_FLOAT)
printf(" Float");
if (chninfo.formats & SND_PCM_FMT_FLOAT64)
if (stream_info.formats & SND_PCM_FMT_FLOAT64)
printf(" Float64");
if (chninfo.formats & SND_PCM_FMT_IEC958_SUBFRAME_LE)
if (stream_info.formats & SND_PCM_FMT_IEC958_SUBFRAME_LE)
printf(" IEC958-LE");
if (chninfo.formats & SND_PCM_FMT_IEC958_SUBFRAME_BE)
if (stream_info.formats & SND_PCM_FMT_IEC958_SUBFRAME_BE)
printf(" IEC958-BE");
if (chninfo.formats & SND_PCM_FMT_SPECIAL)
if (stream_info.formats & SND_PCM_FMT_SPECIAL)
printf(" Special");
printf("\n");
printf(" rates :");
if (chninfo.rates & SND_PCM_RATE_CONTINUOUS)
if (stream_info.rates & SND_PCM_RATE_CONTINUOUS)
printf(" Continuous");
if (chninfo.rates & SND_PCM_RATE_KNOT)
if (stream_info.rates & SND_PCM_RATE_KNOT)
printf(" Knot");
if (chninfo.rates & SND_PCM_RATE_8000)
if (stream_info.rates & SND_PCM_RATE_8000)
printf(" 8000");
if (chninfo.rates & SND_PCM_RATE_11025)
if (stream_info.rates & SND_PCM_RATE_11025)
printf(" 11025");
if (chninfo.rates & SND_PCM_RATE_16000)
if (stream_info.rates & SND_PCM_RATE_16000)
printf(" 16000");
if (chninfo.rates & SND_PCM_RATE_22050)
if (stream_info.rates & SND_PCM_RATE_22050)
printf(" 22050");
if (chninfo.rates & SND_PCM_RATE_32000)
if (stream_info.rates & SND_PCM_RATE_32000)
printf(" 32000");
if (chninfo.rates & SND_PCM_RATE_44100)
if (stream_info.rates & SND_PCM_RATE_44100)
printf(" 44100");
if (chninfo.rates & SND_PCM_RATE_48000)
if (stream_info.rates & SND_PCM_RATE_48000)
printf(" 48000");
if (chninfo.rates & SND_PCM_RATE_88200)
if (stream_info.rates & SND_PCM_RATE_88200)
printf(" 88200");
if (chninfo.rates & SND_PCM_RATE_96000)
if (stream_info.rates & SND_PCM_RATE_96000)
printf(" 96000");
if (chninfo.rates & SND_PCM_RATE_176400)
if (stream_info.rates & SND_PCM_RATE_176400)
printf(" 176400");
if (chninfo.rates & SND_PCM_RATE_192000)
if (stream_info.rates & SND_PCM_RATE_192000)
printf(" 192000");
printf("\n");
printf(" min_rate : %i\n", chninfo.min_rate);
printf(" max_rate : %i\n", chninfo.max_rate);
printf(" min_voices : %i\n", chninfo.min_voices);
printf(" max_voices : %i\n", chninfo.max_voices);
printf(" buffer_size : %i\n", chninfo.buffer_size);
printf(" min_frag_size : %i\n", chninfo.min_fragment_size);
printf(" max_frag_size : %i\n", chninfo.max_fragment_size);
printf(" fragment_align : %i\n", chninfo.fragment_align);
printf(" fifo_size : %i\n", chninfo.fifo_size);
printf(" TBS : %i\n", chninfo.transfer_block_size);
printf(" mmap_size : %li\n", chninfo.mmap_size);
printf(" mixer_device : %i\n", chninfo.mixer_device);
printf(" mixer_eid : '%s',%i,%i\n", chninfo.mixer_eid.name, chninfo.mixer_eid.index, chninfo.mixer_eid.type);
printf(" min_rate : %i\n", stream_info.min_rate);
printf(" max_rate : %i\n", stream_info.max_rate);
printf(" min_channels : %i\n", stream_info.min_channels);
printf(" max_channels : %i\n", stream_info.max_channels);
printf(" buffer_size : %i\n", stream_info.buffer_size);
printf(" min_frag_size : %i\n", stream_info.min_fragment_size);
printf(" max_frag_size : %i\n", stream_info.max_fragment_size);
printf(" fragment_align : %i\n", stream_info.fragment_align);
printf(" fifo_size : %i\n", stream_info.fifo_size);
printf(" TBS : %i\n", stream_info.transfer_block_size);
printf(" mmap_size : %li\n", stream_info.mmap_size);
printf(" mixer_device : %i\n", stream_info.mixer_device);
printf(" mixer_eid : '%s',%i,%i\n", stream_info.mixer_eid.name, stream_info.mixer_eid.index, stream_info.mixer_eid.type);
}
void info(void)
@ -166,9 +166,9 @@ void info(void)
printf(" playback : %i\n", info.playback);
printf(" capture : %i\n", info.capture);
if (info.flags & SND_PCM_INFO_PLAYBACK)
info_channel(handle, SND_PCM_CHANNEL_PLAYBACK, "Playback");
info_channel(handle, SND_PCM_STREAM_PLAYBACK, "Playback");
if (info.flags & SND_PCM_INFO_CAPTURE)
info_channel(handle, SND_PCM_CHANNEL_CAPTURE, "Capture");
info_channel(handle, SND_PCM_STREAM_CAPTURE, "Capture");
snd_pcm_close(handle);
}

View file

@ -54,7 +54,7 @@ void print_switch(snd_ctl_t *ctl_handle, char *space, char *prefix, snd_switch_t
sw1.type = SND_SW_TYPE_LIST_ITEM;
sw1.low = sw1.high = low;
if ((err = snd_ctl_switch_read(ctl_handle, &sw1)) < 0) {
printf("Switch list item read failed for %s interface and device %i channel %i: %s\n", get_interface(sw->iface), sw->device, sw->channel, snd_strerror(err));
printf("Switch list item read failed for %s interface and device %i stream %i: %s\n", get_interface(sw->iface), sw->device, sw->stream, snd_strerror(err));
continue;
}
printf(" %s%s : '%s' [%s] {%s}\n", space, prefix, sw1.name, get_type(sw1.type), sw1.value.item);
@ -62,7 +62,7 @@ void print_switch(snd_ctl_t *ctl_handle, char *space, char *prefix, snd_switch_t
}
}
void process(snd_ctl_t *ctl_handle, char *space, char *prefix, int iface, int device, int channel)
void process(snd_ctl_t *ctl_handle, char *space, char *prefix, int iface, int device, int stream)
{
snd_switch_list_t list;
snd_switch_t sw;
@ -71,7 +71,7 @@ void process(snd_ctl_t *ctl_handle, char *space, char *prefix, int iface, int de
bzero(&list, sizeof(list));
list.iface = iface;
list.device = device;
list.channel = channel;
list.stream = stream;
if ((err = snd_ctl_switch_list(ctl_handle, &list)) < 0) {
printf("Switch listing failed for the %s interface and the device %i: %s\n", get_interface(iface), device, snd_strerror(err));
return;
@ -93,10 +93,10 @@ void process(snd_ctl_t *ctl_handle, char *space, char *prefix, int iface, int de
bzero(&sw, sizeof(sw));
sw.iface = iface;
sw.device = device;
sw.channel = channel;
sw.stream = stream;
strncpy(sw.name, list.pswitches[idx].name, sizeof(sw.name));
if ((err = snd_ctl_switch_read(ctl_handle, &sw)) < 0) {
printf("Switch read failed for the %s interface and the device %i channel %i: %s\n", get_interface(iface), device, channel, snd_strerror(err));
printf("Switch read failed for the %s interface and the device %i stream %i: %s\n", get_interface(iface), device, stream, snd_strerror(err));
continue;
}
print_switch(ctl_handle, space, prefix, &sw);
@ -131,8 +131,8 @@ int main(void)
for (idx = 0; idx < info.mixerdevs; idx++)
process(ctl_handle, " ", "Mixer", SND_CTL_IFACE_MIXER, idx, 0);
for (idx = 0; idx < info.pcmdevs; idx++) {
process(ctl_handle, " ", "PCM playback", SND_CTL_IFACE_PCM, idx, SND_PCM_CHANNEL_PLAYBACK);
process(ctl_handle, " ", "PCM capture", SND_CTL_IFACE_PCM, idx, SND_PCM_CHANNEL_CAPTURE);
process(ctl_handle, " ", "PCM playback", SND_CTL_IFACE_PCM, idx, SND_PCM_STREAM_PLAYBACK);
process(ctl_handle, " ", "PCM capture", SND_CTL_IFACE_PCM, idx, SND_PCM_STREAM_CAPTURE);
}
snd_ctl_close(ctl_handle);
}