mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-12-16 08:56:42 -05:00
Some fixes...
This commit is contained in:
parent
776b186952
commit
deeb7a35d5
1 changed files with 13 additions and 4 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "../include/asoundlib.h"
|
#include "../include/asoundlib.h"
|
||||||
|
|
||||||
#define LATENCY_LIMIT 8192 /* in bytes */
|
#define LATENCY_LIMIT 8192 /* in bytes */
|
||||||
|
|
@ -67,7 +68,7 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue)
|
||||||
params.channel = SND_PCM_CHANNEL_PLAYBACK;
|
params.channel = SND_PCM_CHANNEL_PLAYBACK;
|
||||||
params.mode = SND_PCM_MODE_STREAM;
|
params.mode = SND_PCM_MODE_STREAM;
|
||||||
params.format.interleave = 1;
|
params.format.interleave = 1;
|
||||||
params.format.format = SND_PCM_SFMT_S16_LE;
|
params.format.format = SND_PCM_SFMT_S16_BE; // S16_LE;
|
||||||
params.format.voices = 2;
|
params.format.voices = 2;
|
||||||
params.format.rate = 44100;
|
params.format.rate = 44100;
|
||||||
params.start_mode = SND_PCM_START_GO;
|
params.start_mode = SND_PCM_START_GO;
|
||||||
|
|
@ -82,6 +83,7 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue)
|
||||||
if (*queue > LATENCY_LIMIT)
|
if (*queue > LATENCY_LIMIT)
|
||||||
return -1;
|
return -1;
|
||||||
again = 0;
|
again = 0;
|
||||||
|
params.channel = SND_PCM_CHANNEL_PLAYBACK;
|
||||||
params.buf.stream.queue_size = *queue;
|
params.buf.stream.queue_size = *queue;
|
||||||
if ((err = snd_pcm_plugin_params(phandle, ¶ms)) < 0) {
|
if ((err = snd_pcm_plugin_params(phandle, ¶ms)) < 0) {
|
||||||
printf("Playback params error: %s\n", snd_strerror(err));
|
printf("Playback params error: %s\n", snd_strerror(err));
|
||||||
|
|
@ -96,14 +98,14 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue)
|
||||||
psetup.mode = SND_PCM_MODE_STREAM;
|
psetup.mode = SND_PCM_MODE_STREAM;
|
||||||
psetup.channel = SND_PCM_CHANNEL_PLAYBACK;
|
psetup.channel = SND_PCM_CHANNEL_PLAYBACK;
|
||||||
if ((err = snd_pcm_plugin_setup(phandle, &psetup)) < 0) {
|
if ((err = snd_pcm_plugin_setup(phandle, &psetup)) < 0) {
|
||||||
printf("Playback params error: %s\n", snd_strerror(err));
|
printf("Playback setup error: %s\n", snd_strerror(err));
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
bzero(&csetup, sizeof(csetup));
|
bzero(&csetup, sizeof(csetup));
|
||||||
csetup.mode = SND_PCM_MODE_STREAM;
|
csetup.mode = SND_PCM_MODE_STREAM;
|
||||||
csetup.channel = SND_PCM_CHANNEL_CAPTURE;
|
csetup.channel = SND_PCM_CHANNEL_CAPTURE;
|
||||||
if ((err = snd_pcm_plugin_setup(chandle, &csetup)) < 0) {
|
if ((err = snd_pcm_plugin_setup(chandle, &csetup)) < 0) {
|
||||||
printf("Capture params error: %s\n", snd_strerror(err));
|
printf("Capture setup error: %s\n", snd_strerror(err));
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if (psetup.buf.stream.queue_size > *queue) {
|
if (psetup.buf.stream.queue_size > *queue) {
|
||||||
|
|
@ -146,6 +148,7 @@ void showstat(snd_pcm_t *handle, int channel, snd_pcm_channel_status_t *rstatus)
|
||||||
printf("%s:\n", str);
|
printf("%s:\n", str);
|
||||||
printf(" status = %i\n", status.status);
|
printf(" status = %i\n", status.status);
|
||||||
printf(" position = %u\n", status.scount);
|
printf(" position = %u\n", status.scount);
|
||||||
|
if (rstatus)
|
||||||
*rstatus = status;
|
*rstatus = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,6 +188,8 @@ long readbuf(snd_pcm_t *handle, char *buf, long len)
|
||||||
long r;
|
long r;
|
||||||
|
|
||||||
r = snd_pcm_plugin_read(handle, buf, len);
|
r = snd_pcm_plugin_read(handle, buf, len);
|
||||||
|
// printf("read = %li\n", r);
|
||||||
|
// showstat(handle, SND_PCM_CHANNEL_CAPTURE, NULL);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,8 +199,12 @@ long writebuf(snd_pcm_t *handle, char *buf, long len)
|
||||||
|
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
r = snd_pcm_plugin_write(handle, buf, len);
|
r = snd_pcm_plugin_write(handle, buf, len);
|
||||||
|
if (r == -EAGAIN)
|
||||||
|
continue;
|
||||||
|
// printf("write = %li\n", r);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
// showstat(handle, SND_PCM_CHANNEL_PLAYBACK, NULL);
|
||||||
buf += r;
|
buf += r;
|
||||||
len -= r;
|
len -= r;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue