aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Wilson2011-10-13 15:57:25 -0500
committerSimon Wilson2011-10-14 11:39:00 -0500
commite9942c8b1fab1cea4836b5af2dd59a1bf0ad411d (patch)
tree038f26884056835eff415093b37a7bf773bc2b27
parent621047309242d04a6186230e7a337de8642ec754 (diff)
downloadplatform-external-tinyalsa-e9942c8b1fab1cea4836b5af2dd59a1bf0ad411d.tar.gz
platform-external-tinyalsa-e9942c8b1fab1cea4836b5af2dd59a1bf0ad411d.tar.xz
platform-external-tinyalsa-e9942c8b1fab1cea4836b5af2dd59a1bf0ad411d.zip
Update to latest tinyalsa
6be28f1 pcm: add mmap playback and no periodic IRQ support. fa0697e tinyplay: fix segfault caused by missing device argument Change-Id: I22cf8f01eba21e42b4fa43cc5fd9edd2826f44fa
-rw-r--r--include/tinyalsa/asoundlib.h25
-rw-r--r--pcm.c343
-rw-r--r--tinyplay.c7
3 files changed, 365 insertions, 10 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index 2e8c3e0..3c86c84 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -43,6 +43,19 @@ struct pcm;
43 43
44#define PCM_OUT 0x00000000 44#define PCM_OUT 0x00000000
45#define PCM_IN 0x10000000 45#define PCM_IN 0x10000000
46#define PCM_MMAP 0x00000001
47#define PCM_NOIRQ 0x00000002
48
49/* PCM runtime states */
50#define PCM_STATE_OPEN 0
51#define PCM_STATE_SETUP 1
52#define PCM_STATE_PREPARED 2
53#define PCM_STATE_RUNNING 3
54#define PCM_STATE_XRUN 4
55#define PCM_STATE_DRAINING 5
56#define PCM_STATE_PAUSED 6
57#define PCM_STATE_SUSPENDED 7
58#define PCM_STATE_DISCONNECTED 8
46 59
47/* Bit formats */ 60/* Bit formats */
48enum pcm_format { 61enum pcm_format {
@@ -99,10 +112,12 @@ int pcm_set_config(struct pcm *pcm, struct pcm_config *config);
99/* Returns a human readable reason for the last error */ 112/* Returns a human readable reason for the last error */
100const char *pcm_get_error(struct pcm *pcm); 113const char *pcm_get_error(struct pcm *pcm);
101 114
102/* Returns the buffer size (int bytes) that should be used for pcm_write. 115/* Returns the buffer size (int frames) that should be used for pcm_write.
103 * This will be 1/2 of the actual fifo size. 116 * This will be 1/2 of the actual fifo size.
104 */ 117 */
105unsigned int pcm_get_buffer_size(struct pcm *pcm); 118unsigned int pcm_get_buffer_size(struct pcm *pcm);
119unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames);
120unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int frames);
106 121
107/* Returns the pcm latency in ms */ 122/* Returns the pcm latency in ms */
108unsigned int pcm_get_latency(struct pcm *pcm); 123unsigned int pcm_get_latency(struct pcm *pcm);
@@ -123,6 +138,14 @@ int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail,
123int pcm_write(struct pcm *pcm, void *data, unsigned int count); 138int pcm_write(struct pcm *pcm, void *data, unsigned int count);
124int pcm_read(struct pcm *pcm, void *data, unsigned int count); 139int pcm_read(struct pcm *pcm, void *data, unsigned int count);
125 140
141/*
142 * mmap() support.
143 */
144int pcm_mmap_write(struct pcm *pcm, void *data, unsigned int count);
145int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset,
146 unsigned int *frames);
147int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames);
148
126/* Start and stop a PCM channel that doesn't transfer data */ 149/* Start and stop a PCM channel that doesn't transfer data */
127int pcm_start(struct pcm *pcm); 150int pcm_start(struct pcm *pcm);
128int pcm_stop(struct pcm *pcm); 151int pcm_stop(struct pcm *pcm);
diff --git a/pcm.c b/pcm.c
index 300def5..d12e5da 100644
--- a/pcm.c
+++ b/pcm.c
@@ -33,10 +33,12 @@
33#include <string.h> 33#include <string.h>
34#include <errno.h> 34#include <errno.h>
35#include <unistd.h> 35#include <unistd.h>
36#include <poll.h>
36 37
37#include <sys/ioctl.h> 38#include <sys/ioctl.h>
38#include <sys/mman.h> 39#include <sys/mman.h>
39#include <sys/time.h> 40#include <sys/time.h>
41#include <limits.h>
40 42
41#include <linux/ioctl.h> 43#include <linux/ioctl.h>
42#define __force 44#define __force
@@ -47,6 +49,7 @@
47#include <tinyalsa/asoundlib.h> 49#include <tinyalsa/asoundlib.h>
48 50
49#define PARAM_MAX SNDRV_PCM_HW_PARAM_LAST_INTERVAL 51#define PARAM_MAX SNDRV_PCM_HW_PARAM_LAST_INTERVAL
52#define SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP (1<<2)
50 53
51static inline int param_is_mask(int p) 54static inline int param_is_mask(int p)
52{ 55{
@@ -108,6 +111,16 @@ static void param_set_int(struct snd_pcm_hw_params *p, int n, unsigned int val)
108 } 111 }
109} 112}
110 113
114static unsigned int param_get_int(struct snd_pcm_hw_params *p, int n)
115{
116 if (param_is_interval(n)) {
117 struct snd_interval *i = param_to_interval(p, n);
118 if (i->integer)
119 return i->max;
120 }
121 return 0;
122}
123
111static void param_init(struct snd_pcm_hw_params *p) 124static void param_init(struct snd_pcm_hw_params *p)
112{ 125{
113 int n; 126 int n;
@@ -135,11 +148,14 @@ struct pcm {
135 int running:1; 148 int running:1;
136 int underruns; 149 int underruns;
137 unsigned int buffer_size; 150 unsigned int buffer_size;
151 unsigned int boundary;
138 char error[PCM_ERROR_MAX]; 152 char error[PCM_ERROR_MAX];
139 struct pcm_config config; 153 struct pcm_config config;
140 struct snd_pcm_mmap_status *mmap_status; 154 struct snd_pcm_mmap_status *mmap_status;
141 struct snd_pcm_mmap_control *mmap_control; 155 struct snd_pcm_mmap_control *mmap_control;
142 struct snd_pcm_sync_ptr *sync_ptr; 156 struct snd_pcm_sync_ptr *sync_ptr;
157 void *mmap_buffer;
158 unsigned int noirq_frames_per_msec;
143}; 159};
144 160
145unsigned int pcm_get_buffer_size(struct pcm *pcm) 161unsigned int pcm_get_buffer_size(struct pcm *pcm)
@@ -190,6 +206,18 @@ static unsigned int pcm_format_to_bits(enum pcm_format format)
190 }; 206 };
191} 207}
192 208
209unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int bytes)
210{
211 return bytes / (pcm->config.channels *
212 (pcm_format_to_bits(pcm->config.format) >> 3));
213}
214
215unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames)
216{
217 return frames * pcm->config.channels *
218 (pcm_format_to_bits(pcm->config.format) >> 3);
219}
220
193static int pcm_sync_ptr(struct pcm *pcm, int flags) { 221static int pcm_sync_ptr(struct pcm *pcm, int flags) {
194 if (pcm->sync_ptr) { 222 if (pcm->sync_ptr) {
195 pcm->sync_ptr->flags = flags; 223 pcm->sync_ptr->flags = flags;
@@ -253,6 +281,44 @@ static void pcm_hw_munmap_status(struct pcm *pcm) {
253 pcm->mmap_control = NULL; 281 pcm->mmap_control = NULL;
254} 282}
255 283
284static int pcm_areas_copy(struct pcm *pcm, unsigned int pcm_offset,
285 const char *src, unsigned int src_offset,
286 unsigned int frames)
287{
288 int size_bytes = pcm_frames_to_bytes(pcm, frames);
289 int pcm_offset_bytes = pcm_frames_to_bytes(pcm, pcm_offset);
290 int src_offset_bytes = pcm_frames_to_bytes(pcm, src_offset);
291
292 /* interleaved only atm */
293 memcpy((char*)pcm->mmap_buffer + pcm_offset_bytes,
294 src + src_offset_bytes, size_bytes);
295 return 0;
296}
297
298static int pcm_mmap_write_areas(struct pcm *pcm, char *src,
299 unsigned int offset, unsigned int size)
300{
301 void *pcm_areas;
302 int commit;
303 unsigned int pcm_offset, frames, count = 0;
304
305 while (size > 0) {
306 frames = size;
307 pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
308 pcm_areas_copy(pcm, pcm_offset, src, offset, frames);
309 commit = pcm_mmap_commit(pcm, pcm_offset, frames);
310 if (commit < 0) {
311 oops(pcm, commit, "failed to commit %d frames\n", frames);
312 return commit;
313 }
314
315 offset += commit;
316 count += commit;
317 size -= commit;
318 }
319 return count;
320}
321
256int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail, 322int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail,
257 struct timespec *tstamp) 323 struct timespec *tstamp)
258{ 324{
@@ -361,6 +427,11 @@ int pcm_close(struct pcm *pcm)
361 427
362 pcm_hw_munmap_status(pcm); 428 pcm_hw_munmap_status(pcm);
363 429
430 if (pcm->flags & PCM_MMAP) {
431 pcm_stop(pcm);
432 munmap(pcm->mmap_buffer, pcm_frames_to_bytes(pcm, pcm->buffer_size));
433 }
434
364 if (pcm->fd >= 0) 435 if (pcm->fd >= 0)
365 close(pcm->fd); 436 close(pcm->fd);
366 pcm->running = 0; 437 pcm->running = 0;
@@ -398,12 +469,10 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
398 469
399 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_INFO, &info)) { 470 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_INFO, &info)) {
400 oops(pcm, errno, "cannot get info"); 471 oops(pcm, errno, "cannot get info");
401 goto fail; 472 goto fail_close;
402 } 473 }
403 474
404 param_init(&params); 475 param_init(&params);
405 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS,
406 SNDRV_PCM_ACCESS_RW_INTERLEAVED);
407 param_set_mask(&params, SNDRV_PCM_HW_PARAM_FORMAT, 476 param_set_mask(&params, SNDRV_PCM_HW_PARAM_FORMAT,
408 pcm_format_to_alsa(config->format)); 477 pcm_format_to_alsa(config->format));
409 param_set_mask(&params, SNDRV_PCM_HW_PARAM_SUBFORMAT, 478 param_set_mask(&params, SNDRV_PCM_HW_PARAM_SUBFORMAT,
@@ -418,30 +487,70 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
418 param_set_int(&params, SNDRV_PCM_HW_PARAM_PERIODS, config->period_count); 487 param_set_int(&params, SNDRV_PCM_HW_PARAM_PERIODS, config->period_count);
419 param_set_int(&params, SNDRV_PCM_HW_PARAM_RATE, config->rate); 488 param_set_int(&params, SNDRV_PCM_HW_PARAM_RATE, config->rate);
420 489
490 if (flags & PCM_NOIRQ) {
491
492 if (!(flags & PCM_MMAP)) {
493 oops(pcm, -EINVAL, "noirq only currently supported with mmap().");
494 goto fail;
495 }
496
497 params.flags |= SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
498 pcm->noirq_frames_per_msec = config->rate / 1000;
499 }
500
501 if (flags & PCM_MMAP)
502 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS,
503 SNDRV_PCM_ACCESS_MMAP_INTERLEAVED);
504 else
505 param_set_mask(&params, SNDRV_PCM_HW_PARAM_ACCESS,
506 SNDRV_PCM_ACCESS_RW_INTERLEAVED);
507
421 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_PARAMS, &params)) { 508 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_PARAMS, &params)) {
422 oops(pcm, errno, "cannot set hw params"); 509 oops(pcm, errno, "cannot set hw params");
423 goto fail; 510 goto fail_close;
424 } 511 }
425 512
513 /* get our refined hw_params */
514 config->period_size = param_get_int(&params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
515 config->period_count = param_get_int(&params, SNDRV_PCM_HW_PARAM_PERIODS);
516 pcm->buffer_size = config->period_count * config->period_size;
517
518 if (flags & PCM_MMAP) {
519 pcm->mmap_buffer = mmap(NULL, pcm_frames_to_bytes(pcm, pcm->buffer_size),
520 PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, pcm->fd, 0);
521 if (pcm->mmap_buffer == MAP_FAILED) {
522 oops(pcm, -errno, "failed to mmap buffer %d bytes\n",
523 pcm_frames_to_bytes(pcm, pcm->buffer_size));
524 goto fail_close;
525 }
526 }
527
528
426 memset(&sparams, 0, sizeof(sparams)); 529 memset(&sparams, 0, sizeof(sparams));
427 sparams.tstamp_mode = SNDRV_PCM_TSTAMP_ENABLE; 530 sparams.tstamp_mode = SNDRV_PCM_TSTAMP_ENABLE;
428 sparams.period_step = 1; 531 sparams.period_step = 1;
429 sparams.avail_min = 1; 532 sparams.avail_min = 1;
430 533
431 if (!config->start_threshold) 534 if (!config->start_threshold)
432 sparams.start_threshold = config->period_count * config->period_size; 535 pcm->config.start_threshold = sparams.start_threshold =
536 config->period_count * config->period_size / 2;
433 else 537 else
434 sparams.start_threshold = config->start_threshold; 538 sparams.start_threshold = config->start_threshold;
435 539
540 /* pick a high stop threshold - todo: does this need further tuning */
436 if (!config->stop_threshold) 541 if (!config->stop_threshold)
437 sparams.stop_threshold = config->period_count * config->period_size; 542 pcm->config.stop_threshold = sparams.stop_threshold =
543 config->period_count * config->period_size * 10;
438 else 544 else
439 sparams.stop_threshold = config->stop_threshold; 545 sparams.stop_threshold = config->stop_threshold;
440 546
441 sparams.xfer_align = config->period_size / 2; /* needed for old kernels */ 547 sparams.xfer_align = config->period_size / 2; /* needed for old kernels */
442 sparams.silence_size = 0; 548 sparams.silence_size = 0;
443 sparams.silence_threshold = config->silence_threshold; 549 sparams.silence_threshold = config->silence_threshold;
550 pcm->boundary = sparams.boundary = pcm->buffer_size;
444 551
552 while (pcm->boundary * 2 <= LONG_MAX - pcm->buffer_size)
553 pcm->boundary *= 2;
445 554
446 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)) { 555 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)) {
447 oops(pcm, errno, "cannot set sw params"); 556 oops(pcm, errno, "cannot set sw params");
@@ -454,11 +563,13 @@ struct pcm *pcm_open(unsigned int card, unsigned int device,
454 goto fail; 563 goto fail;
455 } 564 }
456 565
457 pcm->buffer_size = config->period_count * config->period_size;
458 pcm->underruns = 0; 566 pcm->underruns = 0;
459 return pcm; 567 return pcm;
460 568
461fail: 569fail:
570 if (flags & PCM_MMAP)
571 munmap(pcm->mmap_buffer, pcm_frames_to_bytes(pcm, pcm->buffer_size));
572fail_close:
462 close(pcm->fd); 573 close(pcm->fd);
463 pcm->fd = -1; 574 pcm->fd = -1;
464 return pcm; 575 return pcm;
@@ -473,9 +584,14 @@ int pcm_start(struct pcm *pcm)
473{ 584{
474 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_PREPARE) < 0) 585 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_PREPARE) < 0)
475 return oops(pcm, errno, "cannot prepare channel"); 586 return oops(pcm, errno, "cannot prepare channel");
587
588 if (pcm->flags & PCM_MMAP)
589 pcm_sync_ptr(pcm, 0);
590
476 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_START) < 0) 591 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_START) < 0)
477 return oops(pcm, errno, "cannot start channel"); 592 return oops(pcm, errno, "cannot start channel");
478 593
594 pcm->running = 1;
479 return 0; 595 return 0;
480} 596}
481 597
@@ -484,6 +600,219 @@ int pcm_stop(struct pcm *pcm)
484 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_DROP) < 0) 600 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_DROP) < 0)
485 return oops(pcm, errno, "cannot stop channel"); 601 return oops(pcm, errno, "cannot stop channel");
486 602
603 pcm->running = 0;
604 return 0;
605}
606
607static inline int pcm_mmap_playback_avail(struct pcm *pcm)
608{
609 int avail;
610
611 avail = pcm->mmap_status->hw_ptr + pcm->buffer_size - pcm->mmap_control->appl_ptr;
612
613 if (avail < 0)
614 avail += pcm->boundary;
615 else if (avail > (int)pcm->boundary)
616 avail -= pcm->boundary;
617
618 return avail;
619}
620
621static inline int pcm_mmap_capture_avail(struct pcm *pcm)
622{
623 int avail = pcm->mmap_status->hw_ptr - pcm->mmap_control->appl_ptr;
624 if (avail < 0)
625 avail += pcm->boundary;
626 return avail;
627}
628
629static inline int pcm_mmap_avail(struct pcm *pcm)
630{
631 pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_HWSYNC);
632 if (pcm->flags & PCM_IN)
633 return pcm_mmap_capture_avail(pcm);
634 else
635 return pcm_mmap_playback_avail(pcm);
636}
637
638static void pcm_mmap_appl_forward(struct pcm *pcm, int frames)
639{
640 unsigned int appl_ptr = pcm->mmap_control->appl_ptr;
641 appl_ptr += frames;
642
643 /* check for boundary wrap */
644 if (appl_ptr > pcm->boundary)
645 appl_ptr -= pcm->boundary;
646 pcm->mmap_control->appl_ptr = appl_ptr;
647}
648
649int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset,
650 unsigned int *frames)
651{
652 unsigned int continuous, copy_frames, avail;
653
654 /* return the mmap buffer */
655 *areas = pcm->mmap_buffer;
656
657 /* and the application offset in frames */
658 *offset = pcm->mmap_control->appl_ptr % pcm->buffer_size;
659
660 avail = pcm_mmap_avail(pcm);
661 if (avail > pcm->buffer_size)
662 avail = pcm->buffer_size;
663 continuous = pcm->buffer_size - *offset;
664
665 /* we can only copy frames if the are availabale and continuos */
666 copy_frames = *frames;
667 if (copy_frames > avail)
668 copy_frames = avail;
669 if (copy_frames > continuous)
670 copy_frames = continuous;
671 *frames = copy_frames;
672
487 return 0; 673 return 0;
488} 674}
489 675
676int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames)
677{
678 /* update the application pointer in userspace and kernel */
679 pcm_mmap_appl_forward(pcm, frames);
680 pcm_sync_ptr(pcm, 0);
681
682 return frames;
683}
684
685int pcm_avail_update(struct pcm *pcm)
686{
687 pcm_sync_ptr(pcm, 0);
688 return pcm_mmap_avail(pcm);
689}
690
691int pcm_state(struct pcm *pcm)
692{
693 int err = pcm_sync_ptr(pcm, 0);
694 if (err < 0)
695 return err;
696
697 return pcm->mmap_status->state;
698}
699
700int pcm_wait(struct pcm *pcm, int timeout)
701{
702 struct pollfd pfd;
703 unsigned short revents = 0;
704 int err;
705
706 pfd.fd = pcm->fd;
707 pfd.events = POLLOUT | POLLERR | POLLNVAL;
708
709 do {
710 /* let's wait for avail or timeout */
711 err = poll(&pfd, 1, timeout);
712 if (err < 0)
713 return -errno;
714
715 /* timeout ? */
716 if (err == 0)
717 return 0;
718
719 /* have we been interrupted ? */
720 if (errno == -EINTR)
721 continue;
722
723 /* check for any errors */
724 if (pfd.revents & (POLLERR | POLLNVAL)) {
725 switch (pcm_state(pcm)) {
726 case PCM_STATE_XRUN:
727 return -EPIPE;
728 case PCM_STATE_SUSPENDED:
729 return -ESTRPIPE;
730 case PCM_STATE_DISCONNECTED:
731 return -ENODEV;
732 default:
733 return -EIO;
734 }
735 }
736 /* poll again if fd not ready for IO */
737 } while (!(pfd.revents & (POLLIN | POLLOUT)));
738
739 return 1;
740}
741
742int pcm_mmap_write(struct pcm *pcm, void *buffer, unsigned int bytes)
743{
744 int err = 0, frames, avail;
745 unsigned int offset = 0, count;
746
747 if (bytes == 0)
748 return 0;
749
750 count = pcm_bytes_to_frames(pcm, bytes);
751
752 while (count > 0) {
753
754 /* get the available space for writing new frames */
755 avail = pcm_avail_update(pcm);
756 if (avail < 0) {
757 fprintf(stderr, "cannot determine available mmap frames");
758 return err;
759 }
760
761 /* start the audio if we reach the threshold */
762 if (!pcm->running &&
763 (pcm->buffer_size - avail) >= pcm->config.start_threshold) {
764 if (pcm_start(pcm) < 0) {
765 fprintf(stderr, "start error: hw 0x%x app 0x%x avail 0x%x\n",
766 (unsigned int)pcm->mmap_status->hw_ptr,
767 (unsigned int)pcm->mmap_control->appl_ptr,
768 avail);
769 return -errno;
770 }
771 }
772
773 /* sleep until we have space to write new frames */
774 if (pcm->running &&
775 (unsigned int)avail < pcm->mmap_control->avail_min) {
776 int time = -1;
777
778 if (pcm->flags & PCM_NOIRQ)
779 time = (pcm->buffer_size - avail - pcm->mmap_control->avail_min)
780 / pcm->noirq_frames_per_msec;
781
782 err = pcm_wait(pcm, time);
783 if (err < 0) {
784 pcm->running = 0;
785 fprintf(stderr, "wait error: hw 0x%x app 0x%x avail 0x%x\n",
786 (unsigned int)pcm->mmap_status->hw_ptr,
787 (unsigned int)pcm->mmap_control->appl_ptr,
788 avail);
789 pcm->mmap_control->appl_ptr = 0;
790 return err;
791 }
792 continue;
793 }
794
795 frames = count;
796 if (frames > avail)
797 frames = avail;
798
799 if (!frames)
800 break;
801
802 /* copy frames from buffer */
803 frames = pcm_mmap_write_areas(pcm, buffer, offset, frames);
804 if (frames < 0) {
805 fprintf(stderr, "write error: hw 0x%x app 0x%x avail 0x%x\n",
806 (unsigned int)pcm->mmap_status->hw_ptr,
807 (unsigned int)pcm->mmap_control->appl_ptr,
808 avail);
809 return frames;
810 }
811
812 offset += frames;
813 count -= frames;
814 }
815
816_end:
817 return 0;
818}
diff --git a/tinyplay.c b/tinyplay.c
index f52d76a..915a1ea 100644
--- a/tinyplay.c
+++ b/tinyplay.c
@@ -76,9 +76,12 @@ int main(int argc, char **argv)
76 76
77 /* parse command line arguments */ 77 /* parse command line arguments */
78 argv += 2; 78 argv += 2;
79 if (strcmp(*argv, "-d") == 0) { 79 while (*argv) {
80 if (strcmp(*argv, "-d") == 0) {
81 argv++;
82 device = atoi(*argv);
83 }
80 argv++; 84 argv++;
81 device = atoi(*argv);
82 } 85 }
83 86
84 fread(&header, sizeof(struct wav_header), 1, file); 87 fread(&header, sizeof(struct wav_header), 1, file);