aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Wilson2012-02-28 17:26:02 -0600
committerSimon Wilson2012-02-28 17:26:02 -0600
commitdaa83291944318d8face12c780dfb69ae96b0723 (patch)
tree116ac173a9b5c13306e47373d739f99dd0e8a05e /tinyplay.c
parent594e8662270b025d5029edbb54baf46627b3a815 (diff)
downloadplatform-external-tinyalsa-daa83291944318d8face12c780dfb69ae96b0723.tar.gz
platform-external-tinyalsa-daa83291944318d8face12c780dfb69ae96b0723.tar.xz
platform-external-tinyalsa-daa83291944318d8face12c780dfb69ae96b0723.zip
Update to latest tinyalsa
a6dd4ab tinyplay: Use buffer size in bytes instead of frames 5f64fe7 pcm: Factor out pcm_start() from pcm_read() 6bbe77a pcm: Constify write buffers 9989fc2 tinycap, tinyplay, tinymix: Add extra parameters. 3e3376a tinycap, tinyplay: Check *argv before dereferencing. 80085d4 pcm: Fix integer size error. Change-Id: I69a37c0a89e5531b9ab66a8b3f730765904ed9f7
Diffstat (limited to 'tinyplay.c')
-rw-r--r--tinyplay.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/tinyplay.c b/tinyplay.c
index 915a1ea..4d257e7 100644
--- a/tinyplay.c
+++ b/tinyplay.c
@@ -54,17 +54,22 @@ struct wav_header {
54 uint32_t data_sz; 54 uint32_t data_sz;
55}; 55};
56 56
57void play_sample(FILE *file, unsigned int device, unsigned int channels, 57void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels,
58 unsigned int rate, unsigned int bits); 58 unsigned int rate, unsigned int bits, unsigned int period_size,
59 unsigned int period_count);
59 60
60int main(int argc, char **argv) 61int main(int argc, char **argv)
61{ 62{
62 FILE *file; 63 FILE *file;
63 struct wav_header header; 64 struct wav_header header;
64 unsigned int device = 0; 65 unsigned int device = 0;
66 unsigned int card = 0;
67 unsigned int period_size = 1024;
68 unsigned int period_count = 4;
65 69
66 if (argc < 2) { 70 if (argc < 2) {
67 fprintf(stderr, "Usage: %s file.wav [-d device]\n", argv[0]); 71 fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-p period_size]"
72 " [-n n_periods] \n", argv[0]);
68 return 1; 73 return 1;
69 } 74 }
70 75
@@ -79,9 +84,26 @@ int main(int argc, char **argv)
79 while (*argv) { 84 while (*argv) {
80 if (strcmp(*argv, "-d") == 0) { 85 if (strcmp(*argv, "-d") == 0) {
81 argv++; 86 argv++;
82 device = atoi(*argv); 87 if (*argv)
88 device = atoi(*argv);
83 } 89 }
84 argv++; 90 if (strcmp(*argv, "-p") == 0) {
91 argv++;
92 if (*argv)
93 period_size = atoi(*argv);
94 }
95 if (strcmp(*argv, "-n") == 0) {
96 argv++;
97 if (*argv)
98 period_count = atoi(*argv);
99 }
100 if (strcmp(*argv, "-D") == 0) {
101 argv++;
102 if (*argv)
103 card = atoi(*argv);
104 }
105 if (*argv)
106 argv++;
85 } 107 }
86 108
87 fread(&header, sizeof(struct wav_header), 1, file); 109 fread(&header, sizeof(struct wav_header), 1, file);
@@ -96,16 +118,17 @@ int main(int argc, char **argv)
96 return 1; 118 return 1;
97 } 119 }
98 120
99 play_sample(file, device, header.num_channels, header.sample_rate, 121 play_sample(file, card, device, header.num_channels, header.sample_rate,
100 header.bits_per_sample); 122 header.bits_per_sample, period_size, period_count);
101 123
102 fclose(file); 124 fclose(file);
103 125
104 return 0; 126 return 0;
105} 127}
106 128
107void play_sample(FILE *file, unsigned int device, unsigned int channels, 129void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels,
108 unsigned int rate, unsigned int bits) 130 unsigned int rate, unsigned int bits, unsigned int period_size,
131 unsigned int period_count)
109{ 132{
110 struct pcm_config config; 133 struct pcm_config config;
111 struct pcm *pcm; 134 struct pcm *pcm;
@@ -115,8 +138,8 @@ void play_sample(FILE *file, unsigned int device, unsigned int channels,
115 138
116 config.channels = channels; 139 config.channels = channels;
117 config.rate = rate; 140 config.rate = rate;
118 config.period_size = 1024; 141 config.period_size = period_size;
119 config.period_count = 4; 142 config.period_count = period_count;
120 if (bits == 32) 143 if (bits == 32)
121 config.format = PCM_FORMAT_S32_LE; 144 config.format = PCM_FORMAT_S32_LE;
122 else if (bits == 16) 145 else if (bits == 16)
@@ -125,14 +148,14 @@ void play_sample(FILE *file, unsigned int device, unsigned int channels,
125 config.stop_threshold = 0; 148 config.stop_threshold = 0;
126 config.silence_threshold = 0; 149 config.silence_threshold = 0;
127 150
128 pcm = pcm_open(0, device, PCM_OUT, &config); 151 pcm = pcm_open(card, device, PCM_OUT, &config);
129 if (!pcm || !pcm_is_ready(pcm)) { 152 if (!pcm || !pcm_is_ready(pcm)) {
130 fprintf(stderr, "Unable to open PCM device %u (%s)\n", 153 fprintf(stderr, "Unable to open PCM device %u (%s)\n",
131 device, pcm_get_error(pcm)); 154 device, pcm_get_error(pcm));
132 return; 155 return;
133 } 156 }
134 157
135 size = pcm_get_buffer_size(pcm); 158 size = pcm_frames_to_bytes(pcm, pcm_get_buffer_size(pcm));
136 buffer = malloc(size); 159 buffer = malloc(size);
137 if (!buffer) { 160 if (!buffer) {
138 fprintf(stderr, "Unable to allocate %d bytes\n", size); 161 fprintf(stderr, "Unable to allocate %d bytes\n", size);