1
//=========================================================
4
// $Id: sndfile.h,v 1.3 2002/02/13 11:42:56 muse Exp $
6
// (C) Copyright 2001 Werner Schweer (ws@seh.de)
7
// parts based on libsndfile:
8
// Copyright (C) 1999-2000 Erik de Castro Lopo <erikd@zip.com.au>
9
//=========================================================
18
#include <sys/types.h>
20
#include <qfileinfo.h>
22
const int cacheMag = 128;
24
#define SF_BUFFER_LEN 4096
25
#define SF_FILENAME_LEN 256
26
#define SF_HEADER_LEN 2048
28
#define BITWIDTH2BYTES(x) (((x) + 7) / 8)
37
SF_ENDIAN_LITTLE = 100,
71
SFE_WAV_BAD_BLOCKALIGN,
73
SFE_WAV_ADPCM_NOT4BIT,
74
SFE_WAV_ADPCM_CHANNELS,
75
SFE_WAV_GSM610_FORMAT,
76
SFE_WAV_UNKNOWN_CHUNK,
79
SFE_AIFF_UNKNOWN_CHUNK,
84
SFE_AU_UNKNOWN_FORMAT,
87
SFE_RAW_READ_BAD_SPEC,
92
SFE_PAF_UNKNOWN_FORMAT,
101
SFE_NIST_BAD_ENCODING,
103
SFE_MAX_ERROR // This must be last in list.
106
void endswap_short_array(short *ptr, int len);
107
void endswap_int_array(int *ptr, int len);
109
/* The following file types can be read and written.
110
** A file type would consist of a major type (ie SF_FORMAT_WAV) bitwise
111
** ORed with a minor type (ie SF_FORMAT_PCM). SF_FORMAT_TYPEMASK and
112
** SF_FORMAT_SUBMASK can be used to separate the major and minor file
117
SF_FORMAT_WAV = 0x10000, // Microsoft WAV format (big endian).
118
SF_FORMAT_AIFF = 0x20000, // Apple/SGI AIFF format (little endian).
119
SF_FORMAT_AU = 0x30000, // Sun/NeXT AU format (big endian).
120
SF_FORMAT_AULE = 0x40000, // DEC AU format (little endian).
121
SF_FORMAT_RAW = 0x50000, // RAW PCM data.
122
SF_FORMAT_PAF = 0x60000, // Ensoniq PARIS file format.
123
SF_FORMAT_SVX = 0x70000, // Amiga IFF / SVX8 / SV16 format.
124
SF_FORMAT_NIST = 0x80000, // Sphere NIST format.
126
SF_FORMAT_PCM = 0x0001, // PCM data in 8, 16, 24 or 32 bits.
127
SF_FORMAT_FLOAT = 0x0002, // 32 bit floats.
128
SF_FORMAT_ULAW = 0x0003, // U-Law encoded.
129
SF_FORMAT_ALAW = 0x0004, // A-Law encoded.
130
SF_FORMAT_IMA_ADPCM = 0x0005, // IMA ADPCM.
131
SF_FORMAT_MS_ADPCM = 0x0006, // Microsoft ADPCM.
133
SF_FORMAT_PCM_BE = 0x0007, // Big endian PCM data.
134
SF_FORMAT_PCM_LE = 0x0008, // Little endian PCM data.
135
SF_FORMAT_PCM_S8 = 0x0009, // Signed 8 bit PCM.
136
SF_FORMAT_PCM_U8 = 0x000A, // Unsigned 8 bit PCM.
138
SF_FORMAT_SVX_FIB = 0x000B, // SVX Fibonacci Delta encoding.
139
SF_FORMAT_SVX_EXP = 0x000C, // SVX Exponential Delta encoding.
141
SF_FORMAT_GSM610 = 0x000D, // GSM 6.10 encoding.
143
SF_FORMAT_G721_32 = 0x000E, // 32kbs G721 ADPCM encoding.
144
SF_FORMAT_G723_24 = 0x000F, // 24kbs G723 ADPCM encoding.
146
SF_FORMAT_SUBMASK = 0xFFFF,
147
SF_FORMAT_TYPEMASK = 0x7FFF0000
150
//---------------------------------------------------------
152
//---------------------------------------------------------
156
class SndFileFormat {
157
size_t unimpl() const;
161
float buffer[SF_BUFFER_LEN];
164
SndFileFormat(SndFile* s) { sfile = s; }
165
virtual off_t seek(off_t, int) { return unimpl(); }
166
virtual size_t read(float**, size_t) { return unimpl(); }
167
virtual size_t write(float**, size_t) { return unimpl(); }
168
virtual void close() {}
171
//---------------------------------------------------------
174
//---------------------------------------------------------
183
//---------------------------------------------------------
185
//---------------------------------------------------------
189
int refs; // reference count to file
194
unsigned long current;
196
unsigned int _blockwidth; // Size in bytes of one set of interleaved samples.
197
unsigned long _dataoffset; // Offset in number of bytes from beginning of file.
200
int csize; // frames in cache
203
unsigned _samplerate;
207
unsigned _pcmbitwidth;
211
unsigned int _bytewidth; // Size in bytes of one sample (one channel).
213
unsigned long _filelength;
214
unsigned long _datalength; // Length in bytes of the audio data.
218
int wav_open_write();
220
bool validateSfinfo();
221
void readCache(const QString& path);
222
void writeCache(const QString& path);
223
int read_fmt_chunk(WAV_FMT* wav_fmt);
224
int write_header(WAV_FMT *wav_fmt, unsigned int size, int do_fact);
227
SndFile(const QString path);
232
FILE* file() const { return _file; }
237
unsigned samples() const { return _samples; }
238
unsigned channels() const { return _channels; }
239
unsigned samplerate() const { return _samplerate; }
240
unsigned format() const { return _format; }
241
int sampleBits() const { return _pcmbitwidth; }
242
void setFormat(int fmt, int ch, int rate, int bits);
244
size_t read(float**, size_t);
245
size_t write(float**, size_t);
246
off_t seek(off_t frames, int whence);
247
void read(SampleV* s, int mag, unsigned pos);
249
void setErrno(int n) { _errno = n; }
251
QString path() const { return finfo->filePath(); }
252
QString basename() const { return finfo->baseName(); }
253
QString name() const { return finfo->fileName(); }
255
int references() { return refs; }
259
unsigned dataoffset() const { return _dataoffset; }
260
unsigned long filelength() const { return _filelength; }
261
void setFilelength(unsigned long v) { _filelength = v; }
262
unsigned long datalength() { return _datalength; }
263
void setDatalength(unsigned long v) { _datalength = v; }
264
int mode() const { return _mode; }
265
unsigned int bytewidth() const { return _bytewidth; }
266
void setSamples(unsigned v) { _samples = v; }
267
unsigned blockwidth() const { return _blockwidth; }
268
void setBlockwidth(unsigned v) { _blockwidth = v; }
271
//---------------------------------------------------------
273
//---------------------------------------------------------
275
class SndFileList : public std::list<SndFile*> {
277
SndFile* search(const QString& name);
280
typedef SndFileList::iterator iSndFile;