| 1 | /* |
|---|
| 2 | * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno |
|---|
| 3 | * All rights reserved. |
|---|
| 4 | * |
|---|
| 5 | * Redistribution and use in source and binary forms, with or without |
|---|
| 6 | * modification, are permitted provided that the following conditions |
|---|
| 7 | * are met: |
|---|
| 8 | * 1. Redistributions of source code must retain the above copyright |
|---|
| 9 | * notice, this list of conditions and the following disclaimer. |
|---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer in the |
|---|
| 12 | * documentation and/or other materials provided with the distribution. |
|---|
| 13 | * 3. The name of the author may not be used to endorse or promote products |
|---|
| 14 | * derived from this software without specific prior written permission. |
|---|
| 15 | * |
|---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|---|
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|---|
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|---|
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|---|
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|---|
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | #ifndef __MUSIC__ /* __MUSIC__ */ |
|---|
| 30 | #define __MUSIC__ |
|---|
| 31 | |
|---|
| 32 | #ifdef HAVE_CONFIG_H |
|---|
| 33 | # include "config.h" |
|---|
| 34 | #endif |
|---|
| 35 | |
|---|
| 36 | #include <sys/types.h> |
|---|
| 37 | #include <sys/time.h> |
|---|
| 38 | #include <SDL_mixer.h> |
|---|
| 39 | |
|---|
| 40 | #define MIX_PCM_BGM 4 |
|---|
| 41 | #define MIX_PCM_EFFEC 5 |
|---|
| 42 | #define MIX_PCM_KOE 6 |
|---|
| 43 | #define MIX_PCM_SIZE 8 |
|---|
| 44 | |
|---|
| 45 | #define DEFAULT_AUDIOBUF 4096 |
|---|
| 46 | |
|---|
| 47 | enum KoeType { koe_unknown, koe_nwk, koe_ovk, koe_ogg}; |
|---|
| 48 | |
|---|
| 49 | typedef struct { |
|---|
| 50 | FILE* stream; |
|---|
| 51 | int length; |
|---|
| 52 | int offset; |
|---|
| 53 | int rate; |
|---|
| 54 | KoeType type; |
|---|
| 55 | } AvgKoeInfo; |
|---|
| 56 | |
|---|
| 57 | /* koedec.cc */ |
|---|
| 58 | extern AvgKoeInfo OpenKoeFile(const char* path); |
|---|
| 59 | extern char* decode_koe(AvgKoeInfo info, int* len); |
|---|
| 60 | extern char* decode_koe_nwa(AvgKoeInfo info, int* len); |
|---|
| 61 | extern const char* MakeWavHeader(int rate, int ch, int bps, int size); |
|---|
| 62 | extern AvgKoeInfo FindKoe(int file_number, int index); |
|---|
| 63 | |
|---|
| 64 | #include <unistd.h> |
|---|
| 65 | |
|---|
| 66 | class MuSys { |
|---|
| 67 | public: |
|---|
| 68 | static MuSys* GetInstance(void); |
|---|
| 69 | static void Quit(void); |
|---|
| 70 | void PlayCDROM(char* name, int play_count); |
|---|
| 71 | void StopCDROM(int time); |
|---|
| 72 | void PlaySE(const char* name, int loop_flag=0, int channel=0); |
|---|
| 73 | void PlaySE(int number); |
|---|
| 74 | void StopSE(int time = 0); |
|---|
| 75 | bool IsStopSE(void); |
|---|
| 76 | void PlayKoe(const char* fname); |
|---|
| 77 | void StopKoe(int time); |
|---|
| 78 | void PlayMovie(const char* fname, int x1, int y1, int x2, int y2, int loop_count); |
|---|
| 79 | void StopMovie(void); |
|---|
| 80 | bool IsStopMovie(void); |
|---|
| 81 | void InitMusic(void); |
|---|
| 82 | void FinalizeMusic(void); |
|---|
| 83 | |
|---|
| 84 | private: |
|---|
| 85 | MuSys(); |
|---|
| 86 | |
|---|
| 87 | public: |
|---|
| 88 | int volmod[4]; // BGM, KOE, PCM, Se |
|---|
| 89 | int pcm_enable; |
|---|
| 90 | Mix_Chunk *play_chunk[MIX_PCM_SIZE]; |
|---|
| 91 | |
|---|
| 92 | private: |
|---|
| 93 | class AyuSysConfig *config; |
|---|
| 94 | char cdrom_track[128]; char effec_track[128]; |
|---|
| 95 | int movie_id; |
|---|
| 96 | int music_enable; |
|---|
| 97 | static MuSys *_singleton; |
|---|
| 98 | }; |
|---|
| 99 | |
|---|
| 100 | #endif /* __MUSIC__ */ |
|---|