#include #include #include #include #include #include #include static void print_audio_info(struct audio_device *d) { struct audio_channel *c; printf("name=%s\n", d->name); printf("desc=%s\n", d->desc); printf("unit=%d\n", d->unit); printf("devnode=%s\n", d->devnode); printf("is_default=%d\n", d->is_default); printf("format=%#08x\n", d->format); printf("rate=%d\n", d->rate); printf("channels=%d\n", d->channels); if (d->mixer != NULL) printf("mixer=%s\n", d->mixer->name); printf("caps=%#08x\n", d->caps); if (d->caps & PCM_CAP_TRIGGER) printf("\tPCM_CAP_TRIGGER (Trigger start)\n"); if (d->caps & PCM_CAP_MMAP) printf("\tPCM_CAP_MMAP (Memory mapping)\n"); if (d->caps & PCM_CAP_MULTI) printf("\tPCM_CAP_MULTI (Multiple open)\n"); if (d->caps & PCM_CAP_INPUT) printf("\tPCM_CAP_INPUT (Recording)\n"); if (d->caps & PCM_CAP_OUTPUT) printf("\tPCM_CAP_OUTPUT (Playback)\n"); if (d->caps & PCM_CAP_DUPLEX) printf("\tPCM_CAP_DUPLEX (Duplex)\n"); if (d->caps & PCM_CAP_VIRTUAL) printf("\tPCM_CAP_VIRTUAL (Virtual device)\n"); if (d->caps & PCM_CAP_ANALOGIN) printf("\tPCM_CAP_ANALOGIN (Analog input)\n"); if (d->caps & PCM_CAP_ANALOGOUT) printf("\tPCM_CAP_ANALOGOUT (Analog output)\n"); if (d->caps & PCM_CAP_DIGITALIN) printf("\tPCM_CAP_DIGITALIN (Digital input)\n"); if (d->caps & PCM_CAP_DIGITALOUT) printf("\tPCM_CAP_DIGITALOUT (Digital output)\n"); if (d->caps & PCM_CAP_REALTIME) printf("\tPCM_CAP_REALTIME (High precision latency control)\n"); printf("open_mode=%#04x\n", d->open_mode); if (d->open_mode & AUDIO_REC) printf("\tAUDIO_REC (Recording)\n"); if (d->open_mode & AUDIO_PLAY) printf("\tAUDIO_PLAY (Playback)\n"); if (d->open_mode & AUDIO_EXCL) printf("\tAUDIO_EXCL (Exclusive access)\n"); if (d->open_mode & AUDIO_NBIO) printf("\tAUDIO_NBIO (Non-blocking IO)\n"); if (d->open_mode & AUDIO_MMAP) printf("\tAUDIO_MMAP (Memory mapped IO)\n"); if (d->chan_rec) { c = d->chan_rec; printf("chan_rec=%s\n", c->name); printf("\tunit=%d\n", c->unit); printf("\trate=%d\n", c->rate); printf("\tformat=%#08x\n", c->format); printf("\tmin_rate=%d\n", c->min_rate); printf("\tmax_rate=%d\n", c->max_rate); printf("\tcaps=%#08x\n", c->caps); printf("\tbufsz=%ld\n", c->bufsz); printf("\tsample_size=%ld\n", c->sample_size); printf("\tframe_size=%ld\n", c->frame_size); printf("\tframe_total=%d\n", c->frame_total); } if (d->chan_play) { c = d->chan_play; printf("chan_play=%s\n", c->name); printf("\tunit=%d\n", c->unit); printf("\trate=%d\n", c->rate); printf("\tformat=%#08x\n", c->format); printf("\tmin_rate=%d\n", c->min_rate); printf("\tmax_rate=%d\n", c->max_rate); printf("\tcaps=%#08x\n", c->caps); printf("\tbufsz=%ld\n", c->bufsz); printf("\tsample_size=%ld\n", c->sample_size); printf("\tframe_size=%ld\n", c->frame_size); printf("\tframe_total=%d\n", c->frame_total); } } int main(int argc, char *argv[]) { struct audio_device *d; d = audio_open(argv[1], AUDIO_REC | AUDIO_PLAY | AUDIO_MMAP, AFMT_S32_NE, 2, 48000); if (d == NULL) err(1, "audio_open"); print_audio_info(d); for (;;) { char buf[d->chan_play->bufsz]; ssize_t n; n = read(STDIN_FILENO, buf, sizeof(buf)); if (n < 0) err(1, "read"); n = audio_write(d, buf, sizeof(buf)); } audio_close(d); return (0); }