Lines Matching refs:pcm

181 static int oops(struct pcm *pcm, int e, const char *fmt, ...);
325 int param_set_hw_refine(struct pcm *pcm, struct snd_pcm_hw_params *params) in param_set_hw_refine() argument
327 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_REFINE, params)) { in param_set_hw_refine()
334 int param_set_hw_params(struct pcm *pcm, struct snd_pcm_hw_params *params) in param_set_hw_params() argument
336 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_PARAMS, params)) { in param_set_hw_params()
339 pcm->hw_p = params; in param_set_hw_params()
343 int param_set_sw_params(struct pcm *pcm, struct snd_pcm_sw_params *sparams) in param_set_sw_params() argument
345 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_SW_PARAMS, sparams)) { in param_set_sw_params()
348 pcm->sw_p = sparams; in param_set_sw_params()
372 const char* pcm_error(struct pcm *pcm) in pcm_error() argument
374 return pcm->error; in pcm_error()
377 static int oops(struct pcm *pcm, int e, const char *fmt, ...) in oops() argument
383 vsnprintf(pcm->error, PCM_ERROR_MAX, fmt, ap); in oops()
385 sz = strnlen(pcm->error, PCM_ERROR_MAX); in oops()
388 snprintf(pcm->error + sz, PCM_ERROR_MAX - sz, in oops()
393 long pcm_avail(struct pcm *pcm) in pcm_avail() argument
395 struct snd_pcm_sync_ptr *sync_ptr = pcm->sync_ptr; in pcm_avail()
396 if (pcm->flags & DEBUG_ON) { in pcm_avail()
399 pcm->buffer_size, in pcm_avail()
402 if (pcm->flags & PCM_IN) { in pcm_avail()
405 avail += pcm->sw_p->boundary; in pcm_avail()
408 …>s.status.hw_ptr - sync_ptr->c.control.appl_ptr + ((pcm->flags & PCM_MONO) ? pcm->buffer_size/2 : in pcm_avail()
410 avail += pcm->sw_p->boundary; in pcm_avail()
411 else if ((unsigned long) avail >= pcm->sw_p->boundary) in pcm_avail()
412 avail -= pcm->sw_p->boundary; in pcm_avail()
417 int sync_ptr(struct pcm *pcm) in sync_ptr() argument
420 err = ioctl(pcm->fd, SNDRV_PCM_IOCTL_SYNC_PTR, pcm->sync_ptr); in sync_ptr()
430 int mmap_buffer(struct pcm *pcm) in mmap_buffer() argument
436 int channels = (pcm->flags & PCM_MONO) ? 1 : 2; in mmap_buffer()
438 size = pcm->buffer_size; in mmap_buffer()
439 if (pcm->flags & DEBUG_ON) in mmap_buffer()
441 pcm->addr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, in mmap_buffer()
442 pcm->fd, 0); in mmap_buffer()
443 if (pcm->addr) in mmap_buffer()
455 u_int8_t *dst_address(struct pcm *pcm) in dst_address() argument
458 struct snd_pcm_sync_ptr *sync_ptr = pcm->sync_ptr; in dst_address()
461 …appl_ptr = (pcm->flags & PCM_MONO) ? sync_ptr->c.control.appl_ptr*2 : sync_ptr->c.control.appl_ptr… in dst_address()
462 pcm_offset = (appl_ptr % (unsigned long)pcm->buffer_size); in dst_address()
463 return pcm->addr + pcm_offset; in dst_address()
467 int mmap_transfer(struct pcm *pcm, void *data, unsigned offset, in mmap_transfer() argument
470 struct snd_pcm_sync_ptr *sync_ptr = pcm->sync_ptr; in mmap_transfer()
474 int channels = (pcm->flags & PCM_MONO) ? 1 : 2; in mmap_transfer()
476 dst_addr = dst_address(pcm); in mmap_transfer()
488 int mmap_transfer_capture(struct pcm *pcm, void *data, unsigned offset, in mmap_transfer_capture() argument
491 struct snd_pcm_sync_ptr *sync_ptr = pcm->sync_ptr; in mmap_transfer_capture()
496 int channels = (pcm->flags & PCM_MONO) ? 1 : 2; in mmap_transfer_capture()
497 …unsigned int tmp = (pcm->flags & PCM_MONO) ? sync_ptr->c.control.appl_ptr*2 : sync_ptr->c.control.… in mmap_transfer_capture()
499 pcm_offset = (tmp % (unsigned long)pcm->buffer_size); in mmap_transfer_capture()
501 src_addr = pcm->addr + pcm_offset; in mmap_transfer_capture()
512 int pcm_prepare(struct pcm *pcm) in pcm_prepare() argument
514 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_PREPARE)) { in pcm_prepare()
518 pcm->running = 1; in pcm_prepare()
522 static int pcm_write_mmap(struct pcm *pcm, void *data, unsigned count) in pcm_write_mmap() argument
528 frames = (pcm->flags & PCM_MONO) ? (count / 2) : (count / 4); in pcm_write_mmap()
530 pcm->sync_ptr->flags = SNDRV_PCM_SYNC_PTR_APPL | SNDRV_PCM_SYNC_PTR_AVAIL_MIN; in pcm_write_mmap()
531 err = sync_ptr(pcm); in pcm_write_mmap()
535 pcm->underruns++; in pcm_write_mmap()
536 pcm->running = 0; in pcm_write_mmap()
537 pcm_prepare(pcm); in pcm_write_mmap()
539 pcm->sync_ptr->c.control.appl_ptr += frames; in pcm_write_mmap()
540 pcm->sync_ptr->flags = 0; in pcm_write_mmap()
542 err = sync_ptr(pcm); in pcm_write_mmap()
546 pcm->underruns++; in pcm_write_mmap()
547 pcm->running = 0; in pcm_write_mmap()
548 pcm_prepare(pcm); in pcm_write_mmap()
550 bytes_written = pcm->sync_ptr->c.control.appl_ptr - pcm->sync_ptr->s.status.hw_ptr; in pcm_write_mmap()
551 if ((bytes_written >= pcm->sw_p->start_threshold) && (!pcm->start)) { in pcm_write_mmap()
552 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_START)) { in pcm_write_mmap()
557 pcm->underruns++; in pcm_write_mmap()
558 pcm->running = 0; in pcm_write_mmap()
559 pcm_prepare(pcm); in pcm_write_mmap()
566 pcm->start = 1; in pcm_write_mmap()
572 static int pcm_write_nmmap(struct pcm *pcm, void *data, unsigned count) in pcm_write_nmmap() argument
575 int channels = (pcm->flags & PCM_MONO) ? 1 : ((pcm->flags & PCM_5POINT1)? 6 : 2 ); in pcm_write_nmmap()
577 if (pcm->flags & PCM_IN) in pcm_write_nmmap()
583 if (!pcm->running) { in pcm_write_nmmap()
584 if (pcm_prepare(pcm)) in pcm_write_nmmap()
587 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)) { in pcm_write_nmmap()
591 pcm->underruns++; in pcm_write_nmmap()
592 pcm->running = 0; in pcm_write_nmmap()
597 if (pcm->flags & DEBUG_ON) in pcm_write_nmmap()
603 int pcm_write(struct pcm *pcm, void *data, unsigned count) in pcm_write() argument
605 if (pcm->flags & PCM_MMAP) in pcm_write()
606 return pcm_write_mmap(pcm, data, count); in pcm_write()
608 return pcm_write_nmmap(pcm, data, count); in pcm_write()
611 int pcm_read(struct pcm *pcm, void *data, unsigned count) in pcm_read() argument
615 if (!(pcm->flags & PCM_IN)) in pcm_read()
619 if (pcm->flags & PCM_MONO) { in pcm_read()
621 } else if (pcm->flags & PCM_QUAD) { in pcm_read()
623 } else if (pcm->flags & PCM_5POINT1) { in pcm_read()
630 if (!pcm->running) { in pcm_read()
631 if (pcm_prepare(pcm)) in pcm_read()
633 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_START)) { in pcm_read()
637 pcm->running = 1; in pcm_read()
639 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_READI_FRAMES, &x)) { in pcm_read()
643 pcm->underruns++; in pcm_read()
644 pcm->running = 0; in pcm_read()
654 static struct pcm bad_pcm = {
658 static int enable_timer(struct pcm *pcm) { in enable_timer() argument
660 pcm->timer_fd = open("/dev/snd/timer", O_RDWR | O_NONBLOCK); in enable_timer()
661 if (pcm->timer_fd < 0) { in enable_timer()
662 close(pcm->fd); in enable_timer()
669 if (ioctl(pcm->timer_fd, SNDRV_TIMER_IOCTL_TREAD, &arg) < 0) { in enable_timer()
675 sel.id.card = pcm->card_no; in enable_timer()
676 sel.id.device = pcm->device_no; in enable_timer()
677 if (pcm->flags & PCM_IN) in enable_timer()
682 if (pcm->flags & DEBUG_ON) { in enable_timer()
689 if (ioctl(pcm->timer_fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0) { in enable_timer()
691 close(pcm->timer_fd); in enable_timer()
692 close(pcm->fd); in enable_timer()
700 if (ioctl(pcm->timer_fd, SNDRV_TIMER_IOCTL_PARAMS, &timer_param)< 0) { in enable_timer()
703 if (ioctl(pcm->timer_fd, SNDRV_TIMER_IOCTL_START) < 0) { in enable_timer()
704 close(pcm->timer_fd); in enable_timer()
710 static int disable_timer(struct pcm *pcm) { in disable_timer() argument
711 if (pcm == &bad_pcm) in disable_timer()
713 if (ioctl(pcm->timer_fd, SNDRV_TIMER_IOCTL_STOP) < 0) in disable_timer()
715 return close(pcm->timer_fd); in disable_timer()
718 int pcm_close(struct pcm *pcm) in pcm_close() argument
720 if (pcm == &bad_pcm) in pcm_close()
723 if (pcm->flags & PCM_MMAP) { in pcm_close()
724 disable_timer(pcm); in pcm_close()
725 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_DROP) < 0) { in pcm_close()
729 if (munmap(pcm->addr, pcm->buffer_size)) in pcm_close()
732 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_FREE) < 0) { in pcm_close()
737 if (pcm->fd >= 0) in pcm_close()
738 close(pcm->fd); in pcm_close()
739 pcm->running = 0; in pcm_close()
740 pcm->buffer_size = 0; in pcm_close()
741 pcm->fd = -1; in pcm_close()
742 if (pcm->sw_p) in pcm_close()
743 free(pcm->sw_p); in pcm_close()
744 if (pcm->hw_p) in pcm_close()
745 free(pcm->hw_p); in pcm_close()
746 if (pcm->sync_ptr) in pcm_close()
747 free(pcm->sync_ptr); in pcm_close()
748 free(pcm); in pcm_close()
752 struct pcm *pcm_open(unsigned flags, char *device) in pcm_open()
755 struct pcm *pcm; in pcm_open() local
768 pcm = calloc(1, sizeof(struct pcm)); in pcm_open()
769 if (!pcm) in pcm_open()
775 free(pcm); in pcm_open()
783 pcm->card_no = atoi(tmp); in pcm_open()
786 pcm->device_no = atoi(tmp); in pcm_open()
788 if (pcm->device_no > 9) in pcm_open()
797 pcm->card_no = atoi(tmp); in pcm_open()
800 pcm->device_no = atoi(tmp); in pcm_open()
802 if (pcm->device_no > 9) in pcm_open()
808 if (pcm->flags & DEBUG_ON) in pcm_open()
811 pcm->sync_ptr = calloc(1, sizeof(struct snd_pcm_sync_ptr)); in pcm_open()
812 if (!pcm->sync_ptr) { in pcm_open()
813 free(pcm); in pcm_open()
816 pcm->flags = flags; in pcm_open()
818 pcm->fd = open(dname, O_RDWR|O_NONBLOCK); in pcm_open()
819 if (pcm->fd < 0) { in pcm_open()
820 free(pcm->sync_ptr); in pcm_open()
821 free(pcm); in pcm_open()
826 if (fcntl(pcm->fd, F_SETFL, fcntl(pcm->fd, F_GETFL) & in pcm_open()
828 close(pcm->fd); in pcm_open()
829 free(pcm->sync_ptr); in pcm_open()
830 free(pcm); in pcm_open()
835 if (pcm->flags & PCM_MMAP) in pcm_open()
836 enable_timer(pcm); in pcm_open()
838 if (pcm->flags & DEBUG_ON) in pcm_open()
840 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_INFO, &info)) { in pcm_open()
843 if (pcm->flags & DEBUG_ON) in pcm_open()
846 return pcm; in pcm_open()
849 int pcm_ready(struct pcm *pcm) in pcm_ready() argument
851 return pcm->fd >= 0; in pcm_ready()