2 ** Copyright (C) 2008-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.
37 #if (ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_LIBS)
50 static int opcm_read_header (SF_PRIVATE
* psf
) ;
51 static int opcm_close (SF_PRIVATE
*psf
) ;
54 ogg_pcm_open (SF_PRIVATE
*psf
)
55 { OGG_PRIVATE
* odata
= psf
->container_data
;
56 OPCM_PRIVATE
* opcm
= calloc (1, sizeof (OPCM_PRIVATE
)) ;
60 { psf_log_printf (psf
, "%s : odata is NULL???\n", __func__
) ;
64 psf
->codec_data
= opcm
;
66 return SFE_MALLOC_FAILED
;
68 if (psf
->file
.mode
== SFM_RDWR
)
69 return SFE_BAD_MODE_RW
;
71 if (psf
->file
.mode
== SFM_READ
)
72 { /* Call this here so it only gets called once, so no memory is leaked. */
73 ogg_sync_init (&odata
->osync
) ;
75 if ((error
= opcm_read_header (psf
)))
79 psf
->read_short
= opcm_read_s
;
80 psf
->read_int
= opcm_read_i
;
81 psf
->read_float
= opcm_read_f
;
82 psf
->read_double
= opcm_read_d
;
83 psf
->sf
.frames
= opcm_length (psf
) ;
87 psf
->codec_close
= opcm_close
;
89 if (psf
->file
.mode
== SFM_WRITE
)
92 /* Set the default opcm quality here. */
93 vdata
->quality
= 0.4 ;
95 psf
->write_header
= opcm_write_header
;
96 psf
->write_short
= opcm_write_s
;
97 psf
->write_int
= opcm_write_i
;
98 psf
->write_float
= opcm_write_f
;
99 psf
->write_double
= opcm_write_d
;
102 psf
->sf
.frames
= SF_COUNT_MAX
; /* Unknown really */
103 psf
->str_flags
= SF_STR_ALLOW_START
;
107 psf
->blockwidth
= psf
->bytewidth
* psf
->sf
.channels
;
110 psf
->seek
= opcm_seek
;
111 psf
->command
= opcm_command
;
114 /* FIXME, FIXME, FIXME : Hack these here for now and correct later. */
115 psf
->sf
.format
= SF_FORMAT_OGG
| SF_FORMAT_SPEEX
;
116 psf
->sf
.sections
= 1 ;
118 psf
->datalength
= 1 ;
119 psf
->dataoffset
= 0 ;
126 opcm_read_header (SF_PRIVATE
* UNUSED (psf
))
129 } /* opcm_read_header */
132 opcm_close (SF_PRIVATE
* UNUSED (psf
))
142 encoded_speex_frames = (frames_per_packet * Packets)
146 audio_samples = encoded_speex_frames * frame_size
150 duration = audio_samples / rate
155 #else /* ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_LIBS */
158 ogg_pcm_open (SF_PRIVATE
*psf
)
160 psf_log_printf (psf
, "This version of libsndfile was compiled without Ogg/Speex support.\n") ;
161 return SFE_UNIMPLEMENTED
;