summaryrefslogtreecommitdiff
path: root/apps/codecs/libpcm/pcm_common.h
blob: 757d0ad5d9fa556a823eab5c416d9ea327f23901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2009 Yoshihisa Uchida
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#ifndef CODEC_LIBPCMS_PCM_COMMON_H
#define CODEC_LIBPCMS_PCM_COMMON_H

#include <sys/types.h>
#include <stdbool.h>
#include <inttypes.h>

/*
 * PCM_CHUNK_SIZE has the size only of storing the sample at 1/50 seconds.
 * But it might not be 1/50 seconds according to the format.
 * Please confirm the source file of each format.
 */
#define PCM_CHUNK_SIZE (4096*2)

/* Macro that sign extends an unsigned byte */
#define SE(x) ((int32_t)((int8_t)(x)))

/* Macro that shift to -0x80. (0 .. 127 to -128 .. -1, 128 .. 255 to 0 .. 127) */
#define SFT(x) ((int32_t)x-0x80)

struct pcm_format {
    /*
     * RIFF: wFormatTag (in 'fmt ' chunk)
     * AIFF: compressionType (in 'COMM' chunk)
     */
    uint32_t formattag;

    /*
     * RIFF: wChannels (in 'fmt ' chunk)
     * AIFF: numChannels (in 'COMM' chunk)
     */
    uint16_t channels;

    /*
     * RIFF: dwSamplesPerSec (in 'fmt ' chunk)
     * AIFF: sampleRate (in 'COMM' chunk)
     */
    uint32_t samplespersec;

    /* RIFF: dwAvgBytesPerSec (in 'fmt ' chunk) */
    uint32_t avgbytespersec;

    /*
     * RIFF: wBlockAlign (in 'fmt ' chunk)
     * AIFF: blockSize (in 'SSND' chunk)
     */
    uint16_t blockalign;

    /*
     * RIFF: wBitsPerSample (in 'fmt ' chunk)
     * AIFF: sampleSize (in 'COMM' chunk)
     */
    uint16_t bitspersample;

    /* RIFF: wSize (in 'fmt ' chunk) */
    uint16_t size;

    /* RIFF: dSamplesPerBlock (in 'fmt ' chunk) */
    uint16_t samplesperblock;

    /* RIFF: wTotalSamples (in 'fact' chunk) */
    uint16_t totalsamples;

    /* the following values are not RIFF/AIFF chunk values */

    /* bytes per sample */
    int bytespersample;

    /* chunk size */
    long chunksize;

    /* data size */
    uint32_t numbytes;

    /*
     * data endian
     * true: little endian, false: big endian
     */
    bool is_little_endian;

    /*
     * data signess
     * true: signed, false: unsigned
     */
    bool is_signed;
};

struct pcm_codec {
    bool (*set_format)(struct pcm_format *format, const unsigned char *fmtpos);
    uint32_t (*get_seek_pos)(long seek_time);
    int (*decode)(const uint8_t *inbuf, size_t inbufsize,
                  int32_t *outbuf, int *outbufsize);
};

struct pcm_entry {
    uint32_t format_tag;
    const struct pcm_codec *(*get_codec)(void);
};

#endif