PortAudio 2.0
write_wav.h
Go to the documentation of this file.
1/*
2 * PortAudio Portable Real-Time Audio Library
3 * Latest Version at: http://www.portaudio.com
4 *
5 * Copyright (c) 1999-2010 Phil Burk and Ross Bencina
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction,
10 * including without limitation the rights to use, copy, modify, merge,
11 * publish, distribute, sublicense, and/or sell copies of the Software,
12 * and to permit persons to whom the Software is furnished to do so,
13 * subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27/*
28 * The text above constitutes the entire PortAudio license; however,
29 * the PortAudio community also makes the following non-binding requests:
30 *
31 * Any person wishing to distribute modifications to the Software is
32 * requested to send the modifications to the original developer so that
33 * they can be incorporated into the canonical version. It is also
34 * requested that these non-binding requests be included along with the
35 * license above.
36 */
37#ifndef _WAV_WRITER_H
38#define _WAV_WRITER_H
39
40/*
41 * WAV file writer.
42 *
43 * Author: Phil Burk
44 */
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/* Define WAV Chunk and FORM types as 4 byte integers. */
51#define RIFF_ID (('R'<<24) | ('I'<<16) | ('F'<<8) | 'F')
52#define WAVE_ID (('W'<<24) | ('A'<<16) | ('V'<<8) | 'E')
53#define FMT_ID (('f'<<24) | ('m'<<16) | ('t'<<8) | ' ')
54#define DATA_ID (('d'<<24) | ('a'<<16) | ('t'<<8) | 'a')
55#define FACT_ID (('f'<<24) | ('a'<<16) | ('c'<<8) | 't')
56
57/* Errors returned by Audio_ParseSampleImage_WAV */
58#define WAV_ERR_CHUNK_SIZE (-1) /* Chunk size is illegal or past file size. */
59#define WAV_ERR_FILE_TYPE (-2) /* Not a WAV file. */
60#define WAV_ERR_ILLEGAL_VALUE (-3) /* Illegal or unsupported value. Eg. 927 bits/sample */
61#define WAV_ERR_FORMAT_TYPE (-4) /* Unsupported format, eg. compressed. */
62#define WAV_ERR_TRUNCATED (-5) /* End of file missing. */
63
64/* WAV PCM data format ID */
65#define WAVE_FORMAT_PCM (1)
66#define WAVE_FORMAT_IMA_ADPCM (0x0011)
67
68
69typedef struct WAV_Writer_s
70{
71 FILE *fid;
72 /* Offset in file for data size. */
76
77/*********************************************************************************
78 * Open named file and write WAV header to the file.
79 * The header includes the DATA chunk type and size.
80 * Returns number of bytes written to file or negative error code.
81 */
82long Audio_WAV_OpenWriter( WAV_Writer *writer, const char *fileName, int frameRate, int samplesPerFrame );
83
84/*********************************************************************************
85 * Write to the data chunk portion of a WAV file.
86 * Returns bytes written or negative error code.
87 */
89 short *samples,
90 int numSamples
91 );
92
93/*********************************************************************************
94 * Close WAV file.
95 * Update chunk sizes so it can be read by audio applications.
96 */
97long Audio_WAV_CloseWriter( WAV_Writer *writer );
98
99#ifdef __cplusplus
100};
101#endif
102
103#endif /* _WAV_WRITER_H */
Definition write_wav.h:70
FILE * fid
Definition write_wav.h:71
int dataSize
Definition write_wav.h:74
int dataSizeOffset
Definition write_wav.h:73
struct WAV_Writer_s WAV_Writer
long Audio_WAV_OpenWriter(WAV_Writer *writer, const char *fileName, int frameRate, int samplesPerFrame)
Definition write_wav.c:88
long Audio_WAV_WriteShorts(WAV_Writer *writer, short *samples, int numSamples)
Definition write_wav.c:140
long Audio_WAV_CloseWriter(WAV_Writer *writer)
Definition write_wav.c:172