annotate decoders/ogg.c @ 169:a1255c02bab1

Updated.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 26 Nov 2001 04:41:18 +0000
parents 1df5c106504e
children 47cc2de2ae36
rev   line source
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * SDL_sound -- An abstract sound format decoding API.
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 * Copyright (C) 2001 Ryan C. Gordon.
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 *
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 *
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 *
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 /*
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 * Ogg Vorbis decoder for SDL_sound.
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 *
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 * This driver handles .OGG audio files, and depends on libvorbisfile to
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 * do the actual decoding work. libvorbisfile is part of libvorbis, which
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 * is part of the Ogg Vorbis project.
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 *
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 * Ogg Vorbis: http://www.xiph.org/ogg/vorbis/
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 * vorbisfile documentation: http://www.xiph.org/ogg/vorbis/doc/vorbisfile/
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 *
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 * Please see the file LICENSE in the source's root directory.
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 *
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
106
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
35 #if HAVE_CONFIG_H
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
36 # include <config.h>
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
37 #endif
100
6d9fdec2f708 added config.h, added --enable-debug flag, various other changes to the build system
fingolfin
parents: 63
diff changeset
38
104
103cfcb3c014 Updated to fix build system problem.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
39 #ifdef SOUND_SUPPORTS_OGG
103cfcb3c014 Updated to fix build system problem.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
40
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #include <stdio.h>
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #include <stdlib.h>
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 #include <string.h>
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #include <math.h>
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #include <assert.h>
106
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
46
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
47 #include "SDL_sound.h"
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
48
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
49 #define __SDL_SOUND_INTERNAL__
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
50 #include "SDL_sound_internal.h"
40de367eb59e Changing my include structure to do this right.
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
51
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 #include "vorbis/codec.h"
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #include "vorbis/vorbisfile.h"
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55
47
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
56 static int OGG_init(void);
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
57 static void OGG_quit(void);
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 static int OGG_open(Sound_Sample *sample, const char *ext);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 static void OGG_close(Sound_Sample *sample);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 static Uint32 OGG_read(Sound_Sample *sample);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 122
diff changeset
62 static const char *extensions_ogg[] = { "OGG", NULL };
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 const Sound_DecoderFunctions __Sound_DecoderFunctions_OGG =
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 {
149
1df5c106504e Decoders can now list multiple file extensions.
Ryan C. Gordon <icculus@icculus.org>
parents: 122
diff changeset
66 extensions_ogg,
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 "Ogg Vorbis audio through VorbisFile",
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 "Ryan C. Gordon <icculus@clutteredmind.org>",
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 "http://www.icculus.org/SDL_sound/"
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 },
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71
47
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
72 OGG_init, /* init() method */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
73 OGG_quit, /* quit() method */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
74 OGG_open, /* open() method */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
75 OGG_close, /* close() method */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
76 OGG_read /* read() method */
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 };
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79
47
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
80 static int OGG_init(void)
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
81 {
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
82 return(1); /* always succeeds. */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
83 } /* OGG_init */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
84
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
85
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
86 static void OGG_quit(void)
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
87 {
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
88 /* it's a no-op. */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
89 } /* OGG_quit */
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
90
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
91
ea58bc3b15d7 Added init() and quit() methods.
Ryan C. Gordon <icculus@icculus.org>
parents: 24
diff changeset
92
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 /*
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 * These are callbacks from vorbisfile that let them read data from
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 * a RWops...
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97
63
9669aa13d3e0 Changes in preparation for autoconf, and the RWops wrappers changed to
Ryan C. Gordon <icculus@icculus.org>
parents: 59
diff changeset
98 static size_t RWops_ogg_read(void *ptr, size_t size, size_t nmemb, void *datasource)
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 return((size_t) SDL_RWread((SDL_RWops *) datasource, ptr, size, nmemb));
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 } /* RWops_ogg_read */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102
122
095a066b2cd2 Portability fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 106
diff changeset
103 static int RWops_ogg_seek(void *datasource, ogg_int64_t offset, int whence)
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 return(SDL_RWseek((SDL_RWops *) datasource, offset, whence));
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 } /* RWops_ogg_seek */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107
63
9669aa13d3e0 Changes in preparation for autoconf, and the RWops wrappers changed to
Ryan C. Gordon <icculus@icculus.org>
parents: 59
diff changeset
108 static int RWops_ogg_close(void *datasource)
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 /* do nothing; SDL_sound will delete the RWops at a higher level. */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 return(0); /* this is success in fclose(), so I guess that's okay. */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 } /* RWops_ogg_close */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113
63
9669aa13d3e0 Changes in preparation for autoconf, and the RWops wrappers changed to
Ryan C. Gordon <icculus@icculus.org>
parents: 59
diff changeset
114 static long RWops_ogg_tell(void *datasource)
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 return((long) SDL_RWtell((SDL_RWops *) datasource));
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 } /* RWops_ogg_tell */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 static const ov_callbacks RWops_ogg_callbacks =
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 RWops_ogg_read,
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 RWops_ogg_seek,
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 RWops_ogg_close,
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 RWops_ogg_tell
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 };
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 /* Return a human readable version of an VorbisFile error code... */
59
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
129 #if (defined DEBUG_CHATTER)
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 static const char *ogg_error(int errnum)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 switch(errnum)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 case OV_EREAD:
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 return("i/o error");
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 case OV_ENOTVORBIS:
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 return("not a vorbis file");
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 case OV_EVERSION:
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 return("Vorbis version mismatch");
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 case OV_EBADHEADER:
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 return("invalid Vorbis bitstream header");
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 case OV_EFAULT:
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 return("internal logic fault in Vorbis library");
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 } /* switch */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 return("unknown error");
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 } /* ogg_error */
59
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
148 #endif
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 static __inline__ void output_ogg_comments(OggVorbis_File *vf)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 #if (defined DEBUG_CHATTER)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 int i;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 vorbis_comment *vc = ov_comment(vf, -1);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 if (vc == NULL)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 return;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158
59
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
159 SNDDBG(("OGG: vendor == [%s].\n", vc->vendor));
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 for (i = 0; i < vc->comments; i++)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 {
59
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
162 SNDDBG(("OGG: user comment [%s].\n", vc->user_comments[i]));
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 } /* for */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 #endif
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 } /* output_ogg_comments */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 static int OGG_open(Sound_Sample *sample, const char *ext)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 int rc;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 OggVorbis_File *vf;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 vorbis_info *info;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 vf = (OggVorbis_File *) malloc(sizeof (OggVorbis_File));
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 BAIL_IF_MACRO(vf == NULL, ERR_OUT_OF_MEMORY, 0);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 rc = ov_open_callbacks(internal->rw, vf, NULL, 0, RWops_ogg_callbacks);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 if (rc != 0)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 {
59
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
181 SNDDBG(("OGG: can't grok data. reason: [%s].\n", ogg_error(rc)));
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 free(vf);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 BAIL_MACRO("OGG: Not valid Ogg Vorbis data.", 0);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 } /* if */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 info = ov_info(vf, -1);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 if (info == NULL)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 ov_clear(vf);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 free(vf);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 BAIL_MACRO("OGG: failed to retrieve bitstream info", 0);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 } /* if */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193
59
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
194 SNDDBG(("OGG: Accepting data stream.\n"));
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 output_ogg_comments(vf);
59
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
197 SNDDBG(("OGG: bitstream version == (%d).\n", info->version));
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
198 SNDDBG(("OGG: bitstream channels == (%d).\n", info->channels));
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
199 SNDDBG(("OGG: bitstream sampling rate == (%ld).\n", info->rate));
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
200 SNDDBG(("OGG: seekable == {%s}.\n", ov_seekable(vf) ? "TRUE" : "FALSE"));
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
201 SNDDBG(("OGG: number of logical bitstreams == (%ld).\n", ov_streams(vf)));
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
202 SNDDBG(("OGG: serial number == (%ld).\n", ov_serialnumber(vf, -1)));
cd91e1857b42 Changed _D macro to SNDDBG, and fixed a warning if compiling without debug
Ryan C. Gordon <icculus@icculus.org>
parents: 47
diff changeset
203 SNDDBG(("OGG: total seconds of sample == (%f).\n", ov_time_total(vf, -1)));
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 internal->decoder_private = vf;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 sample->flags = SOUND_SAMPLEFLAG_NONE;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 sample->actual.rate = (Uint32) info->rate;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 sample->actual.channels = (Uint8) info->channels;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 /*
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 * Since we might have more than one logical bitstream in the OGG file,
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 * and these bitstreams may be in different formats, we might be
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 * converting two or three times: once in vorbisfile, once again in
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 * SDL_sound, and perhaps a third time to get it to the sound device's
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 * format. That's wickedly inefficient.
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 *
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 * To combat this a little, if the user specified a desired format, we
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 * claim that to be the "actual" format of the collection of logical
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 * bitstreams. This means that VorbisFile will do a conversion as
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 * necessary, and SDL_sound will not. If the user didn't specify a
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 * desired format, then we pretend the "actual" format is something that
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 * OGG files are apparently commonly encoded in.
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 sample->actual.format = (sample->desired.format == 0) ?
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 AUDIO_S16LSB : sample->desired.format;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 return(1);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 } /* OGG_open */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 static void OGG_close(Sound_Sample *sample)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 OggVorbis_File *vf = (OggVorbis_File *) internal->decoder_private;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 ov_clear(vf);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 free(vf);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 } /* OGG_close */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 static Uint32 OGG_read(Sound_Sample *sample)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 {
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 int rc;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 int bitstream;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 OggVorbis_File *vf = (OggVorbis_File *) internal->decoder_private;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 rc = ov_read(vf, internal->buffer, internal->buffer_size,
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 ((sample->actual.format & 0x1000) ? 1 : 0), /* bigendian? */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 ((sample->actual.format & 0xFF) / 8), /* bytes per sample point */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 ((sample->actual.format & 0x8000) ? 1 : 0), /* signed data? */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 &bitstream);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 /* Make sure the read went smoothly... */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 if (rc == 0)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 sample->flags |= SOUND_SAMPLEFLAG_EOF;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 else if (rc < 0)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 /* (next call this EAGAIN may turn into an EOF or error.) */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 else if ((Uint32) rc < internal->buffer_size)
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 return((Uint32) rc);
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 } /* OGG_read */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265
63
9669aa13d3e0 Changes in preparation for autoconf, and the RWops wrappers changed to
Ryan C. Gordon <icculus@icculus.org>
parents: 59
diff changeset
266 #endif /* SOUND_SUPPORTS_OGG */
9669aa13d3e0 Changes in preparation for autoconf, and the RWops wrappers changed to
Ryan C. Gordon <icculus@icculus.org>
parents: 59
diff changeset
267
9669aa13d3e0 Changes in preparation for autoconf, and the RWops wrappers changed to
Ryan C. Gordon <icculus@icculus.org>
parents: 59
diff changeset
268
24
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 /* end of ogg.c ... */
0fc0f91b1b84 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270