FreeCalypso > hg > ice1-trau-tester
comparison pcm/pcm_tx.c @ 11:e149ca1dd14f
pcm: implement play-offset command
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 23 Jun 2024 19:59:17 +0000 |
parents | 5cf7818a7d08 |
children | 27ca01bb5b11 |
comparison
equal
deleted
inserted
replaced
10:5cf7818a7d08 | 11:e149ca1dd14f |
---|---|
135 read(fd, play_buffer, st.st_size); | 135 read(fd, play_buffer, st.st_size); |
136 close(fd); | 136 close(fd); |
137 play_buf_nframes = st.st_size / 160; | 137 play_buf_nframes = st.st_size / 160; |
138 play_buf_ptr = 0; | 138 play_buf_ptr = 0; |
139 } | 139 } |
140 | |
141 void cmd_play_offset(int argc, char **argv) | |
142 { | |
143 int fd; | |
144 struct stat st; | |
145 unsigned offset, pre_offset; | |
146 | |
147 if (argc != 3) { | |
148 printf("error: play-offset command needs 2 arguments\n"); | |
149 return; | |
150 } | |
151 if (play_buffer) { | |
152 printf("error: file play already in progress\n"); | |
153 return; | |
154 } | |
155 offset = strtoul(argv[2], NULL, 0); | |
156 if (offset < 1 || offset > 159) { | |
157 printf("error: offset argument out of range\n"); | |
158 return; | |
159 } | |
160 fd = open(argv[1], O_RDONLY); | |
161 if (fd < 0) { | |
162 perror(argv[1]); | |
163 return; | |
164 } | |
165 fstat(fd, &st); | |
166 if (!S_ISREG(st.st_mode)) { | |
167 close(fd); | |
168 fprintf(stderr, "error: %s is not a regular file\n", argv[1]); | |
169 return; | |
170 } | |
171 if (!st.st_size) { | |
172 close(fd); | |
173 fprintf(stderr, "error: %s is an empty file\n", argv[1]); | |
174 return; | |
175 } | |
176 if (st.st_size % 160) { | |
177 close(fd); | |
178 fprintf(stderr, | |
179 "error: size of %s is not a multiple of 160 bytes\n", | |
180 argv[1]); | |
181 return; | |
182 } | |
183 play_buffer = malloc(st.st_size + 160); | |
184 if (!play_buffer) { | |
185 close(fd); | |
186 fprintf(stderr, "unable to malloc buffer for %s\n", argv[1]); | |
187 return; | |
188 } | |
189 pre_offset = 160 - offset; | |
190 memset(play_buffer, pcm_fill_octet, pre_offset); | |
191 read(fd, play_buffer + pre_offset, st.st_size); | |
192 close(fd); | |
193 memset(play_buffer + pre_offset + st.st_size, pcm_fill_octet, offset); | |
194 play_buf_nframes = st.st_size / 160 + 1; | |
195 play_buf_ptr = 0; | |
196 } |