Erwan
- Fix issue 144 (Sound is either 0 or 100%), for PSP ONLY. The methods are now here for linux/windows, but only the music volume method will work currently, and it sets the volume globally. Patch by Yeshua with some cleanup by myself.
This commit is contained in:
@@ -1,87 +1,88 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
// Copyright (c) 2007 Cooleyes
|
||||
// Copyright (c) 2007 Mr.Cheese
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JAUDIO_H_
|
||||
#define _JAUDIO_H_
|
||||
|
||||
|
||||
#include <pspiofilemgr.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
#define PW_REPLAY 0x00000001 //
|
||||
#define PW_DELAY 0x00000010 //
|
||||
#define PW_FAST 0x00000100 //
|
||||
#define PW_PAUSE 0x00001000 //
|
||||
|
||||
#define NUMBER_WAV_CHANNELS 3
|
||||
|
||||
typedef struct _WAVDATA
|
||||
{
|
||||
char fullName[256]; // filename
|
||||
unsigned long fileSize; // size of file
|
||||
short headSize; // size of head
|
||||
unsigned short format; //
|
||||
unsigned short channelCount; //
|
||||
unsigned long samplePerSecond; //
|
||||
unsigned long bytePerSecond; //
|
||||
unsigned short bytePerSample; //
|
||||
unsigned long soundSize; //
|
||||
char* buffer; // sound data
|
||||
SceUID fd; // file id for streaming
|
||||
unsigned long bytePosition; // current read position
|
||||
char nSample; // progress rate
|
||||
unsigned long sizeStep; //
|
||||
unsigned long flag; // playback flag
|
||||
unsigned long delayTime; // delay time in (us)
|
||||
|
||||
} WAVDATA;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
char loadWaveData(WAVDATA* p_wav, char* fileName, char memLoad);
|
||||
void releaseWaveData(WAVDATA* p_wav);
|
||||
void audioOutCallback(int channel, void* buf, unsigned int length);
|
||||
void audioOutCallback_0(void* buf, unsigned int length, void *userdata);
|
||||
void audioOutCallback_1(void* buf, unsigned int length, void *userdata);
|
||||
void audioOutCallback_2(void* buf, unsigned int length, void *userdata);
|
||||
//void audioOutCallback_3(void* buf, unsigned int length, void *userdata);
|
||||
char playWaveFile(int channel, char* fullName, unsigned long flag);
|
||||
void stopWaveFile(int channel);
|
||||
int playWaveMem(WAVDATA* p_wav, unsigned long flag);
|
||||
void stopWaveMem(int channel);
|
||||
void audioInit();
|
||||
void audioDestroy();
|
||||
void setChannelFlag(int channel, int flag);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#define DECODING_BUFFER_COUNT 2
|
||||
#define SAMPLE_PER_FRAME 1152
|
||||
#define MAX_MP3_FILE 2
|
||||
|
||||
class JMP3;
|
||||
|
||||
void PlayMP3(JMP3 *mp3, bool looping = false);
|
||||
void StopMP3();
|
||||
void ResumeMP3(JMP3 *mp3);
|
||||
|
||||
void ReleaseMP3Decoder();
|
||||
void MP3AudioOutCallback(void* buf, unsigned int length, void *userdata);
|
||||
int decodeThread2(SceSize args, void *argp);
|
||||
extern bool g_MP3DecoderOK;
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
// Copyright (c) 2007 Cooleyes
|
||||
// Copyright (c) 2007 Mr.Cheese
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JAUDIO_H_
|
||||
#define _JAUDIO_H_
|
||||
|
||||
|
||||
#include <pspiofilemgr.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
#define PW_REPLAY 0x00000001 //
|
||||
#define PW_DELAY 0x00000010 //
|
||||
#define PW_FAST 0x00000100 //
|
||||
#define PW_PAUSE 0x00001000 //
|
||||
|
||||
#define NUMBER_WAV_CHANNELS 3
|
||||
|
||||
typedef struct _WAVDATA
|
||||
{
|
||||
char fullName[256]; // filename
|
||||
unsigned long fileSize; // size of file
|
||||
short headSize; // size of head
|
||||
unsigned short format; //
|
||||
unsigned short channelCount; //
|
||||
unsigned long samplePerSecond; //
|
||||
unsigned long bytePerSecond; //
|
||||
unsigned short bytePerSample; //
|
||||
unsigned long soundSize; //
|
||||
char* buffer; // sound data
|
||||
SceUID fd; // file id for streaming
|
||||
unsigned long bytePosition; // current read position
|
||||
char nSample; // progress rate
|
||||
unsigned long sizeStep; //
|
||||
unsigned long flag; // playback flag
|
||||
unsigned long delayTime; // delay time in (us)
|
||||
|
||||
} WAVDATA;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
char loadWaveData(WAVDATA* p_wav, char* fileName, char memLoad);
|
||||
void releaseWaveData(WAVDATA* p_wav);
|
||||
void audioOutCallback(int channel, void* buf, unsigned int length);
|
||||
void audioOutCallback_0(void* buf, unsigned int length, void *userdata);
|
||||
void audioOutCallback_1(void* buf, unsigned int length, void *userdata);
|
||||
void audioOutCallback_2(void* buf, unsigned int length, void *userdata);
|
||||
//void audioOutCallback_3(void* buf, unsigned int length, void *userdata);
|
||||
char playWaveFile(int channel, char* fullName, unsigned long flag);
|
||||
void stopWaveFile(int channel);
|
||||
int playWaveMem(WAVDATA* p_wav, unsigned long flag);
|
||||
void stopWaveMem(int channel);
|
||||
void audioInit();
|
||||
void audioDestroy();
|
||||
void setChannelFlag(int channel, int flag);
|
||||
void setPspVolume(int volume);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#define DECODING_BUFFER_COUNT 2
|
||||
#define SAMPLE_PER_FRAME 1152
|
||||
#define MAX_MP3_FILE 2
|
||||
|
||||
class JMP3;
|
||||
|
||||
void PlayMP3(JMP3 *mp3, bool looping = false);
|
||||
void StopMP3();
|
||||
void ResumeMP3(JMP3 *mp3);
|
||||
|
||||
void ReleaseMP3Decoder();
|
||||
void MP3AudioOutCallback(void* buf, unsigned int length, void *userdata);
|
||||
int decodeThread2(SceSize args, void *argp);
|
||||
extern bool g_MP3DecoderOK;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,200 +1,205 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JSOUNDSYSTEM_H_
|
||||
#define _JSOUNDSYSTEM_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "JTypes.h"
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#elif defined (LINUX)
|
||||
#else
|
||||
|
||||
#include <pspgu.h>
|
||||
#include <pspkernel.h>
|
||||
#include <pspdisplay.h>
|
||||
#include <pspdebug.h>
|
||||
#include <pspctrl.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <psprtc.h>
|
||||
|
||||
#include "JAudio.h"
|
||||
#include "JMP3.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
class JMusic
|
||||
{
|
||||
public:
|
||||
JMusic();
|
||||
~JMusic();
|
||||
void Update();
|
||||
int getPlayTime();
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
FSOUND_SAMPLE *mTrack; // MP3 needed to be of "sample" type for FMOD, FMUSIC_MODULE is for MODs
|
||||
#else
|
||||
JMP3* mTrack;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
class JSample
|
||||
{
|
||||
public:
|
||||
JSample();
|
||||
~JSample();
|
||||
|
||||
int mVoice;
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
FSOUND_SAMPLE *mSample;
|
||||
#else
|
||||
WAVDATA *mSample;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Sound engine for playing sound effects (WAV) and background
|
||||
/// music (MP3).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JSoundSystem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get the singleton instance
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static JSoundSystem* GetInstance();
|
||||
|
||||
static void Destroy();
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load music.
|
||||
///
|
||||
/// @note MP3 is the only supported format for the moment.
|
||||
///
|
||||
/// @param filename - Name of the music file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JMusic *LoadMusic(const char *fileName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete music from memory.
|
||||
///
|
||||
/// @param music - Music to be deleted.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//void FreeMusic(JMusic *music);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Play music.
|
||||
///
|
||||
/// @param music - Music to be played.
|
||||
/// @param looping - Play the music in a loop.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PlayMusic(JMusic *music, bool looping = false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop playing.
|
||||
///
|
||||
/// @param music - Music to be stopped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopMusic(JMusic *music);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Resume playing.
|
||||
///
|
||||
/// @param music - Music to be resumed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void ResumeMusic(JMusic *music);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load sound effect.
|
||||
///
|
||||
/// @note WAV sound effect only.
|
||||
///
|
||||
/// @param fileName - Sound effect for loading.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSample *LoadSample(const char *fileName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete sound effect from memory.
|
||||
///
|
||||
/// @param sample - Sound to be deleted.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//void FreeSample(JSample *sample);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Play sound effect.
|
||||
///
|
||||
/// @param sample - Sound for playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PlaySample(JSample *sample);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set volume for audio playback.
|
||||
///
|
||||
/// @param volume - New volume.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetVolume(int volume);
|
||||
|
||||
int mChannel;
|
||||
protected:
|
||||
JSoundSystem();
|
||||
~JSoundSystem();
|
||||
|
||||
void InitSoundSystem();
|
||||
void DestroySoundSystem();
|
||||
|
||||
private:
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
JMusic *mCurrentMusic;
|
||||
|
||||
#endif
|
||||
|
||||
int mVolume;
|
||||
|
||||
|
||||
static JSoundSystem* mInstance;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JSOUNDSYSTEM_H_
|
||||
#define _JSOUNDSYSTEM_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "JTypes.h"
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#elif defined (LINUX)
|
||||
#else
|
||||
|
||||
#include <pspgu.h>
|
||||
#include <pspkernel.h>
|
||||
#include <pspdisplay.h>
|
||||
#include <pspdebug.h>
|
||||
#include <pspctrl.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <psprtc.h>
|
||||
|
||||
#include "JAudio.h"
|
||||
#include "JMP3.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
class JMusic
|
||||
{
|
||||
public:
|
||||
JMusic();
|
||||
~JMusic();
|
||||
void Update();
|
||||
int getPlayTime();
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
FSOUND_SAMPLE *mTrack; // MP3 needed to be of "sample" type for FMOD, FMUSIC_MODULE is for MODs
|
||||
#else
|
||||
JMP3* mTrack;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
class JSample
|
||||
{
|
||||
public:
|
||||
JSample();
|
||||
~JSample();
|
||||
|
||||
int mVoice;
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
FSOUND_SAMPLE *mSample;
|
||||
#else
|
||||
WAVDATA *mSample;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Sound engine for playing sound effects (WAV) and background
|
||||
/// music (MP3).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JSoundSystem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get the singleton instance
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static JSoundSystem* GetInstance();
|
||||
|
||||
static void Destroy();
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load music.
|
||||
///
|
||||
/// @note MP3 is the only supported format for the moment.
|
||||
///
|
||||
/// @param filename - Name of the music file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JMusic *LoadMusic(const char *fileName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete music from memory.
|
||||
///
|
||||
/// @param music - Music to be deleted.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//void FreeMusic(JMusic *music);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Play music.
|
||||
///
|
||||
/// @param music - Music to be played.
|
||||
/// @param looping - Play the music in a loop.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PlayMusic(JMusic *music, bool looping = false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop playing.
|
||||
///
|
||||
/// @param music - Music to be stopped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopMusic(JMusic *music);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Resume playing.
|
||||
///
|
||||
/// @param music - Music to be resumed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void ResumeMusic(JMusic *music);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load sound effect.
|
||||
///
|
||||
/// @note WAV sound effect only.
|
||||
///
|
||||
/// @param fileName - Sound effect for loading.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSample *LoadSample(const char *fileName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete sound effect from memory.
|
||||
///
|
||||
/// @param sample - Sound to be deleted.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//void FreeSample(JSample *sample);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Play sound effect.
|
||||
///
|
||||
/// @param sample - Sound for playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PlaySample(JSample *sample);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set volume for audio playback.
|
||||
///
|
||||
/// @param volume - New volume.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetVolume(int volume);
|
||||
|
||||
void SetMusicVolume(int volume);
|
||||
|
||||
void SetSfxVolume(int volume);
|
||||
|
||||
int mChannel;
|
||||
protected:
|
||||
JSoundSystem();
|
||||
~JSoundSystem();
|
||||
|
||||
void InitSoundSystem();
|
||||
void DestroySoundSystem();
|
||||
|
||||
private:
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
JMusic *mCurrentMusic;
|
||||
|
||||
#endif
|
||||
|
||||
int mVolume;
|
||||
int mMusicVolume;
|
||||
|
||||
|
||||
static JSoundSystem* mInstance;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user