Changeset c5c65b6 in mainline
- Timestamp:
- 2012-07-06T14:11:32Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9b3d999
- Parents:
- 6be06d0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dplay/dplay.c
r6be06d0 rc5c65b6 74 74 pb->buffer.base = NULL; 75 75 pb->buffer.size = 0; 76 pb->buffer.position = NULL; 76 77 pb->playing = false; 77 78 pb->source = NULL; … … 94 95 break; 95 96 } 96 printf(" Got device event!!!\n");97 printf("+"); 97 98 const size_t bytes = fread(pb->buffer.position, sizeof(uint8_t), 98 99 buffer_part, pb->source); 99 pb->buffer.position += bytes; 100 if (bytes != buffer_part) 101 bzero(pb->buffer.position, buffer_part - bytes); 102 pb->buffer.position += buffer_part - bytes; 100 bzero(pb->buffer.position + bytes, buffer_part - bytes); 101 pb->buffer.position += buffer_part; 102 103 103 if (pb->buffer.position >= (pb->buffer.base + pb->buffer.size)) 104 104 pb->buffer.position = pb->buffer.base; … … 118 118 assert(pb->device); 119 119 pb->buffer.position = pb->buffer.base; 120 printf("Playing: %dHz, %d-bit samples, %d channel(s), %sSIGNED.\n",121 sampling_rate, sample_size, channels, sign ? "": "UN");120 printf("Playing: %dHz, %d-bit %ssigned samples, %d channel(s).\n", 121 sampling_rate, sample_size, sign ? "": "un", channels); 122 122 const size_t bytes = fread(pb->buffer.base, sizeof(uint8_t), 123 123 pb->buffer.size, pb->source); 124 124 if (bytes != pb->buffer.size) 125 return;125 bzero(pb->buffer.base + bytes, pb->buffer.size - bytes); 126 126 printf("Buffer data ready.\n"); 127 127 fibril_mutex_lock(&pb->mutex); … … 139 139 audio_pcm_buffer_stop_playback(pb->device, pb->buffer.id); 140 140 fibril_condvar_wait(&pb->cv, &pb->mutex); 141 printf("\n"); 141 142 } 142 143 … … 175 176 async_exch_t *exch = async_exchange_begin(session); 176 177 if (!exch) { 178 ret = EPARTY; 177 179 printf("Failed to start session exchange.\n"); 178 async_hangup(session); 179 return 1; 180 goto close_session; 180 181 } 181 182 const char* info = NULL; … … 183 184 if (ret != EOK) { 184 185 printf("Failed to get PCM info.\n"); 185 async_exchange_end(exch); 186 async_hangup(session); 187 return 1; 186 goto close_session; 188 187 } 189 188 printf("Playing on %s.\n", info); … … 197 196 if (ret != EOK) { 198 197 printf("Failed to get PCM buffer: %s.\n", str_error(ret)); 199 async_exchange_end(exch); 200 async_hangup(session); 201 return 1; 198 goto close_session; 202 199 } 203 200 printf("Buffer (%u): %p %zu.\n", pb.buffer.id, pb.buffer.base, … … 209 206 pb.source = fopen(file, "rb"); 210 207 if (pb.source == NULL) { 208 ret = ENOENT; 211 209 printf("Failed to open %s.\n", file); 212 munmap(pb.buffer.base, pb.buffer.size); 213 audio_pcm_buffer_release_buffer(exch, pb.buffer.id); 214 async_exchange_end(exch); 215 async_hangup(session); 216 return 1; 210 goto cleanup; 217 211 } 218 212 wave_header_t header; … … 226 220 printf("Error parsing wav header: %s.\n", error); 227 221 fclose(pb.source); 228 munmap(pb.buffer.base, pb.buffer.size); 229 audio_pcm_buffer_release_buffer(exch, pb.buffer.id); 230 async_exchange_end(exch); 231 async_hangup(session); 232 return 1; 222 goto cleanup; 233 223 } 234 224 235 225 play(&pb, rate, sample_size, channels, sign); 236 226 227 cleanup: 237 228 munmap(pb.buffer.base, pb.buffer.size); 238 229 audio_pcm_buffer_release_buffer(exch, pb.buffer.id); 230 close_session: 239 231 async_exchange_end(exch); 240 232 async_hangup(session); 241 return 0;233 return ret == EOK ? 0 : 1; 242 234 } 243 235 /**
Note:
See TracChangeset
for help on using the changeset viewer.