Changeset a8e87da in mainline for uspace/app/wavplay/dplay.c


Ignore:
Timestamp:
2013-04-10T18:49:43Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b1dfe13
Parents:
76e863c
Message:

wavplay: comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/wavplay/dplay.c

    r76e863c ra8e87da  
    5252#define DEFAULT_FRAGMENTS 2
    5353
     54/** Playback helper structure */
    5455typedef struct {
    5556        struct {
     
    6667} playback_t;
    6768
     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 */
    6875static void playback_initialize(playback_t *pb, audio_pcm_sess_t *sess)
    6976{
     
    8087}
    8188
    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 */
    8395static void device_event_callback(ipc_callid_t iid, ipc_call_t *icall, void* arg)
    8496{
     
    125137}
    126138
     139/**
     140 * Start event based playback.
     141 * @param pb Playback helper structure.
     142 */
    127143static void play_fragment(playback_t *pb)
    128144{
     
    166182}
    167183
     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 */
    168190static size_t buffer_occupied(const playback_t *pb, size_t pos)
    169191{
     
    176198}
    177199
     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 */
    178206static size_t buffer_avail(const playback_t *pb, size_t pos)
    179207{
     
    185213}
    186214
     215/**
     216 * Size of the space between write pointer and the end of a cyclic buffer
     217 * @param pb Playback helper structure.
     218 */
    187219static size_t buffer_remain(const playback_t *pb)
    188220{
     
    191223}
    192224
     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 */
    193230static void buffer_advance(playback_t *pb, size_t bytes)
    194231{
     
    202239        printf("%.2lu:%.6lu   "f, time.tv_sec % 100, time.tv_usec, __VA_ARGS__)
    203240
    204 
     241/**
     242 * Start playback using buffer position api.
     243 * @param pb Playback helper function.
     244 */
    205245static void play(playback_t *pb)
    206246{
     
    217257        do {
    218258                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 */
    220261                size_t bytes = fread(pb->buffer.write_ptr, sizeof(uint8_t),
    221262                    min(available, buffer_remain(pb)), pb->source);
     
    225266                    pb->buffer.write_ptr - pb->buffer.base);
    226267                available -= bytes;
     268
     269                /* continue if we wrapped around the end */
    227270                if (available) {
    228271                        bytes = fread(pb->buffer.write_ptr,
     
    254297                    pcm_format_size_to_usec(to_play, &pb->f);
    255298
     299                /* Compute delay time */
    256300                const useconds_t real_delay = (usecs > work_time)
    257301                    ? usecs - work_time : 0;
     
    260304                if (real_delay)
    261305                        async_usleep(real_delay);
     306                /* update buffer position */
    262307                const int ret = audio_pcm_get_buffer_pos(pb->device, &pos);
    263308                if (ret != EOK) {
     
    265310                }
    266311                getuptime(&time);
     312
     313                /* we did not use all the space we had,
     314                 * that is the end */
    267315                if (available)
    268316                        break;
     
    272320}
    273321
     322/**
     323 * Play audio file usign direct device access.
     324 * @param device The device.
     325 * @param file The file.
     326 * @return Error code.
     327 */
    274328int dplay(const char *device, const char *file)
    275329{
Note: See TracChangeset for help on using the changeset viewer.