fba7b0cfd1a0720a4cc3425d65b15950cf6edec6
2 ** Copyright (C) 2002-2011 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
)
74 if (psf
->file
.mode
== SFM_READ
|| (psf
->file
.mode
== SFM_RDWR
&& psf
->filelength
> 0))
75 { if ((error
= dwd_read_header (psf
)))
79 if ((SF_CONTAINER (psf
->sf
.format
)) != SF_FORMAT_DWD
)
80 return SFE_BAD_OPEN_FORMAT
;
82 if (psf
->file
.mode
== SFM_WRITE
|| psf
->file
.mode
== SFM_RDWR
)
84 /*-psf->endian = SF_ENDIAN (psf->sf.format) ;
85 if (CPU_IS_LITTLE_ENDIAN && psf->endian == SF_ENDIAN_CPU)
86 psf->endian = SF_ENDIAN_LITTLE ;
87 else if (psf->endian != SF_ENDIAN_LITTLE)
88 psf->endian = SF_ENDIAN_BIG ;
90 if (! (encoding = dwd_write_header (psf, SF_FALSE)))
93 psf->write_header = dwd_write_header ;
97 psf
->container_close
= dwd_close
;
99 /*-psf->blockwidth = psf->bytewidth * psf->sf.channels ;-*/
104 /*------------------------------------------------------------------------------
108 dwd_close (SF_PRIVATE
* UNUSED (psf
))
113 /* This struct contains all the fields of interest om the DWD header, but does not
114 ** do so in the same order and layout as the actual file, header.
115 ** No assumptions are made about the packing of this struct.
118 { unsigned char major
, minor
, compression
, channels
, bitwidth
;
119 unsigned short srate
, maxval
;
120 unsigned int id
, datalen
, frames
, offset
;
124 dwd_read_header (SF_PRIVATE
*psf
)
127 memset (psf
->u
.cbuf
, 0, sizeof (psf
->u
.cbuf
)) ;
128 /* Set position to start of file to begin reading header. */
129 psf_binheader_readf (psf
, "pb", 0, psf
->u
.cbuf
, DWD_IDENTIFIER_LEN
) ;
131 if (memcmp (psf
->u
.cbuf
, DWD_IDENTIFIER
, DWD_IDENTIFIER_LEN
) != 0)
132 return SFE_DWD_NO_DWD
;
134 psf_log_printf (psf
, "Read only : DiamondWare Digitized (.dwd)\n", psf
->u
.cbuf
) ;
136 psf_binheader_readf (psf
, "11", &dwdh
.major
, &dwdh
.minor
) ;
137 psf_binheader_readf (psf
, "e4j1", &dwdh
.id
, 1, &dwdh
.compression
) ;
138 psf_binheader_readf (psf
, "e211", &dwdh
.srate
, &dwdh
.channels
, &dwdh
.bitwidth
) ;
139 psf_binheader_readf (psf
, "e24", &dwdh
.maxval
, &dwdh
.datalen
) ;
140 psf_binheader_readf (psf
, "e44", &dwdh
.frames
, &dwdh
.offset
) ;
142 psf_log_printf (psf
, " Version Major : %d\n Version Minor : %d\n Unique ID : %08X\n",
143 dwdh
.major
, dwdh
.minor
, dwdh
.id
) ;
144 psf_log_printf (psf
, " Compression : %d => ", dwdh
.compression
) ;
146 if (dwdh
.compression
!= 0)
147 { psf_log_printf (psf
, "Unsupported compression\n") ;
148 return SFE_DWD_COMPRESSION
;
151 psf_log_printf (psf
, "None\n") ;
153 psf_log_printf (psf
, " Sample Rate : %d\n Channels : %d\n"
155 dwdh
.srate
, dwdh
.channels
, dwdh
.bitwidth
) ;
157 switch (dwdh
.bitwidth
)
159 psf
->sf
.format
= SF_FORMAT_DWD
| SF_FORMAT_PCM_S8
;
164 psf
->sf
.format
= SF_FORMAT_DWD
| SF_FORMAT_PCM_16
;
169 psf_log_printf (psf
, "*** Bad bit width %d\n", dwdh
.bitwidth
) ;
170 return SFE_DWD_BAND_BIT_WIDTH
;
173 if (psf
->filelength
!= dwdh
.offset
+ dwdh
.datalen
)
174 { psf_log_printf (psf
, " Data Length : %d (should be %D)\n", dwdh
.datalen
, psf
->filelength
- dwdh
.offset
) ;
175 dwdh
.datalen
= (unsigned int) (psf
->filelength
- dwdh
.offset
) ;
178 psf_log_printf (psf
, " Data Length : %d\n", dwdh
.datalen
) ;
180 psf_log_printf (psf
, " Max Value : %d\n", dwdh
.maxval
) ;
181 psf_log_printf (psf
, " Frames : %d\n", dwdh
.frames
) ;
182 psf_log_printf (psf
, " Data Offset : %d\n", dwdh
.offset
) ;
184 psf
->datalength
= dwdh
.datalen
;
185 psf
->dataoffset
= dwdh
.offset
;
187 psf
->endian
= SF_ENDIAN_LITTLE
;
189 psf
->sf
.samplerate
= dwdh
.srate
;
190 psf
->sf
.channels
= dwdh
.channels
;
191 psf
->sf
.sections
= 1 ;
193 return pcm_init (psf
) ;
194 } /* dwd_read_header */
196 /*------------------------------------------------------------------------------