Changeset a8e87da in mainline for uspace/app/wavplay/dplay.c
- Timestamp:
- 2013-04-10T18:49:43Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b1dfe13
- Parents:
- 76e863c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/wavplay/dplay.c
r76e863c ra8e87da 52 52 #define DEFAULT_FRAGMENTS 2 53 53 54 /** Playback helper structure */ 54 55 typedef struct { 55 56 struct { … … 66 67 } playback_t; 67 68 69 /** 70 * Initialize playback helper structure. 71 * @param pb Pointer to helper structure to initialize 72 * @param sess Pointer to audio device IPC session 73 * @return 74 */ 68 75 static void playback_initialize(playback_t *pb, audio_pcm_sess_t *sess) 69 76 { … … 80 87 } 81 88 82 89 /** 90 * Fragment playback callback function. 91 * @param iid IPC call id. 92 * @param icall Pointer to the call structure 93 * @param arg Argument, pointer to the playback helper function 94 */ 83 95 static void device_event_callback(ipc_callid_t iid, ipc_call_t *icall, void* arg) 84 96 { … … 125 137 } 126 138 139 /** 140 * Start event based playback. 141 * @param pb Playback helper structure. 142 */ 127 143 static void play_fragment(playback_t *pb) 128 144 { … … 166 182 } 167 183 184 /** 185 * Count occupied space in a cyclic buffer. 186 * @param pb Playback helper structure. 187 * @param pos read pointer position. 188 * @return Occupied space size. 189 */ 168 190 static size_t buffer_occupied(const playback_t *pb, size_t pos) 169 191 { … … 176 198 } 177 199 200 /** 201 * Count available space in a cyclic buffer. 202 * @param pb Playback helper structure. 203 * @param pos read pointer position. 204 * @return Free space size. 205 */ 178 206 static size_t buffer_avail(const playback_t *pb, size_t pos) 179 207 { … … 185 213 } 186 214 215 /** 216 * Size of the space between write pointer and the end of a cyclic buffer 217 * @param pb Playback helper structure. 218 */ 187 219 static size_t buffer_remain(const playback_t *pb) 188 220 { … … 191 223 } 192 224 225 /** 226 * Move write pointer forward. Wrap around the end. 227 * @param pb Playback helper structure. 228 * @param bytes NUmber of bytes to advance. 229 */ 193 230 static void buffer_advance(playback_t *pb, size_t bytes) 194 231 { … … 202 239 printf("%.2lu:%.6lu "f, time.tv_sec % 100, time.tv_usec, __VA_ARGS__) 203 240 204 241 /** 242 * Start playback using buffer position api. 243 * @param pb Playback helper function. 244 */ 205 245 static void play(playback_t *pb) 206 246 { … … 217 257 do { 218 258 size_t available = buffer_avail(pb, pos); 219 /* Writing might need wrap around the end */ 259 /* Writing might need wrap around the end, 260 * read directly to device buffer */ 220 261 size_t bytes = fread(pb->buffer.write_ptr, sizeof(uint8_t), 221 262 min(available, buffer_remain(pb)), pb->source); … … 225 266 pb->buffer.write_ptr - pb->buffer.base); 226 267 available -= bytes; 268 269 /* continue if we wrapped around the end */ 227 270 if (available) { 228 271 bytes = fread(pb->buffer.write_ptr, … … 254 297 pcm_format_size_to_usec(to_play, &pb->f); 255 298 299 /* Compute delay time */ 256 300 const useconds_t real_delay = (usecs > work_time) 257 301 ? usecs - work_time : 0; … … 260 304 if (real_delay) 261 305 async_usleep(real_delay); 306 /* update buffer position */ 262 307 const int ret = audio_pcm_get_buffer_pos(pb->device, &pos); 263 308 if (ret != EOK) { … … 265 310 } 266 311 getuptime(&time); 312 313 /* we did not use all the space we had, 314 * that is the end */ 267 315 if (available) 268 316 break; … … 272 320 } 273 321 322 /** 323 * Play audio file usign direct device access. 324 * @param device The device. 325 * @param file The file. 326 * @return Error code. 327 */ 274 328 int dplay(const char *device, const char *file) 275 329 {
Note:
See TracChangeset
for help on using the changeset viewer.