1
/* $Id: wave.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJMEDIA_WAVE_H__
21
#define __PJMEDIA_WAVE_H__
26
* @brief WAVE file manipulation.
28
#include <pjmedia/types.h>
31
* @defgroup PJMEDIA_FILE_FORMAT File Formats
32
* @brief Supported file formats
37
* @defgroup PJMEDIA_WAVE WAVE Header
38
* @ingroup PJMEDIA_FILE_FORMAT
39
* @brief Representation of RIFF/WAVE file format
42
* This the the low level representation of RIFF/WAVE file format. For
43
* higher abstraction, please see \ref PJMEDIA_FILE_PLAY and
44
* \ref PJMEDIA_FILE_REC.
51
* Standard RIFF tag to identify RIFF file format in the WAVE header.
53
#define PJMEDIA_RIFF_TAG ('F'<<24|'F'<<16|'I'<<8|'R')
56
* Standard WAVE tag to identify WAVE header.
58
#define PJMEDIA_WAVE_TAG ('E'<<24|'V'<<16|'A'<<8|'W')
61
* Standard FMT tag to identify format chunks.
63
#define PJMEDIA_FMT_TAG (' '<<24|'t'<<16|'m'<<8|'f')
66
* Standard DATA tag to identify data chunks.
68
#define PJMEDIA_DATA_TAG ('a'<<24|'t'<<16|'a'<<8|'d')
71
* Standard FACT tag to identify fact chunks.
73
#define PJMEDIA_FACT_TAG ('t'<<24|'c'<<16|'a'<<8|'f')
77
* Enumeration of format compression tag.
80
PJMEDIA_WAVE_FMT_TAG_PCM = 1,
81
PJMEDIA_WAVE_FMT_TAG_ALAW = 6,
82
PJMEDIA_WAVE_FMT_TAG_ULAW = 7
83
} pjmedia_wave_fmt_tag;
87
* This file describes the simpler/canonical version of a WAVE file.
88
* It does not support the full RIFF format specification.
91
struct pjmedia_wave_hdr
93
/** This structure describes RIFF WAVE file header */
95
pj_uint32_t riff; /**< "RIFF" ASCII tag. */
96
pj_uint32_t file_len; /**< File length minus 8 bytes */
97
pj_uint32_t wave; /**< "WAVE" ASCII tag. */
100
/** This structure describes format chunks/header */
102
pj_uint32_t fmt; /**< "fmt " ASCII tag. */
103
pj_uint32_t len; /**< 16 for PCM. */
104
pj_uint16_t fmt_tag; /**< 1 for PCM */
105
pj_uint16_t nchan; /**< Number of channels. */
106
pj_uint32_t sample_rate; /**< Sampling rate. */
107
pj_uint32_t bytes_per_sec; /**< Average bytes per second. */
108
pj_uint16_t block_align; /**< nchannels * bits / 8 */
109
pj_uint16_t bits_per_sample; /**< Bits per sample. */
112
/** The data header preceeds the actual data in the file. */
114
pj_uint32_t data; /**< "data" ASCII tag. */
115
pj_uint32_t len; /**< Data length. */
121
* @see pjmedia_wave_hdr
123
typedef struct pjmedia_wave_hdr pjmedia_wave_hdr;
126
* This structure describes generic RIFF subchunk header.
128
typedef struct pjmedia_wave_subchunk
130
pj_uint32_t id; /**< Subchunk ASCII tag. */
131
pj_uint32_t len; /**< Length following this field */
132
} pjmedia_wave_subchunk;
136
* Normalize subchunk header from little endian (the representation of
137
* RIFF file) into host's endian.
139
#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0
140
# define PJMEDIA_WAVE_NORMALIZE_SUBCHUNK(ch) \
142
(ch)->id = pj_swap32((ch)->id); \
143
(ch)->len = pj_swap32((ch)->len); \
146
# define PJMEDIA_WAVE_NORMALIZE_SUBCHUNK(ch)
151
* On big-endian hosts, this function swaps the byte order of the values
152
* in the WAVE header fields. On little-endian hosts, this function does
155
* Application SHOULD call this function after reading the WAVE header
156
* chunks from a file.
158
* @param hdr The WAVE header.
160
PJ_DECL(void) pjmedia_wave_hdr_file_to_host( pjmedia_wave_hdr *hdr );
164
* On big-endian hosts, this function swaps the byte order of the values
165
* in the WAVE header fields. On little-endian hosts, this function does
168
* Application SHOULD call this function before writing the WAVE header
171
* @param hdr The WAVE header.
173
PJ_DECL(void) pjmedia_wave_hdr_host_to_file( pjmedia_wave_hdr *hdr );
183
#endif /* __PJMEDIA_WAVE_H__ */