annotate decoders/oggtremor.c @ 591:8faf61a640f0 tip

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