2
** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
4
** This program is free software; you can redistribute it and/or modify
5
** it under the terms of the GNU Lesser General Public License as published by
6
** the Free Software Foundation; either version 2.1 of the License, or
7
** (at your option) any later version.
9
** This program is distributed in the hope that it will be useful,
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
** GNU Lesser General Public License for more details.
14
** You should have received a copy of the GNU Lesser General Public License
15
** along with this program; if not, write to the Free Software
16
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30
#if (ENABLE_EXPERIMENTAL_CODE == 0)
33
dwd_open (SF_PRIVATE *psf)
35
return SFE_UNIMPLEMENTED ;
41
/*------------------------------------------------------------------------------
42
** Macros to handle big/little endian issues.
45
#define SFE_DWD_NO_DWD 1666
46
#define SFE_DWD_BAND_BIT_WIDTH 1667
47
#define SFE_DWD_COMPRESSION 1668
49
#define DWD_IDENTIFIER "DiamondWare Digitized\n\0\x1a"
50
#define DWD_IDENTIFIER_LEN 24
52
#define DWD_HEADER_LEN 57
54
/*------------------------------------------------------------------------------
58
/*------------------------------------------------------------------------------
59
** Private static functions.
62
static int dwd_read_header (SF_PRIVATE *psf) ;
64
static int dwd_close (SF_PRIVATE *psf) ;
66
/*------------------------------------------------------------------------------
71
dwd_open (SF_PRIVATE *psf)
72
{ int subformat, error = 0 ;
74
if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR && psf->filelength > 0))
75
{ if ((error = dwd_read_header (psf)))
79
if ((psf->sf.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_DWD)
80
return SFE_BAD_OPEN_FORMAT ;
82
subformat = psf->sf.format & SF_FORMAT_SUBMASK ;
84
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
86
/*-psf->endian = psf->sf.format & SF_FORMAT_ENDMASK ;
87
if (CPU_IS_LITTLE_ENDIAN && psf->endian == SF_ENDIAN_CPU)
88
psf->endian = SF_ENDIAN_LITTLE ;
89
else if (psf->endian != SF_ENDIAN_LITTLE)
90
psf->endian = SF_ENDIAN_BIG ;
92
if (! (encoding = dwd_write_header (psf, SF_FALSE)))
95
psf->write_header = dwd_write_header ;
99
psf->container_close = dwd_close ;
101
/*-psf->blockwidth = psf->bytewidth * psf->sf.channels ;-*/
106
/*------------------------------------------------------------------------------
110
dwd_close (SF_PRIVATE *psf)
117
/* This struct contains all the fields of interest om the DWD header, but does not
118
** do so in the same order and layout as the actual file, header.
119
** No assumptions are made about the packing of this struct.
122
{ unsigned char major, minor, compression, channels, bitwidth ;
123
unsigned short srate, maxval ;
124
unsigned int id, datalen, frames, offset ;
128
dwd_read_header (SF_PRIVATE *psf)
131
memset (psf->u.cbuf, 0, sizeof (psf->u.cbuf)) ;
132
/* Set position to start of file to begin reading header. */
133
psf_binheader_readf (psf, "pb", 0, psf->u.cbuf, DWD_IDENTIFIER_LEN) ;
135
if (memcmp (psf->u.cbuf, DWD_IDENTIFIER, DWD_IDENTIFIER_LEN) != 0)
136
return SFE_DWD_NO_DWD ;
138
psf_log_printf (psf, "Read only : DiamondWare Digitized (.dwd)\n", psf->u.cbuf) ;
140
psf_binheader_readf (psf, "11", &dwdh.major, &dwdh.minor) ;
141
psf_binheader_readf (psf, "e4j1", &dwdh.id, 1, &dwdh.compression) ;
142
psf_binheader_readf (psf, "e211", &dwdh.srate, &dwdh.channels, &dwdh.bitwidth) ;
143
psf_binheader_readf (psf, "e24", &dwdh.maxval, &dwdh.datalen) ;
144
psf_binheader_readf (psf, "e44", &dwdh.frames, &dwdh.offset) ;
146
psf_log_printf (psf, " Version Major : %d\n Version Minor : %d\n Unique ID : %08X\n",
147
dwdh.major, dwdh.minor, dwdh.id) ;
148
psf_log_printf (psf, " Compression : %d => ", dwdh.compression) ;
150
if (dwdh.compression != 0)
151
{ psf_log_printf (psf, "Unsupported compression\n") ;
152
return SFE_DWD_COMPRESSION ;
155
psf_log_printf (psf, "None\n") ;
157
psf_log_printf (psf, " Sample Rate : %d\n Channels : %d\n"
159
dwdh.srate, dwdh.channels, dwdh.bitwidth) ;
161
switch (dwdh.bitwidth)
163
psf->sf.format = SF_FORMAT_DWD | SF_FORMAT_PCM_S8 ;
168
psf->sf.format = SF_FORMAT_DWD | SF_FORMAT_PCM_16 ;
173
psf_log_printf (psf, "*** Bad bit width %d\n", dwdh.bitwidth) ;
174
return SFE_DWD_BAND_BIT_WIDTH ;
177
if (psf->filelength != dwdh.offset + dwdh.datalen)
178
{ psf_log_printf (psf, " Data Length : %d (should be %D)\n", dwdh.datalen, psf->filelength - dwdh.offset) ;
179
dwdh.datalen = (unsigned int) (psf->filelength - dwdh.offset) ;
182
psf_log_printf (psf, " Data Length : %d\n", dwdh.datalen) ;
184
psf_log_printf (psf, " Max Value : %d\n", dwdh.maxval) ;
185
psf_log_printf (psf, " Frames : %d\n", dwdh.frames) ;
186
psf_log_printf (psf, " Data Offset : %d\n", dwdh.offset) ;
188
psf->datalength = dwdh.datalen ;
189
psf->dataoffset = dwdh.offset ;
191
psf->endian = SF_ENDIAN_LITTLE ;
193
psf->sf.samplerate = dwdh.srate ;
194
psf->sf.channels = dwdh.channels ;
195
psf->sf.sections = 1 ;
197
return pcm_init (psf) ;
198
} /* dwd_read_header */
200
/*------------------------------------------------------------------------------
205
** Do not edit or modify anything in this comment block.
206
** The arch-tag line is a file identity tag for the GNU Arch
207
** revision control system.
209
** arch-tag: a5e1d2a6-a840-4039-a0e7-e1a43eb05a4f