Changeset b5d2e57 in mainline
- Timestamp:
- 2012-08-30T20:07:38Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 03362fbd
- Parents:
- 017455e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/wavplay/dplay.c
r017455e rb5d2e57 173 173 printf("Playing: %dHz, %s, %d channel(s).\n", pb->f.sampling_rate, 174 174 pcm_sample_format_str(pb->f.sample_format), pb->f.channels); 175 static suseconds_t work_time = 8000; /* 2ms */175 static useconds_t work_time = 8000; /* 8 ms */ 176 176 size_t bytes = fread(pb->buffer.position, sizeof(uint8_t), 177 177 pb->buffer.size, pb->source); … … 183 183 size_t pos = 0; 184 184 audio_pcm_get_buffer_pos(pb->device, &pos); 185 useconds_t usecs = pcm_format_size_to_usec(bytes - pos, &pb->f); 185 size_t to_play = bytes - pos; 186 useconds_t usecs = (bytes > pos) ? 187 pcm_format_size_to_usec(to_play, &pb->f) : 0; 186 188 187 189 pb->buffer.position += bytes; 188 190 189 191 printf("%u usecs to play %zu bytes from pos %zu.\n", 190 usecs, bytes, pos); 191 async_usleep(usecs - work_time); 192 audio_pcm_get_buffer_pos(pb->device, &pos); 193 printf("Woke up at position %zu/%zu.\n", pos, pb->buffer.size); 192 usecs, to_play, pos); 193 if (usecs > work_time) { 194 async_usleep(usecs - work_time); 195 audio_pcm_get_buffer_pos(pb->device, &pos); 196 // printf("Woke up at position %zu/%zu.\n", 197 // pos, pb->buffer.size); 198 } 194 199 195 200 /* Remove any overflow */ … … 202 207 /* This was the last part, 203 208 * zero 200 bytes or until the end of buffer. */ 204 bzero(pb->buffer.position, min( 200, remain));209 bzero(pb->buffer.position, min(1024, remain)); 205 210 if ((pb->buffer.base + pos) > pb->buffer.position) { 206 211 printf("Overflow: %zu vs. %zu!\n", … … 223 228 break; 224 229 audio_pcm_get_buffer_pos(pb->device, &pos); 225 printf("Half buffer copied at pos %zu ", pos);230 printf("Half buffer copied at pos %zu ", pos); 226 231 /* Wait until the rest of the buffer is ready */ 227 232 udelay(pcm_format_size_to_usec(pb->buffer.size - pos, &pb->f)); 228 233 /* copy the other part of the buffer */ 229 audio_pcm_get_buffer_pos(pb->device, &pos); 230 printf(" the other half copied at pos %zu\n", pos); 231 bytes += fread(pb->buffer.position + bytes, sizeof(uint8_t), 232 pb->buffer.size / 2, pb->source); 234 if (bytes == (pb->buffer.size / 2)) { 235 bytes += fread(pb->buffer.position + bytes, 236 sizeof(uint8_t), pb->buffer.size / 2, pb->source); 237 audio_pcm_get_buffer_pos(pb->device, &pos); 238 printf("the other half copied at pos %zu\n", pos); 239 } 233 240 } while (1); 234 241 audio_pcm_stop_playback(pb->device);
Note:
See TracChangeset
for help on using the changeset viewer.