xref: /third_party/libsnd/src/new.c (revision b815c7f3)
1/*
2** Copyright (C) 2002-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#include	<fcntl.h>
23#include	<string.h>
24#include	<ctype.h>
25
26#include	"sndfile.h"
27#include	"sfendian.h"
28#include	"common.h"
29
30#if (ENABLE_EXPERIMENTAL_CODE == 0)
31
32int
33new_open	(SF_PRIVATE *psf)
34{	if (psf)
35		return SFE_UNIMPLEMENTED ;
36	return (psf && 0) ;
37} /* new_open */
38
39#else
40
41/*------------------------------------------------------------------------------
42** Macros to handle big/little endian issues.
43*/
44
45/*------------------------------------------------------------------------------
46** Typedefs.
47*/
48
49/*------------------------------------------------------------------------------
50** Private static functions.
51*/
52
53static int	new_read_header (SF_PRIVATE *psf) ;
54
55/*------------------------------------------------------------------------------
56** Public function.
57*/
58
59int
60new_open (SF_PRIVATE *psf)
61{	int	subformat, error = 0 ;
62
63	if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
64		return SFE_UNIMPLEMENTED ;
65
66	if ((error = new_read_header (psf)))
67			return error ;
68
69	if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_WVE)
70		return	SFE_BAD_OPEN_FORMAT ;
71
72	subformat = SF_CODEC (psf->sf.format) ;
73
74	return error ;
75} /* new_open */
76
77/*------------------------------------------------------------------------------
78*/
79
80static int
81new_read_header (SF_PRIVATE *psf)
82{	int marker ;
83
84	/* Set position to start of file to begin reading header. */
85	psf_binheader_readf (psf, "pm", 0, &marker) ;
86	if (marker != ALAW_MARKER)
87		return SFE_WVE_NOT_WVE ;
88
89	psf_binheader_readf (psf, "m", &marker) ;
90	if (marker != SOUN_MARKER)
91		return SFE_WVE_NOT_WVE ;
92
93	psf_binheader_readf (psf, "m", &marker) ;
94	if (marker != DFIL_MARKER)
95		return SFE_WVE_NOT_WVE ;
96
97	psf_log_printf (psf, "Read only : Psion Alaw\n"
98			"  Sample Rate : 8000\n"
99			"  Channels    : 1\n"
100			"  Encoding    : A-law\n") ;
101
102	psf->dataoffset = 0x20 ;
103	psf->datalength = psf->filelength - psf->dataoffset ;
104
105	psf->sf.format		= SF_FORMAT_WVE | SF_FORMAT_ALAW ;
106	psf->sf.samplerate	= 8000 ;
107	psf->sf.frames		= psf->datalength ;
108	psf->sf.channels	= 1 ;
109
110	return alaw_init (psf) ;
111} /* new_read_header */
112
113/*------------------------------------------------------------------------------
114*/
115
116#endif
117