first run through for sound on iOS platforms. Currently works only for simulator unless the music files are extracted from the zip file onto the filesystem.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#ifdef ANDROID
|
||||
#include <SLES/OpenSLES.h>
|
||||
#include "SLES/OpenSLES_Android.h"
|
||||
|
||||
#elif defined USE_PHONON
|
||||
#include <phonon/AudioOutput>
|
||||
#include <phonon/MediaObject>
|
||||
@@ -48,6 +49,8 @@
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
using namespace std;
|
||||
|
||||
#ifdef USE_PHONON
|
||||
class JMusic : public QObject
|
||||
{
|
||||
@@ -69,6 +72,10 @@ public:
|
||||
void seekAtTheBegining();
|
||||
#elif defined (PSP)
|
||||
JMP3* mTrack;
|
||||
#elif defined (IOS)
|
||||
std::string filename;
|
||||
std::string key;
|
||||
std::string ext;
|
||||
#elif defined WITH_FMOD
|
||||
FSOUND_SAMPLE* mTrack; // MP3 needed to be of "sample" type for FMOD, FMUSIC_MODULE is for MODs
|
||||
#elif defined ANDROID
|
||||
@@ -82,7 +89,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------------------------
|
||||
class JSample
|
||||
{
|
||||
public:
|
||||
@@ -93,6 +100,12 @@ class JSample
|
||||
|
||||
#if defined (PSP)
|
||||
WAVDATA *mSample;
|
||||
#elif defined (IOS)
|
||||
std::string filename;
|
||||
std::string key;
|
||||
std::string ext;
|
||||
|
||||
void* mSample;
|
||||
#elif defined (WITH_FMOD)
|
||||
FSOUND_SAMPLE *mSample;
|
||||
#elif defined (USE_PHONON)
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
//
|
||||
// JSfx.cpp
|
||||
// wagic
|
||||
//
|
||||
// Created by Michael Nguyen on 2/3/12.
|
||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "JFileSystem.h"
|
||||
#include "JSoundSystem.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#import "SoundManager.h"
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
JMusic::JMusic()
|
||||
{
|
||||
}
|
||||
|
||||
void JMusic::Update(){
|
||||
|
||||
}
|
||||
|
||||
int JMusic::getPlayTime(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
JMusic::~JMusic()
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSample::JSample()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
JSample::~JSample()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned long JSample::fileSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSoundSystem* JSoundSystem::mInstance = NULL;
|
||||
|
||||
JSoundSystem* JSoundSystem::GetInstance()
|
||||
{
|
||||
if (mInstance == NULL)
|
||||
{
|
||||
mInstance = new JSoundSystem();
|
||||
mInstance->InitSoundSystem();
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::Destroy()
|
||||
{
|
||||
if (mInstance)
|
||||
{
|
||||
mInstance->DestroySoundSystem();
|
||||
delete mInstance;
|
||||
mInstance = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JSoundSystem::JSoundSystem()
|
||||
{
|
||||
mVolume = 0;
|
||||
mSampleVolume = 0;
|
||||
}
|
||||
|
||||
JSoundSystem::~JSoundSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void JSoundSystem::InitSoundSystem()
|
||||
{
|
||||
NSLog(@"InitSoundSystem enter");
|
||||
[SoundManager sharedSoundManager];
|
||||
|
||||
|
||||
NSLog(@"InitSoundSystem leave");
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::DestroySoundSystem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
JMusic *JSoundSystem::LoadMusic(const char *fileName)
|
||||
{
|
||||
JMusic* music = new JMusic();
|
||||
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||
music->filename = fullpath;
|
||||
NSString *filename = [NSString stringWithCString: fileName encoding:NSUTF8StringEncoding];
|
||||
NSString *key = [[filename componentsSeparatedByString: @"."] objectAtIndex: 0];
|
||||
NSString *fileType = [[key componentsSeparatedByString: @"."] lastObject];
|
||||
NSString *path = [NSString stringWithCString: fullpath.c_str() encoding:NSUTF8StringEncoding];
|
||||
music->key = [key cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
music->ext = [fileType cStringUsingEncoding: NSUTF8StringEncoding];
|
||||
|
||||
[[SoundManager sharedSoundManager] loadBackgroundMusicWithKey:key musicFile:path];
|
||||
|
||||
return music;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::PlayMusic(JMusic *music, bool looping)
|
||||
{
|
||||
NSString *key = [NSString stringWithCString: music->key.c_str() encoding: NSUTF8StringEncoding];
|
||||
[[SoundManager sharedSoundManager] playMusicWithKey: key timesToRepeat: looping? -1 : 1];
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::StopMusic(JMusic *music)
|
||||
{
|
||||
[[SoundManager sharedSoundManager] stopMusic];
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::SetVolume(int volume)
|
||||
{
|
||||
SetMusicVolume(volume);
|
||||
SetSfxVolume(volume);
|
||||
}
|
||||
|
||||
void JSoundSystem::SetMusicVolume(int volume)
|
||||
{
|
||||
mVolume = volume;
|
||||
[[SoundManager sharedSoundManager] setMusicVolume: (float ) volume];
|
||||
}
|
||||
|
||||
void JSoundSystem::SetSfxVolume(int volume){
|
||||
mSampleVolume = volume;
|
||||
[[SoundManager sharedSoundManager] setFxVolume: (float ) volume];
|
||||
SetMusicVolume(mVolume);
|
||||
}
|
||||
|
||||
JSample *JSoundSystem::LoadSample(const char *fileName)
|
||||
{
|
||||
JSample* sample = new JSample();
|
||||
if (sample)
|
||||
{
|
||||
NSArray *components = [[NSString stringWithCString:fileName encoding:NSUTF8StringEncoding] componentsSeparatedByString:@"."];
|
||||
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||
sample->filename = fullpath;
|
||||
sample->ext = [[components lastObject] cStringUsingEncoding: NSUTF8StringEncoding];
|
||||
NSString *key = [components objectAtIndex:0];
|
||||
NSString *musicFile = [NSString stringWithCString: fullpath.c_str() encoding:NSUTF8StringEncoding];
|
||||
[[SoundManager sharedSoundManager] loadSoundWithKey: key musicFile: musicFile];
|
||||
}
|
||||
return sample;
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::PlaySample(JSample *sample)
|
||||
{
|
||||
SoundManager *soundManager = [SoundManager sharedSoundManager];
|
||||
NSString *key = [NSString stringWithCString: sample->key.c_str() encoding:NSUTF8StringEncoding];
|
||||
[soundManager playSoundWithKey: key gain: 1.0f pitch: 1.0f location:CGPointZero shouldLoop: NO sourceID: -1];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user