PCM changes (record->capture)...

This commit is contained in:
Jaroslav Kysela 1999-06-12 19:23:10 +00:00
parent fd672765f4
commit dc126564c7
8 changed files with 57 additions and 57 deletions

View file

@ -40,13 +40,13 @@ int snd_ctl_switch_read(snd_ctl_t *handle, snd_switch_t * sw);
int snd_ctl_switch_write(snd_ctl_t *handle, snd_switch_t * sw);
int snd_ctl_pcm_info(snd_ctl_t *handle, int dev, snd_pcm_info_t * info);
int snd_ctl_pcm_playback_info(snd_ctl_t *handle, int dev, snd_pcm_playback_info_t * info);
int snd_ctl_pcm_record_info(snd_ctl_t *handle, int dev, snd_pcm_record_info_t * info);
int snd_ctl_pcm_capture_info(snd_ctl_t *handle, int dev, snd_pcm_capture_info_t * info);
int snd_ctl_pcm_playback_switch_list(snd_ctl_t *handle, int dev, snd_switch_list_t * list);
int snd_ctl_pcm_playback_switch_read(snd_ctl_t *handle, int dev, snd_switch_t * sw);
int snd_ctl_pcm_playback_switch_write(snd_ctl_t *handle, int dev, snd_switch_t * sw);
int snd_ctl_pcm_record_switch_list(snd_ctl_t *handle, int dev, snd_switch_list_t * list);
int snd_ctl_pcm_record_switch_read(snd_ctl_t *handle, int dev, snd_switch_t * sw);
int snd_ctl_pcm_record_switch_write(snd_ctl_t *handle, int dev, snd_switch_t * sw);
int snd_ctl_pcm_capture_switch_list(snd_ctl_t *handle, int dev, snd_switch_list_t * list);
int snd_ctl_pcm_capture_switch_read(snd_ctl_t *handle, int dev, snd_switch_t * sw);
int snd_ctl_pcm_capture_switch_write(snd_ctl_t *handle, int dev, snd_switch_t * sw);
int snd_ctl_mixer_info(snd_ctl_t *handle, int dev, snd_mixer_info_t * info);
int snd_ctl_mixer_switch_list(snd_ctl_t *handle, int dev, snd_switch_list_t *list);
int snd_ctl_mixer_switch_read(snd_ctl_t *handle, int dev, snd_switch_t * sw);

View file

@ -6,7 +6,7 @@
****************************************************************************/
#define SND_PCM_OPEN_PLAYBACK (O_WRONLY)
#define SND_PCM_OPEN_RECORD (O_RDONLY)
#define SND_PCM_OPEN_CAPTURE (O_RDONLY)
#define SND_PCM_OPEN_DUPLEX (O_RDWR)
#ifdef __cplusplus
@ -22,19 +22,19 @@ int snd_pcm_file_descriptor(snd_pcm_t *handle);
int snd_pcm_block_mode(snd_pcm_t *handle, int enable);
int snd_pcm_info(snd_pcm_t *handle, snd_pcm_info_t * info);
int snd_pcm_playback_info(snd_pcm_t *handle, snd_pcm_playback_info_t * info);
int snd_pcm_record_info(snd_pcm_t *handle, snd_pcm_record_info_t * info);
int snd_pcm_capture_info(snd_pcm_t *handle, snd_pcm_capture_info_t * info);
int snd_pcm_playback_format(snd_pcm_t *handle, snd_pcm_format_t * format);
int snd_pcm_record_format(snd_pcm_t *handle, snd_pcm_format_t * format);
int snd_pcm_capture_format(snd_pcm_t *handle, snd_pcm_format_t * format);
int snd_pcm_playback_params(snd_pcm_t *handle, snd_pcm_playback_params_t * params);
int snd_pcm_record_params(snd_pcm_t *handle, snd_pcm_record_params_t * params);
int snd_pcm_capture_params(snd_pcm_t *handle, snd_pcm_capture_params_t * params);
int snd_pcm_playback_status(snd_pcm_t *handle, snd_pcm_playback_status_t * status);
int snd_pcm_record_status(snd_pcm_t *handle, snd_pcm_record_status_t * status);
int snd_pcm_capture_status(snd_pcm_t *handle, snd_pcm_capture_status_t * status);
int snd_pcm_drain_playback(snd_pcm_t *handle);
int snd_pcm_flush_playback(snd_pcm_t *handle);
int snd_pcm_flush_record(snd_pcm_t *handle);
int snd_pcm_flush_capture(snd_pcm_t *handle);
int snd_pcm_playback_pause(snd_pcm_t *handle, int enable);
int snd_pcm_playback_time(snd_pcm_t *handle, int enable);
int snd_pcm_record_time(snd_pcm_t *handle, int enable);
int snd_pcm_capture_time(snd_pcm_t *handle, int enable);
ssize_t snd_pcm_write(snd_pcm_t *handle, const void *buffer, size_t size);
ssize_t snd_pcm_read(snd_pcm_t *handle, void *buffer, size_t size);
@ -43,7 +43,7 @@ ssize_t snd_pcm_read(snd_pcm_t *handle, void *buffer, size_t size);
#endif
#define SND_PCM_LB_OPEN_PLAYBACK 0
#define SND_PCM_LB_OPEN_RECORD 1
#define SND_PCM_LB_OPEN_CAPTURE 1
#ifdef __cplusplus
extern "C" {

View file

@ -171,7 +171,7 @@ int snd_ctl_pcm_playback_info(snd_ctl_t *handle, int dev, snd_pcm_playback_info_
return 0;
}
int snd_ctl_pcm_record_info(snd_ctl_t *handle, int dev, snd_pcm_record_info_t * info)
int snd_ctl_pcm_capture_info(snd_ctl_t *handle, int dev, snd_pcm_capture_info_t * info)
{
snd_ctl_t *ctl;
@ -180,7 +180,7 @@ int snd_ctl_pcm_record_info(snd_ctl_t *handle, int dev, snd_pcm_record_info_t *
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)
if (ioctl(ctl->fd, SND_CTL_IOCTL_PCM_CAPTURE_INFO, info) < 0)
return -errno;
return 0;
}
@ -227,7 +227,7 @@ int snd_ctl_pcm_playback_switch_write(snd_ctl_t *handle, int dev, snd_switch_t *
return 0;
}
int snd_ctl_pcm_record_switch_list(snd_ctl_t *handle, int dev, snd_switch_list_t * list)
int snd_ctl_pcm_capture_switch_list(snd_ctl_t *handle, int dev, snd_switch_list_t * list)
{
snd_ctl_t *ctl;
@ -241,7 +241,7 @@ int snd_ctl_pcm_record_switch_list(snd_ctl_t *handle, int dev, snd_switch_list_t
return 0;
}
int snd_ctl_pcm_record_switch_read(snd_ctl_t *handle, int dev, snd_switch_t * sw)
int snd_ctl_pcm_capture_switch_read(snd_ctl_t *handle, int dev, snd_switch_t * sw)
{
snd_ctl_t *ctl;
@ -255,7 +255,7 @@ int snd_ctl_pcm_record_switch_read(snd_ctl_t *handle, int dev, snd_switch_t * sw
return 0;
}
int snd_ctl_pcm_record_switch_write(snd_ctl_t *handle, int dev, snd_switch_t * sw)
int snd_ctl_pcm_capture_switch_write(snd_ctl_t *handle, int dev, snd_switch_t * sw)
{
snd_ctl_t *ctl;

View file

@ -139,14 +139,14 @@ int snd_pcm_playback_info(snd_pcm_t *handle, snd_pcm_playback_info_t * info)
return 0;
}
int snd_pcm_record_info(snd_pcm_t *handle, snd_pcm_record_info_t * info)
int snd_pcm_capture_info(snd_pcm_t *handle, snd_pcm_capture_info_t * info)
{
snd_pcm_t *pcm;
pcm = handle;
if (!pcm || !info)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_INFO, info) < 0)
if (ioctl(pcm->fd, SND_PCM_IOCTL_CAPTURE_INFO, info) < 0)
return -errno;
return 0;
}
@ -163,14 +163,14 @@ int snd_pcm_playback_format(snd_pcm_t *handle, snd_pcm_format_t * format)
return 0;
}
int snd_pcm_record_format(snd_pcm_t *handle, snd_pcm_format_t * format)
int snd_pcm_capture_format(snd_pcm_t *handle, snd_pcm_format_t * format)
{
snd_pcm_t *pcm;
pcm = handle;
if (!pcm || !format)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_FORMAT, format) < 0)
if (ioctl(pcm->fd, SND_PCM_IOCTL_CAPTURE_FORMAT, format) < 0)
return -errno;
return 0;
}
@ -187,14 +187,14 @@ int snd_pcm_playback_params(snd_pcm_t *handle, snd_pcm_playback_params_t * param
return 0;
}
int snd_pcm_record_params(snd_pcm_t *handle, snd_pcm_record_params_t * params)
int snd_pcm_capture_params(snd_pcm_t *handle, snd_pcm_capture_params_t * params)
{
snd_pcm_t *pcm;
pcm = handle;
if (!pcm || !params)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_PARAMS, params) < 0)
if (ioctl(pcm->fd, SND_PCM_IOCTL_CAPTURE_PARAMS, params) < 0)
return -errno;
return 0;
}
@ -211,14 +211,14 @@ int snd_pcm_playback_status(snd_pcm_t *handle, snd_pcm_playback_status_t * statu
return 0;
}
int snd_pcm_record_status(snd_pcm_t *handle, snd_pcm_record_status_t * status)
int snd_pcm_capture_status(snd_pcm_t *handle, snd_pcm_capture_status_t * status)
{
snd_pcm_t *pcm;
pcm = handle;
if (!pcm || !status)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_STATUS, status) < 0)
if (ioctl(pcm->fd, SND_PCM_IOCTL_CAPTURE_STATUS, status) < 0)
return -errno;
return 0;
}
@ -247,14 +247,14 @@ int snd_pcm_flush_playback(snd_pcm_t *handle)
return 0;
}
int snd_pcm_flush_record(snd_pcm_t *handle)
int snd_pcm_flush_capture(snd_pcm_t *handle)
{
snd_pcm_t *pcm;
pcm = handle;
if (!pcm)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_FLUSH_RECORD) < 0)
if (ioctl(pcm->fd, SND_PCM_IOCTL_FLUSH_CAPTURE) < 0)
return -errno;
return 0;
}
@ -283,14 +283,14 @@ int snd_pcm_playback_time(snd_pcm_t *handle, int enable)
return 0;
}
int snd_pcm_record_time(snd_pcm_t *handle, int enable)
int snd_pcm_capture_time(snd_pcm_t *handle, int enable)
{
snd_pcm_t *pcm;
pcm = handle;
if (!pcm)
return -EINVAL;
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_TIME, &enable) < 0)
if (ioctl(pcm->fd, SND_PCM_IOCTL_CAPTURE_TIME, &enable) < 0)
return -errno;
return 0;
}

View file

@ -48,7 +48,7 @@ int snd_pcm_loopback_open(snd_pcm_loopback_t **handle, int card, int device, int
if (card < 0 || card >= SND_CARDS)
return -EINVAL;
sprintf(filename, SND_FILE_PCM_LB, card, device,
mode == SND_PCM_LB_OPEN_RECORD ? "r" : "p");
mode == SND_PCM_LB_OPEN_CAPTURE ? "r" : "p");
if ((fd = open(filename, mode)) < 0) {
snd_card_load(card);
if ((fd = open(filename, mode)) < 0)

View file

@ -14,14 +14,14 @@ static char *xitoa(int aaa)
/*
* This small demo program can be used for measuring latency between
* record and playback. This latency is measured from driver (diff when
* playback and record was started). Scheduler is set to SCHED_RR.
* capture and playback. This latency is measured from driver (diff when
* playback and capture was started). Scheduler is set to SCHED_RR.
*
* Used format is 44100Hz, Signed Little Endian 16-bit, Stereo.
*
* Program begins with 128-byte fragment (about 726us) and step is 32-byte
* until playback without underruns is reached. This program starts playback
* after two fragments are recorded (teoretical latency is 1452us by 128-byte
* after two fragments are captureed (teoretical latency is 1452us by 128-byte
* fragment).
*/
@ -38,7 +38,7 @@ void setformat(void *phandle, void *rhandle)
printf("Playback format error: %s\n", snd_strerror(err));
exit(0);
}
if ((err = snd_pcm_record_format(rhandle, &format)) < 0) {
if ((err = snd_pcm_capture_format(rhandle, &format)) < 0) {
printf("Record format error: %s\n", snd_strerror(err));
exit(0);
}
@ -46,7 +46,7 @@ void setformat(void *phandle, void *rhandle)
printf("Playback time error: %s\n", snd_strerror(err));
exit(0);
}
if ((err = snd_pcm_record_time(rhandle, 1)) < 0) {
if ((err = snd_pcm_capture_time(rhandle, 1)) < 0) {
printf("Record time error: %s\n", snd_strerror(err));
exit(0);
}
@ -56,15 +56,15 @@ int setparams(void *phandle, void *rhandle, int *fragmentsize)
{
int err, step = 4;
snd_pcm_playback_info_t pinfo;
snd_pcm_record_info_t rinfo;
snd_pcm_capture_info_t rinfo;
snd_pcm_playback_params_t pparams;
snd_pcm_record_params_t rparams;
snd_pcm_capture_params_t rparams;
if ((err = snd_pcm_playback_info(phandle, &pinfo)) < 0) {
printf("Playback info error: %s\n", snd_strerror(err));
exit(0);
}
if ((err = snd_pcm_record_info(rhandle, &rinfo)) < 0) {
if ((err = snd_pcm_capture_info(rhandle, &rinfo)) < 0) {
printf("Record info error: %s\n", snd_strerror(err));
exit(0);
}
@ -96,7 +96,7 @@ int setparams(void *phandle, void *rhandle, int *fragmentsize)
bzero(&rparams, sizeof(rparams));
rparams.fragment_size = *fragmentsize;
rparams.fragments_min = 1; /* wakeup if at least one fragment is ready */
if ((err = snd_pcm_record_params(rhandle, &rparams)) < 0) {
if ((err = snd_pcm_capture_params(rhandle, &rparams)) < 0) {
*fragmentsize += step;
continue;
}
@ -122,7 +122,7 @@ int playbackunderrun(void *phandle)
return pstatus.underrun;
}
void recordfragment(void *rhandle, char *buffer, int index, int fragmentsize)
void capturefragment(void *rhandle, char *buffer, int index, int fragmentsize)
{
int err;
@ -184,14 +184,14 @@ int main(void)
int err, fragmentsize = 0;
int ridx, pidx, size, ok;
snd_pcm_playback_status_t pstatus;
snd_pcm_record_status_t rstatus;
snd_pcm_capture_status_t rstatus;
setscheduler();
if ((err = snd_pcm_open(&phandle, pcard, pdevice, SND_PCM_OPEN_PLAYBACK)) < 0) {
printf("Playback open error: %s\n", snd_strerror(err));
return 0;
}
if ((err = snd_pcm_open(&rhandle, rcard, rdevice, SND_PCM_OPEN_RECORD)) < 0) {
if ((err = snd_pcm_open(&rhandle, rcard, rdevice, SND_PCM_OPEN_CAPTURE)) < 0) {
printf("Record open error: %s\n", snd_strerror(err));
return 0;
}
@ -201,9 +201,9 @@ int main(void)
break;
ok = 1;
ridx = pidx = size = 0;
recordfragment(rhandle, buffer, ridx++, fragmentsize);
recordfragment(rhandle, buffer, ridx++, fragmentsize);
if ((err = snd_pcm_record_status(rhandle, &rstatus)) < 0) {
capturefragment(rhandle, buffer, ridx++, fragmentsize);
capturefragment(rhandle, buffer, ridx++, fragmentsize);
if ((err = snd_pcm_capture_status(rhandle, &rstatus)) < 0) {
printf("Record status error: %s\n", snd_strerror(err));
exit(0);
}
@ -213,7 +213,7 @@ int main(void)
pidx += 2;
pidx %= 2;
while (ok && size < 3 * 176400) { /* 30 seconds */
recordfragment(rhandle, buffer, ridx++, fragmentsize);
capturefragment(rhandle, buffer, ridx++, fragmentsize);
ridx %= 2;
playfragment(phandle, buffer, pidx++, fragmentsize);
size += fragmentsize;
@ -225,7 +225,7 @@ int main(void)
printf("Playback status error: %s\n", snd_strerror(err));
exit(0);
}
snd_pcm_flush_record(rhandle);
snd_pcm_flush_capture(rhandle);
snd_pcm_flush_playback(phandle);
if (ok && !playbackunderrun(phandle) > 0) {
printf("Playback OK!!!\n");

View file

@ -24,7 +24,7 @@ void setformat(void *phandle, void *rhandle)
if ((err = snd_pcm_playback_format(phandle, &format)) < 0) {
printf("Playback format error: %s\n", snd_strerror(err));
}
if ((err = snd_pcm_record_format(rhandle, &format)) < 0) {
if ((err = snd_pcm_capture_format(rhandle, &format)) < 0) {
printf("Record format error: %s\n", snd_strerror(err));
}
}
@ -39,7 +39,7 @@ void method1(void)
printf("Playback open error: %s\n", snd_strerror(err));
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_CAPTURE)) < 0) {
printf("Record open error: %s\n", snd_strerror(err));
return;
}
@ -74,7 +74,7 @@ void method2(void)
printf("Playback open error: %s\n", snd_strerror(err));
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_CAPTURE)) < 0) {
printf("Record open error: %s\n", snd_strerror(err));
return;
}
@ -86,7 +86,7 @@ void method2(void)
return;
}
printf("done...\n");
if ((err = snd_pcm_flush_record(rhandle)) < 0) {
if ((err = snd_pcm_flush_capture(rhandle)) < 0) {
printf("Record flush error: %s\n", snd_strerror(err));
return;
}
@ -127,7 +127,7 @@ void method3(void)
return;
}
printf("done...\n");
if ((err = snd_pcm_flush_record(handle)) < 0) {
if ((err = snd_pcm_flush_capture(handle)) < 0) {
printf("Record flush error: %s\n", snd_strerror(err));
return;
}

View file

@ -40,7 +40,7 @@ const char *get_interface(void)
case 2:
return "PCM playback";
case 3:
return "PCM record";
return "PCM capture";
case 4:
return "rawmidi output";
case 5:
@ -60,7 +60,7 @@ int switch_list(snd_switch_list_t *list)
case 2:
return snd_ctl_pcm_playback_switch_list(ctl_handle, sw_device, list);
case 3:
return snd_ctl_pcm_record_switch_list(ctl_handle, sw_device, list);
return snd_ctl_pcm_capture_switch_list(ctl_handle, sw_device, list);
case 4:
return snd_ctl_rawmidi_output_switch_list(ctl_handle, sw_device, list);
case 5:
@ -80,7 +80,7 @@ int switch_read(snd_switch_t *sw)
case 2:
return snd_ctl_pcm_playback_switch_read(ctl_handle, sw_device, sw);
case 3:
return snd_ctl_pcm_record_switch_write(ctl_handle, sw_device, sw);
return snd_ctl_pcm_capture_switch_write(ctl_handle, sw_device, sw);
case 4:
return snd_ctl_rawmidi_output_switch_read(ctl_handle, sw_device, sw);
case 5:
@ -100,7 +100,7 @@ int switch_write(snd_switch_t *sw)
case 2:
return snd_ctl_pcm_playback_switch_write(ctl_handle, sw_device, sw);
case 3:
return snd_ctl_pcm_record_switch_write(ctl_handle, sw_device, sw);
return snd_ctl_pcm_capture_switch_write(ctl_handle, sw_device, sw);
case 4:
return snd_ctl_rawmidi_output_switch_write(ctl_handle, sw_device, sw);
case 5:
@ -195,7 +195,7 @@ int main(void)
process(" ", "Mixer", 1, idx);
for (idx = 0; idx < info.pcmdevs; idx++) {
process(" ", "PCM playback", 2, idx);
process(" ", "PCM record", 3, idx);
process(" ", "PCM capture", 3, idx);
}
snd_ctl_close(ctl_handle);
}