• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
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.
8 **
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.
13 **
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.
17 */
18 
19 #include	"sfconfig.h"
20 
21 #include	<stdio.h>
22 
23 #include	"sndfile.h"
24 #include	"common.h"
25 
26 /*------------------------------------------------------------------------------
27 ** Public function.
28 */
29 
30 int
raw_open(SF_PRIVATE * psf)31 raw_open	(SF_PRIVATE *psf)
32 {	int	subformat, error = SFE_NO_ERROR ;
33 
34 	subformat = SF_CODEC (psf->sf.format) ;
35 
36 	psf->endian = SF_ENDIAN (psf->sf.format) ;
37 
38 	if (CPU_IS_BIG_ENDIAN && (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU))
39 		psf->endian = SF_ENDIAN_BIG ;
40 	else if (CPU_IS_LITTLE_ENDIAN && (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU))
41 		psf->endian = SF_ENDIAN_LITTLE ;
42 
43 	psf->blockwidth = psf->bytewidth * psf->sf.channels ;
44 	psf->dataoffset = 0 ;
45 	psf->datalength = psf->filelength ;
46 
47 	switch (subformat)
48 	{	case SF_FORMAT_PCM_S8 :
49 				error = pcm_init (psf) ;
50 				break ;
51 
52 		case SF_FORMAT_PCM_U8 :
53 				error = pcm_init (psf) ;
54 				break ;
55 
56 		case SF_FORMAT_PCM_16 :
57 		case SF_FORMAT_PCM_24 :
58 		case SF_FORMAT_PCM_32 :
59 				error = pcm_init (psf) ;
60 				break ;
61 
62 		case SF_FORMAT_ULAW :
63 				error = ulaw_init (psf) ;
64 				break ;
65 
66 		case SF_FORMAT_ALAW :
67 				error = alaw_init (psf) ;
68 				break ;
69 
70 		case SF_FORMAT_GSM610 :
71 				error = gsm610_init (psf) ;
72 				break ;
73 
74 		/* Lite remove start */
75 
76 		case SF_FORMAT_NMS_ADPCM_16 :
77 		case SF_FORMAT_NMS_ADPCM_24 :
78 		case SF_FORMAT_NMS_ADPCM_32 :
79 				error = nms_adpcm_init (psf) ;
80 				break ;
81 
82 		case SF_FORMAT_FLOAT :
83 				error = float32_init (psf) ;
84 				break ;
85 
86 		case SF_FORMAT_DOUBLE :
87 				error = double64_init (psf) ;
88 				break ;
89 
90 		case SF_FORMAT_DWVW_12 :
91 				error = dwvw_init (psf, 12) ;
92 				break ;
93 
94 		case SF_FORMAT_DWVW_16 :
95 				error = dwvw_init (psf, 16) ;
96 				break ;
97 
98 		case SF_FORMAT_DWVW_24 :
99 				error = dwvw_init (psf, 24) ;
100 				break ;
101 
102 		case SF_FORMAT_VOX_ADPCM :
103 				error = vox_adpcm_init (psf) ;
104 				break ;
105 		/* Lite remove end */
106 
107 		default : return SFE_BAD_OPEN_FORMAT ;
108 		} ;
109 
110 	return error ;
111 } /* raw_open */
112