libsndfile source files.
[Faustine.git] / interpretor / libsndfile-1.0.25 / src / ogg_pcm.c
1 /*
2 ** Copyright (C) 2008-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
20 #include "sfconfig.h"
21
22 #include <stdio.h>
23 #include <fcntl.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <time.h>
27 #include <math.h>
28
29 #if HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32
33 #include "sndfile.h"
34 #include "sfendian.h"
35 #include "common.h"
36
37 #if (ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_LIBS)
38
39 #include <ogg/ogg.h>
40
41 #include "ogg.h"
42
43 typedef struct
44 { int32_t serialno ;
45
46
47 void * state ;
48 } OPCM_PRIVATE ;
49
50 static int opcm_read_header (SF_PRIVATE * psf) ;
51 static int opcm_close (SF_PRIVATE *psf) ;
52
53 int
54 ogg_pcm_open (SF_PRIVATE *psf)
55 { OGG_PRIVATE* odata = psf->container_data ;
56 OPCM_PRIVATE* opcm = calloc (1, sizeof (OPCM_PRIVATE)) ;
57 int error = 0 ;
58
59 if (odata == NULL)
60 { psf_log_printf (psf, "%s : odata is NULL???\n", __func__) ;
61 return SFE_INTERNAL ;
62 } ;
63
64 psf->codec_data = opcm ;
65 if (opcm == NULL)
66 return SFE_MALLOC_FAILED ;
67
68 if (psf->file.mode == SFM_RDWR)
69 return SFE_BAD_MODE_RW ;
70
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) ;
74
75 if ((error = opcm_read_header (psf)))
76 return error ;
77
78 #if 0
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) ;
84 #endif
85 } ;
86
87 psf->codec_close = opcm_close ;
88
89 if (psf->file.mode == SFM_WRITE)
90 {
91 #if 0
92 /* Set the default opcm quality here. */
93 vdata->quality = 0.4 ;
94
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 ;
100 #endif
101
102 psf->sf.frames = SF_COUNT_MAX ; /* Unknown really */
103 psf->str_flags = SF_STR_ALLOW_START ;
104 } ;
105
106 psf->bytewidth = 1 ;
107 psf->blockwidth = psf->bytewidth * psf->sf.channels ;
108
109 #if 0
110 psf->seek = opcm_seek ;
111 psf->command = opcm_command ;
112 #endif
113
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 ;
117
118 psf->datalength = 1 ;
119 psf->dataoffset = 0 ;
120 /* End FIXME. */
121
122 return error ;
123 } /* ogg_pcm_open */
124
125 static int
126 opcm_read_header (SF_PRIVATE * UNUSED (psf))
127 {
128 return 0 ;
129 } /* opcm_read_header */
130
131 static int
132 opcm_close (SF_PRIVATE * UNUSED (psf))
133 {
134
135
136 return 0 ;
137 } /* opcm_close */
138
139
140
141 /*
142 encoded_speex_frames = (frames_per_packet * Packets)
143 = 1 * 272
144 = 272
145
146 audio_samples = encoded_speex_frames * frame_size
147 = 272 * 640
148 = 174080
149
150 duration = audio_samples / rate
151 = 174080 / 44100
152 = 3.947
153 */
154
155 #else /* ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_LIBS */
156
157 int
158 ogg_pcm_open (SF_PRIVATE *psf)
159 {
160 psf_log_printf (psf, "This version of libsndfile was compiled without Ogg/Speex support.\n") ;
161 return SFE_UNIMPLEMENTED ;
162 } /* ogg_pcm_open */
163
164 #endif