music_ogg.h
author Ryan C. Gordon <icculus@icculus.org>
Sat, 19 Nov 2005 18:43:48 +0000
changeset 281 33730d0864d8
parent 246 9fa5d0f9d042
child 353 21fe62f9c4c6
permissions -rw-r--r--
From: Gabriel <mystml@adinet.com.uy>
To: SDL Mailing List <sdl@libsdl.org>
Date: Thu, 13 Oct 2005 15:00:22 -0300
Subject: [SDL] [PATCH] Correct OGG music looping

Bug description : looping music when playing .ogg files left an audible
gap in the mixer buffer.

Bug fix : OGG_playAudio() now returns the actual read length.
music_mixer restarts the music and calls OGG_playAudio() again if it
didn't fill the buffer.

Notes : Tested in Linux and works fine. Since there's no platform
dependent code involved, it should work everywhere else.

A similar fix for the rest of the music formats should be easy, but
since I can't test it at the time, I opted not to do it.

--Gabriel

--
Gabriel Gambetta
Mystery Studio - http://www.mysterystudio.com
Gabriel on Graphics - http://gabrielongraphics.blogspot.com
     1 /*
     2     SDL_mixer:  An audio mixer library based on the SDL library
     3     Copyright (C) 1997-2004 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /* $Id$ */
    24 
    25 #ifdef OGG_MUSIC
    26 
    27 /* This file supports Ogg Vorbis music streams */
    28 
    29 #include <vorbis/vorbisfile.h>
    30 
    31 typedef struct {
    32 	int playing;
    33 	int volume;
    34 	OggVorbis_File vf;
    35 	int section;
    36 	SDL_AudioCVT cvt;
    37 	int len_available;
    38 	Uint8 *snd_available;
    39 } OGG_music;
    40 
    41 /* Initialize the Ogg Vorbis player, with the given mixer settings
    42    This function returns 0, or -1 if there was an error.
    43  */
    44 extern int OGG_init(SDL_AudioSpec *mixer);
    45 
    46 /* Set the volume for an OGG stream */
    47 extern void OGG_setvolume(OGG_music *music, int volume);
    48 
    49 /* Load an OGG stream from the given file */
    50 extern OGG_music *OGG_new(const char *file);
    51 
    52 /* Load an OGG stream from an SDL_RWops object */
    53 extern OGG_music *OGG_new_RW(SDL_RWops *rw);
    54 
    55 /* Start playback of a given OGG stream */
    56 extern void OGG_play(OGG_music *music);
    57 
    58 /* Return non-zero if a stream is currently playing */
    59 extern int OGG_playing(OGG_music *music);
    60 
    61 /* Play some of a stream previously started with OGG_play() */
    62 extern int OGG_playAudio(OGG_music *music, Uint8 *stream, int len);
    63 
    64 /* Stop playback of a stream previously started with OGG_play() */
    65 extern void OGG_stop(OGG_music *music);
    66 
    67 /* Close the given OGG stream */
    68 extern void OGG_delete(OGG_music *music);
    69 
    70 /* Jump (seek) to a given position (time is in seconds) */
    71 extern void OGG_jump_to_time(OGG_music *music, double time);
    72 
    73 #endif /* OGG_MUSIC */