/* * Music Player class * * Copyright (C) 2008 Alejandro Valenzuela Roca, * * http://mexinetica.com/~lanjoe9 * * This file is part of MotorJ, a free framework for videogame development. * * * * MotorJ is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MotorJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with MotorJ. If not, see . */ #ifndef MUSICPLAYER_CLASS_H #define MUSICPLAYER_CLASS_H #ifdef PC_SDL #include #include #include "support.h" #endif #ifdef NINTENDO_DS #include #include #include #include #include "ds_only/Tremor/ivorbisfile.h" #endif enum MJMUSICPLAYERSTATUS{MP_UNLOADED, MP_IDLE, MP_LOADING, MP_PLAYING, MP_PAUSED, MP_STOPPED, MP_SEEKING}; #define MP_EXPECTED_SIZE 88200 //! Music player object. Can easily load, pause and loop music files in Ogg Vorbis format class mjMusicPlayer{ public: mjMusicPlayer(); //! Open a file and get it ready to play int LoadFile(const char * filename); //! Start playing the file (or continue playing if paused) void Play(); //! Pause the currently playing file void Pause(); //! (Nintendo DS) Set file position to sync audio across devices void SetCounter(unsigned short * counter); //! (Nintendo DS) Set the approximate frames per second for adequate decompression void setFPS(unsigned short fps); //! Set the music volume (0 - 255) unsigned short volume; //! Get the player's current status MJMUSICPLAYERSTATUS GetStatus(); //! (Nintendo DS) Perform update (Called automatically by motorJ) void Update(); //! Close file and free memory if needed void Unload(); //! If true, the music player will loop endlessly bool loop; #ifdef NINTENDO_DS //! (Nintendo DS) When looping, start the loop at this time position ogg_int64_t loop_start_time; //! (Nintendo DS) Get current play position ogg_int64_t TimePos(); //! (Nintendo DS) Seek to the specified time position void TimeSeek(ogg_int64_t ms); //! (Nintendo DS) Function called by the timer interrupt (Called automatically by motorJ) void InterruptFunction(); //! (Nintendo DS) Clear buffers and sync void Sync(); #endif #ifdef PC_SDL //! Establish RAW file location to save the game's audio (Note: both music and sound effects will be saved) int SetAudioCaptureFile(const char * filename); //! Start capturing audio (audio capture file should have been set) void StartAudioCapture(); //! Stop capturing audio void StopAudioCapture(); ~mjMusicPlayer(); //void AudioCaptureFunction(void *udata, Uint8 *stream, int len); #endif private: MJMUSICPLAYERSTATUS status; unsigned short ifps; #ifdef PC_SDL Mix_Music * cMusic; FILE* captureFile; #endif #ifdef NINTENDO_DS FILE * mplayerfile; int M_FRAGMENT; int ov_currentSection; unsigned short * mplayercount; OggVorbis_File ov_file; vorbis_info * ov_info_struct; char buffers[2][MP_EXPECTED_SIZE]; TransferSoundData sampleTSD; int ov_currentsection; bool currentlyReading; unsigned readBufferCount; bool mustSwitch; bool istopping; #endif }; #endif