aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Wilson2012-05-15 19:37:19 -0500
committerSimon Wilson2012-05-15 19:37:19 -0500
commit85dc38f5bee79c184260e8c665cc34143be12bd4 (patch)
tree0fab8eaea062d7617c66b8ec6e7bfe1550881359
parent60d82d75f995538f04ff47e9b7499c86d54b72f4 (diff)
downloadplatform-external-tinyalsa-85dc38f5bee79c184260e8c665cc34143be12bd4.tar.gz
platform-external-tinyalsa-85dc38f5bee79c184260e8c665cc34143be12bd4.tar.xz
platform-external-tinyalsa-85dc38f5bee79c184260e8c665cc34143be12bd4.zip
Update to latest tinyalsa
2581a1e add error check for pcm_start 6a52f2c mixer: add missing include for sys/ioctl.h 9eba533 tinyplay: add multichannel support fba29e6 tinycap: Fix byte_rate and block_align values Change-Id: Icbee0a8c1e101234ac55ba8494c74b442f215576
-rw-r--r--mixer.c2
-rw-r--r--pcm.c5
-rw-r--r--tinycap.c2
-rw-r--r--tinyplay.c73
4 files changed, 55 insertions, 27 deletions
diff --git a/mixer.c b/mixer.c
index 4a39a43..9514528 100644
--- a/mixer.c
+++ b/mixer.c
@@ -34,6 +34,8 @@
34#include <errno.h> 34#include <errno.h>
35#include <ctype.h> 35#include <ctype.h>
36 36
37#include <sys/ioctl.h>
38
37#include <linux/ioctl.h> 39#include <linux/ioctl.h>
38#define __force 40#define __force
39#define __bitwise 41#define __bitwise
diff --git a/pcm.c b/pcm.c
index 6d4dbd5..4e9133a 100644
--- a/pcm.c
+++ b/pcm.c
@@ -415,7 +415,10 @@ int pcm_read(struct pcm *pcm, void *data, unsigned int count)
415 415
416 for (;;) { 416 for (;;) {
417 if (!pcm->running) { 417 if (!pcm->running) {
418 pcm_start(pcm); 418 if (pcm_start(pcm) < 0) {
419 fprintf(stderr, "start error");
420 return -errno;
421 }
419 } 422 }
420 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_READI_FRAMES, &x)) { 423 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_READI_FRAMES, &x)) {
421 pcm->running = 0; 424 pcm->running = 0;
diff --git a/tinycap.c b/tinycap.c
index dcc238c..d563309 100644
--- a/tinycap.c
+++ b/tinycap.c
@@ -136,9 +136,9 @@ int main(int argc, char **argv)
136 header.audio_format = FORMAT_PCM; 136 header.audio_format = FORMAT_PCM;
137 header.num_channels = channels; 137 header.num_channels = channels;
138 header.sample_rate = rate; 138 header.sample_rate = rate;
139 header.bits_per_sample = bits;
139 header.byte_rate = (header.bits_per_sample / 8) * channels * rate; 140 header.byte_rate = (header.bits_per_sample / 8) * channels * rate;
140 header.block_align = channels * (header.bits_per_sample / 8); 141 header.block_align = channels * (header.bits_per_sample / 8);
141 header.bits_per_sample = bits;
142 header.data_id = ID_DATA; 142 header.data_id = ID_DATA;
143 143
144 /* leave enough room for header */ 144 /* leave enough room for header */
diff --git a/tinyplay.c b/tinyplay.c
index 4d257e7..3f76cc6 100644
--- a/tinyplay.c
+++ b/tinyplay.c
@@ -36,22 +36,24 @@
36#define ID_FMT 0x20746d66 36#define ID_FMT 0x20746d66
37#define ID_DATA 0x61746164 37#define ID_DATA 0x61746164
38 38
39#define FORMAT_PCM 1 39struct riff_wave_header {
40
41struct wav_header {
42 uint32_t riff_id; 40 uint32_t riff_id;
43 uint32_t riff_sz; 41 uint32_t riff_sz;
44 uint32_t riff_fmt; 42 uint32_t wave_id;
45 uint32_t fmt_id; 43};
46 uint32_t fmt_sz; 44
45struct chunk_header {
46 uint32_t id;
47 uint32_t sz;
48};
49
50struct chunk_fmt {
47 uint16_t audio_format; 51 uint16_t audio_format;
48 uint16_t num_channels; 52 uint16_t num_channels;
49 uint32_t sample_rate; 53 uint32_t sample_rate;
50 uint32_t byte_rate; 54 uint32_t byte_rate;
51 uint16_t block_align; 55 uint16_t block_align;
52 uint16_t bits_per_sample; 56 uint16_t bits_per_sample;
53 uint32_t data_id;
54 uint32_t data_sz;
55}; 57};
56 58
57void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels, 59void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels,
@@ -61,11 +63,15 @@ void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned in
61int main(int argc, char **argv) 63int main(int argc, char **argv)
62{ 64{
63 FILE *file; 65 FILE *file;
64 struct wav_header header; 66 struct riff_wave_header riff_wave_header;
67 struct chunk_header chunk_header;
68 struct chunk_fmt chunk_fmt;
65 unsigned int device = 0; 69 unsigned int device = 0;
66 unsigned int card = 0; 70 unsigned int card = 0;
67 unsigned int period_size = 1024; 71 unsigned int period_size = 1024;
68 unsigned int period_count = 4; 72 unsigned int period_count = 4;
73 char *filename;
74 int more_chunks = 1;
69 75
70 if (argc < 2) { 76 if (argc < 2) {
71 fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-p period_size]" 77 fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-p period_size]"
@@ -73,12 +79,41 @@ int main(int argc, char **argv)
73 return 1; 79 return 1;
74 } 80 }
75 81
76 file = fopen(argv[1], "rb"); 82 filename = argv[1];
83 file = fopen(filename, "rb");
77 if (!file) { 84 if (!file) {
78 fprintf(stderr, "Unable to open file '%s'\n", argv[1]); 85 fprintf(stderr, "Unable to open file '%s'\n", filename);
86 return 1;
87 }
88
89 fread(&riff_wave_header, sizeof(riff_wave_header), 1, file);
90 if ((riff_wave_header.riff_id != ID_RIFF) ||
91 (riff_wave_header.wave_id != ID_WAVE)) {
92 fprintf(stderr, "Error: '%s' is not a riff/wave file\n", filename);
93 fclose(file);
79 return 1; 94 return 1;
80 } 95 }
81 96
97 do {
98 fread(&chunk_header, sizeof(chunk_header), 1, file);
99
100 switch (chunk_header.id) {
101 case ID_FMT:
102 fread(&chunk_fmt, sizeof(chunk_fmt), 1, file);
103 /* If the format header is larger, skip the rest */
104 if (chunk_header.sz > sizeof(chunk_fmt))
105 fseek(file, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR);
106 break;
107 case ID_DATA:
108 /* Stop looking for chunks */
109 more_chunks = 0;
110 break;
111 default:
112 /* Unknown chunk, skip bytes */
113 fseek(file, chunk_header.sz, SEEK_CUR);
114 }
115 } while (more_chunks);
116
82 /* parse command line arguments */ 117 /* parse command line arguments */
83 argv += 2; 118 argv += 2;
84 while (*argv) { 119 while (*argv) {
@@ -106,20 +141,8 @@ int main(int argc, char **argv)
106 argv++; 141 argv++;
107 } 142 }
108 143
109 fread(&header, sizeof(struct wav_header), 1, file); 144 play_sample(file, card, device, chunk_fmt.num_channels, chunk_fmt.sample_rate,
110 145 chunk_fmt.bits_per_sample, period_size, period_count);
111 if ((header.riff_id != ID_RIFF) ||
112 (header.riff_fmt != ID_WAVE) ||
113 (header.fmt_id != ID_FMT) ||
114 (header.audio_format != FORMAT_PCM) ||
115 (header.fmt_sz != 16)) {
116 fprintf(stderr, "Error: '%s' is not a PCM riff/wave file\n", argv[1]);
117 fclose(file);
118 return 1;
119 }
120
121 play_sample(file, card, device, header.num_channels, header.sample_rate,
122 header.bits_per_sample, period_size, period_count);
123 146
124 fclose(file); 147 fclose(file);
125 148