Mercurial > almixer_isolated
annotate Isolated/LGPL/oggvorbis.c @ 62:7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Instead of trying to backport my Tremor decoder which originated from the SDL_sound Vorbis decoder, I told Johnson it would be better to just start at the source and avoid all the original gotchas I hit in the subtle differences between Tremor and Vorbis.
Since this derives directly from Ryan Gordon's SDL_sound implementation, I am putting this under the LGPL subdirectory.
Johnson Lin < arch . jslin - at - gmail . com >
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Tue, 19 Jun 2012 00:31:12 -0700 |
parents | |
children |
rev | line source |
---|---|
62
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1 /* |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2 * SDL_sound -- An abstract sound format decoding API. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3 * Copyright (C) 2001 Ryan C. Gordon. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4 * |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
8 * version 2.1 of the License, or (at your option) any later version. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
9 * |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
14 * |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
18 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
19 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
20 /* |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
21 * Ogg Vorbis decoder for SDL_sound. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
22 * |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
23 * This driver handles .OGG audio files, and depends on libvorbisfile to |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
24 * do the actual decoding work. libvorbisfile is part of libvorbis, which |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
25 * is part of the Ogg Vorbis project. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
26 * |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
27 * Ogg Vorbis: http://www.xiph.org/ogg/vorbis/ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
28 * vorbisfile documentation: http://www.xiph.org/ogg/vorbis/doc/vorbisfile/ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
29 * |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
30 * Please see the file LICENSE.txt in the source's root directory. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
31 * |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
32 * This file written by Ryan C. Gordon. (icculus@icculus.org) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
33 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
34 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
35 #if HAVE_CONFIG_H |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
36 # include <config.h> |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
37 #endif |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
38 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
39 #ifdef SOUND_SUPPORTS_OGG |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
40 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
41 #include <stdio.h> |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
42 #include <stdlib.h> |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
43 #include <string.h> |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
44 #include <math.h> |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
45 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
46 #include "SoundDecoder.h" |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
47 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
48 #include "SoundDecoder_Internal.h" |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
49 #include "SDL_endian_minimal.h" |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
50 #include "ALmixer_RWops.h" |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
51 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
52 //#include <vorbis/codec.h> |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
53 #ifdef _WIN32 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
54 #include <vorbis/vorbisfile.h> |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
55 #else |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
56 #include <ivorbisfile.h> |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
57 #endif //_WIN32 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
58 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
59 #define ERR_IO_ERROR "I/O error" |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
60 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
61 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
62 static int OGG_init(void); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
63 static void OGG_quit(void); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
64 static int OGG_open(Sound_Sample *sample, const char *ext); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
65 static void OGG_close(Sound_Sample *sample); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
66 static uint32_t OGG_read(Sound_Sample *sample); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
67 static int OGG_rewind(Sound_Sample *sample); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
68 static int OGG_seek(Sound_Sample *sample, uint32_t ms); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
69 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
70 static const char *extensions_ogg[] = { "OGG", NULL }; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
71 const Sound_DecoderFunctions __Sound_DecoderFunctions_OGG = |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
72 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
73 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
74 extensions_ogg, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
75 "Ogg Vorbis audio through VorbisFile", |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
76 "Ryan C. Gordon <icculus@icculus.org>", |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
77 "http://www.icculus.org/SDL_sound/" |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
78 }, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
79 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
80 OGG_init, /* init() method */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
81 OGG_quit, /* quit() method */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
82 OGG_open, /* open() method */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
83 OGG_close, /* close() method */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
84 OGG_read, /* read() method */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
85 OGG_rewind, /* rewind() method */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
86 OGG_seek /* seek() method */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
87 }; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
88 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
89 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
90 static int OGG_init(void) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
91 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
92 return(1); /* always succeeds. */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
93 } /* OGG_init */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
94 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
95 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
96 static void OGG_quit(void) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
97 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
98 /* it's a no-op. */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
99 } /* OGG_quit */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
100 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
101 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
102 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
103 /* |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
104 * These are callbacks from vorbisfile that let them read data from |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
105 * a RWops... |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
106 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
107 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
108 static size_t RWops_ogg_read(void *ptr, size_t size, size_t nmemb, void *datasource) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
109 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
110 return((size_t) ALmixer_RWread((ALmixer_RWops *) datasource, ptr, size, nmemb)); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
111 } /* RWops_ogg_read */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
112 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
113 static int RWops_ogg_seek(void *datasource, ogg_int64_t offset, int whence) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
114 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
115 return(ALmixer_RWseek((ALmixer_RWops *) datasource, offset, whence)); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
116 } /* RWops_ogg_seek */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
117 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
118 static int RWops_ogg_close(void *datasource) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
119 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
120 /* do nothing; SDL_sound will delete the RWops at a higher level. */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
121 return(0); /* this is success in fclose(), so I guess that's okay. */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
122 } /* RWops_ogg_close */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
123 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
124 static long RWops_ogg_tell(void *datasource) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
125 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
126 return((long) ALmixer_RWtell((ALmixer_RWops *) datasource)); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
127 } /* RWops_ogg_tell */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
128 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
129 static const ov_callbacks RWops_ogg_callbacks = |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
130 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
131 RWops_ogg_read, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
132 RWops_ogg_seek, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
133 RWops_ogg_close, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
134 RWops_ogg_tell |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
135 }; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
136 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
137 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
138 /* Return a human readable version of an VorbisFile error code... */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
139 #if (defined DEBUG_CHATTER) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
140 static const char *ogg_error(int errnum) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
141 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
142 switch(errnum) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
143 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
144 case OV_EREAD: |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
145 return("i/o error"); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
146 case OV_ENOTVORBIS: |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
147 return("not a vorbis file"); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
148 case OV_EVERSION: |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
149 return("Vorbis version mismatch"); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
150 case OV_EBADHEADER: |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
151 return("invalid Vorbis bitstream header"); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
152 case OV_EFAULT: |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
153 return("internal logic fault in Vorbis library"); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
154 } /* switch */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
155 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
156 return("unknown error"); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
157 } /* ogg_error */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
158 #endif |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
159 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
160 static __inline__ void output_ogg_comments(OggVorbis_File *vf) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
161 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
162 #if (defined DEBUG_CHATTER) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
163 int i; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
164 vorbis_comment *vc = ov_comment(vf, -1); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
165 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
166 if (vc == NULL) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
167 return; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
168 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
169 SNDDBG(("OGG: vendor == [%s].\n", vc->vendor)); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
170 for (i = 0; i < vc->comments; i++) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
171 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
172 SNDDBG(("OGG: user comment [%s].\n", vc->user_comments[i])); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
173 } /* for */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
174 #endif |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
175 } /* output_ogg_comments */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
176 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
177 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
178 static int OGG_open(Sound_Sample *sample, const char *ext) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
179 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
180 int rc; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
181 double total_time; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
182 OggVorbis_File *vf; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
183 vorbis_info *info; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
184 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
185 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
186 vf = (OggVorbis_File *) malloc(sizeof (OggVorbis_File)); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
187 BAIL_IF_MACRO(vf == NULL, ERR_OUT_OF_MEMORY, 0); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
188 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
189 rc = ov_open_callbacks(internal->rw, vf, NULL, 0, RWops_ogg_callbacks); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
190 if (rc != 0) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
191 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
192 #if (defined DEBUG_CHATTER) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
193 SNDDBG(("OGG: can't grok data. reason: [%s].\n", ogg_error(rc))); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
194 #endif |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
195 free(vf); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
196 BAIL_MACRO("OGG: Not valid Ogg Vorbis data.", 0); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
197 } /* if */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
198 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
199 info = ov_info(vf, -1); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
200 if (info == NULL) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
201 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
202 ov_clear(vf); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
203 free(vf); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
204 BAIL_MACRO("OGG: failed to retrieve bitstream info", 0); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
205 } /* if */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
206 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
207 SNDDBG(("OGG: Accepting data stream.\n")); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
208 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
209 output_ogg_comments(vf); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
210 SNDDBG(("OGG: bitstream version == (%d).\n", info->version)); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
211 SNDDBG(("OGG: bitstream channels == (%d).\n", info->channels)); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
212 SNDDBG(("OGG: bitstream sampling rate == (%ld).\n", info->rate)); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
213 SNDDBG(("OGG: seekable == {%s}.\n", ov_seekable(vf) ? "TRUE" : "FALSE")); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
214 SNDDBG(("OGG: number of logical bitstreams == (%ld).\n", ov_streams(vf))); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
215 SNDDBG(("OGG: serial number == (%ld).\n", ov_serialnumber(vf, -1))); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
216 SNDDBG(("OGG: total seconds of sample == (%f).\n", ov_time_total(vf, -1))); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
217 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
218 internal->decoder_private = vf; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
219 sample->flags = SOUND_SAMPLEFLAG_CANSEEK; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
220 sample->actual.rate = (uint32_t) info->rate; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
221 sample->actual.channels = (uint8_t) info->channels; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
222 total_time = ov_time_total(vf, -1); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
223 if (OV_EINVAL == total_time) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
224 internal->total_time = -1; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
225 else |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
226 internal->total_time = (int32_t)(total_time * 1000.0 + 0.5); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
227 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
228 /* |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
229 * Since we might have more than one logical bitstream in the OGG file, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
230 * and these bitstreams may be in different formats, we might be |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
231 * converting two or three times: once in vorbisfile, once again in |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
232 * SDL_sound, and perhaps a third time to get it to the sound device's |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
233 * format. That's wickedly inefficient. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
234 * |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
235 * To combat this a little, if the user specified a desired format, we |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
236 * claim that to be the "actual" format of the collection of logical |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
237 * bitstreams. This means that VorbisFile will do a conversion as |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
238 * necessary, and SDL_sound will not. If the user didn't specify a |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
239 * desired format, then we pretend the "actual" format is something that |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
240 * OGG files are apparently commonly encoded in. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
241 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
242 sample->actual.format = (sample->desired.format == 0) ? |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
243 AUDIO_S16LSB : sample->desired.format; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
244 return(1); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
245 } /* OGG_open */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
246 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
247 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
248 static void OGG_close(Sound_Sample *sample) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
249 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
250 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
251 OggVorbis_File *vf = (OggVorbis_File *) internal->decoder_private; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
252 ov_clear(vf); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
253 free(vf); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
254 } /* OGG_close */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
255 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
256 /* Note: According to the Vorbis documentation: |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
257 * "ov_read() will decode at most one vorbis packet per invocation, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
258 * so the value returned will generally be less than length." |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
259 * Due to this, for buffer sizes like 16384, SDL_Sound was always getting |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
260 * an underfilled buffer and always setting the EAGAIN flag. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
261 * Since the SDL_Sound API implies that the entire buffer |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
262 * should be filled unless EOF, additional code has been added |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
263 * to this function to call ov_read() until the buffer is filled. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
264 * However, there may still be some corner cases where the buffer |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
265 * cannot be entirely filled. So be aware. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
266 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
267 static uint32_t OGG_read(Sound_Sample *sample) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
268 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
269 int rc; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
270 int bitstream; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
271 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
272 OggVorbis_File *vf = (OggVorbis_File *) internal->decoder_private; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
273 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
274 rc = ov_read(vf, internal->buffer, internal->buffer_size, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
275 ((sample->actual.format & 0x1000) ? 1 : 0), /* bigendian? */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
276 ((sample->actual.format & 0xFF) / 8), /* bytes per sample point */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
277 ((sample->actual.format & 0x8000) ? 1 : 0), /* signed data? */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
278 &bitstream); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
279 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
280 /* Make sure the read went smoothly... */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
281 if (rc == 0) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
282 sample->flags |= SOUND_SAMPLEFLAG_EOF; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
283 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
284 else if (rc < 0) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
285 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
286 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
287 /* If the buffer isn't filled, keep trying to fill it |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
288 * until no more data can be grabbed */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
289 else if ((uint32_t) rc < internal->buffer_size) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
290 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
291 /* Creating a pointer to the buffer that denotes where to start |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
292 * writing new data. */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
293 uint8_t lala; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
294 char* buffer_start_point = NULL; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
295 int total_bytes_read = rc; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
296 int bytes_remaining = internal->buffer_size - rc; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
297 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
298 /* Keep grabbing data until something prevents |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
299 * us from getting more. (Could be EOF, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
300 * packets are too large to fit in remaining |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
301 * space, or an error.) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
302 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
303 while( (rc > 0) && (bytes_remaining > 0) ) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
304 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
305 /* Set buffer pointer to end of last write */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
306 /* All the messiness is to get rid of the warning for |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
307 * dereferencing a void* |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
308 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
309 buffer_start_point = &(((char*)internal->buffer)[total_bytes_read]); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
310 rc = ov_read(vf, buffer_start_point, bytes_remaining, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
311 ((sample->actual.format & 0x1000) ? 1 : 0), /* bigendian? */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
312 ((sample->actual.format & 0xFF) / 8), /* bytes per sample point */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
313 ((sample->actual.format & 0x8000) ? 1 : 0), /* signed data? */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
314 &bitstream); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
315 /* Make sure rc > 0 because we don't accidently want |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
316 * to change the counters if there was an error |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
317 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
318 if(rc > 0) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
319 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
320 total_bytes_read += rc; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
321 bytes_remaining = bytes_remaining - rc; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
322 } |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
323 } |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
324 /* I think the minimum read size is 2, though I'm |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
325 * not sure about this. (I've hit cases where I |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
326 * couldn't read less than 4.) What I don't want to do is |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
327 * accidently claim we hit EOF when the reason rc == 0 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
328 * is because the requested amount of data was smaller |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
329 * than the minimum packet size. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
330 * For now, I will be conservative |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
331 * and not set the EOF flag, and let the next call to |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
332 * this function figure it out. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
333 * I think the ERROR flag is safe to set because |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
334 * it looks like OGG simply returns 0 if the |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
335 * read size is too small. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
336 * And in most cases for sensible buffer sizes, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
337 * this fix will fill the buffer, |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
338 * so we can set the EAGAIN flag without worrying |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
339 * that it will always be set. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
340 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
341 if(rc < 0) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
342 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
343 sample->flags |= SOUND_SAMPLEFLAG_ERROR; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
344 } |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
345 else if(rc == 0) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
346 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
347 /* Do nothing for now until there is a better solution */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
348 /* sample->flags |= SOUND_SAMPLEFLAG_EOF; */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
349 } |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
350 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
351 /* Test for a buffer underrun. It should occur less frequently |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
352 * now, but it still may happen and not necessarily mean |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
353 * anything useful. */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
354 if ((uint32_t) total_bytes_read < internal->buffer_size) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
355 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
356 sample->flags |= SOUND_SAMPLEFLAG_EAGAIN; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
357 } |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
358 /* change rc to the total bytes read so function |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
359 * can return the correct value. |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
360 */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
361 rc = total_bytes_read; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
362 } |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
363 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
364 return((uint32_t) rc); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
365 } /* OGG_read */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
366 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
367 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
368 static int OGG_rewind(Sound_Sample *sample) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
369 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
370 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
371 OggVorbis_File *vf = (OggVorbis_File *) internal->decoder_private; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
372 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
373 BAIL_IF_MACRO(ov_raw_seek(vf, 0) < 0, ERR_IO_ERROR, 0); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
374 return(1); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
375 } /* OGG_rewind */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
376 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
377 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
378 static int OGG_seek(Sound_Sample *sample, uint32_t ms) |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
379 { |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
380 Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
381 OggVorbis_File *vf = (OggVorbis_File *) internal->decoder_private; |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
382 double timepos = (((double) ms) / 1000.0); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
383 BAIL_IF_MACRO(ov_time_seek(vf, timepos) < 0, ERR_IO_ERROR, 0); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
384 return(1); |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
385 } /* OGG_seek */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
386 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
387 #endif /* SOUND_SUPPORTS_OGG */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
388 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
389 |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
390 /* end of ogg.c ... */ |
7a4a8459f0c1
Ogg Vorbis decoder for SoundDecoder directly adapted from SDL_sound's code. Thanks to Johnson Lin for providing this!
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
391 |