Changeset 0a4ad7d in mainline


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

wavplay: Add direct recording functionality

Location:
uspace/app/wavplay
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/wavplay/Makefile

    re1d2f0e r0a4ad7d  
    4242SOURCES = \
    4343        dplay.c \
     44        drec.c \
    4445        main.c \
    4546        wave.c
  • uspace/app/wavplay/main.c

    re1d2f0e r0a4ad7d  
    4545
    4646#include "dplay.h"
     47#include "drec.h"
    4748#include "wave.h"
    4849
     
    252253                    i - optind + 1, argc - optind, file);
    253254                if (record) {
    254                         printf("Recording is not supported yet.\n");
    255                         return 1;
     255                        if (direct) {
     256                                drecord(device, file);
     257                        } else {
     258                                printf("Indirect recording is not supported "
     259                                    "yet.\n");
     260                                break;
     261                        }
    256262                }
    257263                if (direct) {
  • uspace/app/wavplay/wave.c

    re1d2f0e r0a4ad7d  
    3939#include "wave.h"
    4040
    41 int wav_parse_header(void *file, const void **data, size_t *data_size,
     41/**
     42 * Parse wav header data.
     43 * @param[in] hdata Header data to parse.
     44 * @param[out] data Pointer to audio data.
     45 * @param[out] data_size Size of the data after the header.
     46 * @param[out] channels Number of channels in stored audio format.
     47 * @param[out] sampling_rate Sampling rate of the store data.
     48 * @param[out] format Sample format.
     49 * @param[out] error String representatoin of error, if any.
     50 * @return Error code.
     51 *
     52 * Does sanity checks and endian conversion.
     53 */
     54int wav_parse_header(const void *hdata, const void **data, size_t *data_size,
    4255    unsigned *channels, unsigned *sampling_rate, pcm_sample_format_t *format,
    4356    const char **error)
    4457{
    45         if (!file) {
     58        if (!hdata) {
    4659                if (error)
    47                         *error = "file not present";
     60                        *error = "no header";
    4861                return EINVAL;
    4962        }
    5063
    51         const wave_header_t *header = file;
     64        const wave_header_t *header = hdata;
    5265        if (str_lcmp(header->chunk_id, CHUNK_ID, 4) != 0) {
    5366                if (error)
     
    113126        return EOK;
    114127}
     128
     129/**
     130 * Initialize wave fromat ehader structure.
     131 * @param header Structure to initialize.
     132 * @param format Desired PCM format
     133 * @param size Size of the stored data.
     134 *
     135 * Initializes format specific elements and covnerts endian
     136 */
     137void wav_init_header(wave_header_t *header, pcm_format_t format, size_t size)
     138{
     139        assert(header);
     140#define COPY_STR(dst, src)   memcpy(dst, src, str_size(src))
     141
     142        COPY_STR(&header->chunk_id, CHUNK_ID);
     143        COPY_STR(&header->format, FORMAT_STR);
     144        COPY_STR(&header->subchunk1_id, SUBCHUNK1_ID);
     145        header->subchunk1_size = host2uint16_t_le(PCM_SUBCHUNK1_SIZE);
     146        header->audio_format = host2uint16_t_le(FORMAT_LINEAR_PCM);
     147
     148        COPY_STR(&header->subchunk2_id, SUBCHUNK2_ID);
     149        header->subchunk2_size = host2uint32_t_le(size);
     150        header->sampling_rate = host2uint32_t_le(format.sampling_rate);
     151        header->channels = host2uint32_t_le(format.channels);
     152        header->sample_size =
     153            host2uint32_t_le(pcm_sample_format_size(format.sample_format));
     154}
    115155/**
    116156 * @}
  • uspace/app/wavplay/wave.h

    re1d2f0e r0a4ad7d  
    3636
    3737#include <stdint.h>
     38#include <pcm/format.h>
    3839#include <pcm/sample_format.h>
    3940
     
    8990} wave_header_t;
    9091
    91 int wav_parse_header(void *, const void**, size_t *, unsigned *, unsigned *,
    92     pcm_sample_format_t *, const char **);
     92int wav_parse_header(const void *, const void**, size_t *, unsigned *,
     93    unsigned *, pcm_sample_format_t *, const char **);
    9394
     95void wav_init_header(wave_header_t *, pcm_format_t , size_t);
    9496#endif
    9597/**
Note: See TracChangeset for help on using the changeset viewer.