Changeset 346643c in mainline for uspace/app/drec


Ignore:
Timestamp:
2012-07-11T12:05:30Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
039337e8
Parents:
94694a4
Message:

audio: Use enum for sample format.

Location:
uspace/app/drec
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/drec/drec.c

    r94694a4 r346643c  
    4747#include <stdio.h>
    4848#include <macros.h>
     49#include <pcm_sample_format.h>
    4950
    5051#include "wave.h"
     
    5354#define SUBBUFFERS 2
    5455
    55 const unsigned sampling_rate = 44100, sample_size = 16, channels = 2;
    56 bool sign = true;
     56const unsigned sampling_rate = 44100, channels = 2, sample_size = 16;
     57const pcm_sample_format_t format = PCM_SAMPLE_SINT16_LE;
    5758
    5859typedef struct {
     
    104105
    105106
    106 static void record(record_t *rec, unsigned sampling_rate, unsigned sample_size,
    107     unsigned channels, bool sign)
     107static void record(record_t *rec, unsigned channels, unsigned sampling_rate,
     108    pcm_sample_format_t format)
    108109{
    109110        assert(rec);
    110111        assert(rec->device);
    111112        rec->buffer.position = rec->buffer.base;
    112         printf("Recording: %dHz, %d-bit %ssigned samples, %d channel(s).\n",
    113             sampling_rate, sample_size, sign ? "": "un", channels);
     113        printf("Recording: %dHz, %s, %d channel(s).\n",
     114            sampling_rate, pcm_sample_format_str(format), channels);
    114115        int ret = audio_pcm_start_record(rec->device, rec->buffer.id,
    115             SUBBUFFERS, sampling_rate, sample_size, channels, sign);
     116            SUBBUFFERS, channels, sampling_rate, format);
    116117        if (ret != EOK) {
    117118                printf("Failed to start recording: %s.\n", str_error(ret));
     
    201202                .sampling_rate = sampling_rate,
    202203                .sample_size = sample_size,
    203                 .byte_rate = (sampling_rate / 8) * channels,
    204                 .block_align = (sampling_rate / 8) * channels,
     204                .byte_rate = sampling_rate * (sample_size / 8) * channels,
     205                .block_align = (sample_size / 8) * channels,
    205206                .subchunk2_id = SUBCHUNK2_ID,
    206207        };
    207208        fwrite(&header, sizeof(header), 1, rec.file);
    208         record(&rec, sampling_rate, sample_size, channels, sign);
     209        record(&rec, sampling_rate, channels, format);
    209210        fclose(rec.file);
    210211
  • uspace/app/drec/wave.c

    r94694a4 r346643c  
    4040
    4141int wav_parse_header(void *file, const void **data, size_t *data_size,
    42     unsigned *sampling_rate, unsigned *sample_size, unsigned *channels,
    43     bool *sign, const char **error)
     42    unsigned *channels, unsigned *sampling_rate, pcm_sample_format_t *format,
     43    const char **error)
    4444{
    4545        if (!file) {
     
    8686        }
    8787
     88
    8889        if (data)
    8990                *data = header->data;
     
    9394        if (sampling_rate)
    9495                *sampling_rate = uint32_t_le2host(header->sampling_rate);
    95         if (sample_size)
    96                 *sample_size = uint32_t_le2host(header->sample_size);
    9796        if (channels)
    9897                *channels = uint16_t_le2host(header->channels);
    99         if (sign)
    100                 *sign = uint32_t_le2host(header->sample_size) == 16
    101                     ? true : false;
     98        if (format) {
     99                const unsigned size = uint32_t_le2host(header->sample_size);
     100                switch (size) {
     101                case 8: *format = PCM_SAMPLE_UINT8; break;
     102                case 16: *format = PCM_SAMPLE_SINT16_LE; break;
     103                case 24: *format = PCM_SAMPLE_SINT24_LE; break;
     104                case 32: *format = PCM_SAMPLE_SINT32_LE; break;
     105                default:
     106                        *error = "Unknown format";
     107                        return ENOTSUP;
     108                }
     109        }
    102110        if (error)
    103111                *error = "no error";
  • uspace/app/drec/wave.h

    r94694a4 r346643c  
    3737#include <stdint.h>
    3838#include <bool.h>
     39#include <pcm_sample_format.h>
    3940
    4041/** Wave file header format.
     
    9091
    9192int wav_parse_header(void *, const void**, size_t *, unsigned *, unsigned *,
    92     unsigned *, bool *, const char **error_str);
     93    pcm_sample_format_t *, const char **);
    9394
    9495#endif
Note: See TracChangeset for help on using the changeset viewer.