Changeset abaef81 in mainline


Ignore:
Timestamp:
2013-03-16T23:47:27Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
36774cf
Parents:
89d3946f
Message:

wavplay: Add playback function based on the new hound API

File:
1 edited

Legend:

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

    r89d3946f rabaef81  
    4646#include "wave.h"
    4747
     48#define BUFFER_SIZE (4 * 1024)
     49
     50
     51static int hplay(const char *filename)
     52{
     53        FILE *source = fopen(filename, "rb");
     54        if (!source)
     55                return EINVAL;
     56        wave_header_t header;
     57        size_t read = fread(&header, sizeof(header), 1, source);
     58        if (read != sizeof(header)) {
     59                fclose(source);
     60                return EIO;
     61        }
     62        unsigned rate, channels;
     63        pcm_sample_format_t format;
     64        const char *error;
     65        int ret = wav_parse_header(&header, NULL, NULL, &channels, &rate,
     66            &format, &error);
     67        if (ret != EOK) {
     68                printf("Error parsing wav header: %s.\n", error);
     69                fclose(source);
     70                return EINVAL;
     71        }
     72        hound_context_t *hound = hound_context_create_playback(filename,
     73            channels, rate, format, 0);
     74        if (!hound) {
     75                printf("Failed to create HOUND context\n");
     76                fclose(source);
     77                return ENOMEM;
     78        }
     79
     80        ret = hound_context_connect_target(hound, "default");
     81        if (ret != EOK) {
     82                printf("Failed to connect to default target: %s\n",
     83                    str_error(ret));
     84                fclose(source);
     85                return ENOMEM;
     86        }
     87        static char buffer[BUFFER_SIZE];
     88        size_t size = 0;
     89        while ((size = fread(buffer, sizeof(buffer), 1, source)) > 0) {
     90                ret = hound_write_main_stream(hound, buffer, size);
     91                if (ret != EOK) {
     92                        printf("Failed to write to context main stream: %s\n",
     93                            str_error(ret));
     94                        break;
     95                }
     96        }
     97        fclose(source);
     98        return ret;
     99}
     100
    48101typedef struct {
    49         FILE* source;
     102        FILE *source;
    50103        volatile bool playing;
    51104        fibril_mutex_t mutex;
     
    205258        else
    206259                return play_hound(file);
     260        (void)hplay;
    207261}
    208262/**
Note: See TracChangeset for help on using the changeset viewer.