Sounds::Sounds() {
	IGLog("Sounds init");

	soundKeyMove = NULL;
	soundOpenChest = NULL;
	soundRestartLevel = NULL;
	soundDoor = NULL;
	soundClick = NULL;
	soundMapLocked = NULL;
	soundUnlockAchievement = NULL;
	
	if(AIRPLAY_DEVICE == AIRPLAY_DEVICE_IPHONE) {
		// for iphone, if there's background music playing, keep it playing
		if(s3eIOSBackgroundMusicAvailable() == S3E_TRUE) {
			if(s3eIOSBackgroundMusicGetInt(S3E_IOSBACKGROUNDMUSIC_PLAYBACK_STATE) == S3E_IOSBACKGROUNDMUSIC_PLAYBACK_INTERRUPTED)
				s3eIOSBackgroundMusicPlay();
			if(s3eIOSBackgroundAudioIsPlaying() == S3E_TRUE)
				s3eIOSBackgroundAudioSetMix(S3E_TRUE);
		}
	}

	// set default frequency at which all channels will play at, in Hz.
	s3eSoundSetInt(S3E_SOUND_DEFAULT_FREQ, 44100);

	// turn down the volume
	s3eSoundSetInt(S3E_SOUND_VOLUME, 96);
	s3eAudioSetInt(S3E_AUDIO_VOLUME, 96);

	// if sounds are enabled, load the sounds
	if(Settings::getInstance()->soundEnabled)
		loadSounds();

	// start playing music?
	gameplayStart = 0;
	gameplayPlaying = false;
	if(Settings::getInstance()->musicEnabled) {
		if(GameData::getInstance()->isSavedGame())
			startMusicGameplay();
		else
			startMusicMenu();
	}
}
ResourceManager::ResourceManager()
{
    // Setting default frequency at which all channels will play at, in Hz.
    s3eSoundSetInt(S3E_SOUND_DEFAULT_FREQ, 12000);

    groups = new std::vector<CIwResGroup *>;
    images = new std::vector<CIw2DImage *>;
    fonts = new std::vector<CIw2DFont *>;
    audioSizes = new std::vector<int32>;
    audioData = new std::vector<int16 *>;
    texts = new std::vector<std::string>;

    images->reserve(100);
    texts->reserve(100);

    // Consume the first slot of all vectors so that we can report index 0 as an error condition
    images->push_back(null);
    fonts->push_back(null);
    audioSizes->push_back(0);
    audioData->push_back(null);
    texts->push_back("");

    fontInitialized = false;
}
	void SimpleAudioEngine::setEffectsVolume(float volume)
	{		
		s3eSoundSetInt(S3E_SOUND_VOLUME, (int32)(volume * (float)GEOM_ONE_FP8));
	}
void CIwGameAudio::setSoundVolume(float vol)
{
	SoundVolume = vol;
	s3eSoundSetInt(S3E_SOUND_VOLUME, (int)(SoundVolume * S3E_SOUND_MAX_VOLUME));
}
	void SimpleAudioEngine::setEffectsVolume(float volume)
	{
		
		s3eSoundSetInt(S3E_SOUND_VOLUME, volume);
	}
void Initialise()
{
	// Initialise Marmalade modules
	IwGxInit();

	// Create a new CIwTexture and use it to load the GUI image file
	gpTexture = new CIwTexture;
	gpTexture->LoadFromFile("ui.png");
	gpTexture->Upload();

	// Check for Dolby Digital Plus support
	gDolbySupported = false;
	gDolbyInitialised = false;
	if (s3eDolbyAudioAvailable() == S3E_TRUE)
	{
		if (s3eDolbyAudioSupported() == S3E_TRUE)
		{
			gDolbySupported = true;
		}
		s3eDeviceYield(0);
	}

	// Initialise Pause/Resume callbacks
	s3eDeviceRegister(S3E_DEVICE_PAUSE, AppSuspended, NULL);
	s3eDeviceRegister(S3E_DEVICE_BACKGROUND, AppSuspended, NULL);
	s3eDeviceRegister(S3E_DEVICE_UNPAUSE, AppResumed, NULL);
	s3eDeviceRegister(S3E_DEVICE_FOREGROUND, AppResumed, NULL);

	// Create our interface buttons
	int32 lSize = IwGxGetScreenWidth() / 5;
	int32 lGap = (int32) ((float) lSize * 0.1f);
	lSize = (int32) ((float) lSize * 0.9f);

	int32 lRowSize = IwGxGetScreenHeight() / 4;
	int32 lTopRowX = (IwGxGetScreenWidth() - (4 * lSize) - (3 * lGap)) / 2;
	int32 lTopRowY = lRowSize - (lSize / 2);
	int32 lBottomRowX = (IwGxGetScreenWidth() - (5 * lSize) - (4 * lGap)) / 2;
	int32 lBottomRowY = (3 * lRowSize) - (lSize / 2);
	int32 lLabelWidth = (240 * lSize) / 160;
	int32 lLabelHeight = (42 * lSize) / 160;
	int32 lLabelX = (IwGxGetScreenWidth() - lLabelWidth) / 2;

	gButton[BUTTON_AUDIO_LABEL] = new Button(gpTexture, lLabelX, lTopRowY - lLabelHeight - 10, lLabelWidth, lLabelHeight, 4, 408, 240, 42, false);
	gButton[BUTTON_AUDIO_OFF] = new Button(gpTexture, lTopRowX, lTopRowY, lSize, lSize, 347, 3, 160, 160, true);
	gButton[BUTTON_AUDIO_MUSIC] = new Button(gpTexture, lTopRowX + (lSize + lGap), lTopRowY, lSize, lSize, 175, 3, 160, 160, true);
	gButton[BUTTON_AUDIO_SFX] = new Button(gpTexture, lTopRowX + (2 * (lSize + lGap)), lTopRowY, lSize, lSize, 2, 173, 160, 160, true);
	gButton[BUTTON_AUDIO_SPEECH] = new Button(gpTexture, lTopRowX + (3 * (lSize + lGap)), lTopRowY, lSize, lSize, 174, 173, 160, 160, true);
	gButton[BUTTON_FILTER_LABEL] = new Button(gpTexture, lLabelX, lBottomRowY - lLabelHeight - 10, lLabelWidth, lLabelHeight, 2, 353, 240, 42, false);
	gButton[BUTTON_FILTER_OFF] = new Button(gpTexture, lBottomRowX, lBottomRowY, lSize, lSize, 347, 3, 160, 160, gDolbySupported);
	gButton[BUTTON_FILTER_MOVIE] = new Button(gpTexture, lBottomRowX + (lSize + lGap), lBottomRowY, lSize, lSize, 2, 3, 160, 160, gDolbySupported);
	gButton[BUTTON_FILTER_MUSIC] = new Button(gpTexture, lBottomRowX + (2 * (lSize + lGap)), lBottomRowY, lSize, lSize, 175, 3, 160, 160, gDolbySupported);
	gButton[BUTTON_FILTER_GAME] = new Button(gpTexture, lBottomRowX + (3 * (lSize + lGap)), lBottomRowY, lSize, lSize, 2, 173, 160, 160, gDolbySupported);
	gButton[BUTTON_FILTER_VOICE] = new Button(gpTexture, lBottomRowX + (4 * (lSize + lGap)), lBottomRowY, lSize, lSize, 174, 173, 160, 160, gDolbySupported);

	// Load sound effects into memory
	gpGunBattleSound = new Sound("gun-battle.raw");
	gpFemaleCountingSound = new Sound("female-counting.raw");

	// Configure default sample rate for s3eSound
	s3eSoundSetInt(S3E_SOUND_DEFAULT_FREQ, 44100);
}