예제 #1
0
void SoundManager::loadMusic(char** path)
{



	musicpath[0] = "data/media/music/spooky.ogg";
	musicpath[1] = "data/media/music/hills.ogg";
	musicpath[2] = "data/media/music/tut3.ogg";




	AddMusic(musicpath[0], "Spooky Scary Skeletons");
	AddMusic(musicpath[1], "Green Hills");
	AddMusic(musicpath[2], "Tutorial 3");



}
bool AudioManager::LoadAudio()
{
	//Create all the layers of sfx for the different players
	for(int i = 0; i < m_sfxChannelCount; i++)
	{
		vector<shared_ptr<ImplData>> sfxVec;
		m_sfxTrackList.push_back(sfxVec);
	}
	for(int m = 0; m < m_musicChannelCount; m++)
	{
		vector<shared_ptr<ImplData>> musicVev;
		m_musicTrackList.push_back(musicVev);
	}

	string path = "Data\\Audio\\";
	string searchPattern = "*.wav";
	string fullSearchPath = path + searchPattern;
	WIN32_FIND_DATA FindData;
	HANDLE hFind;
	hFind = FindFirstFile(fullSearchPath.c_str(), &FindData);

	if (hFind == INVALID_HANDLE_VALUE)
	{
		errorOutput << "Unable to find directory: " << path;
		string o = errorOutput.str();
		MessageBoxA(NULL, o.c_str(), "ERROR", MB_OK | MB_ICONERROR);
	}

	do
	{
		//convert to sent the path
		string filePath = path + FindData.cFileName;
		char *cstr = new char[filePath.length() + 1];
		strcpy(cstr, filePath.c_str());
		
		ifstream in(filePath.c_str());
		if (in)
		{
			string filecheck = cstr;

			//Check to see if the file is of type music and add it
			if(filecheck.find("music_") != string::npos)
			{
				musicIndexMap.insert(std::map<string, int >::value_type(FindData.cFileName, musicIndexMap.size()));
				AddMusic(cstr);
			}
			//Check to see if the file is of type sfx and add it
			if(filecheck.find("sfx_") != string::npos)
			{
				sfxIndexMap.insert(std::map<string, int >::value_type(FindData.cFileName, sfxIndexMap.size()));
				AddSFX(cstr);
			}

			//Check to see if the file is of type sfx and add it
			if (filecheck.find("3ds_") != string::npos)
			{
				sound3dIndexMap.insert(std::map<string, int >::value_type(FindData.cFileName, sound3dIndexMap.size()));
				Add3dSound(cstr);
			}
		}
		else
		{
			errorOutput << "Problem opening file: " << FindData.cFileName;
			string o = errorOutput.str();
			MessageBoxA(NULL, o.c_str(), "ERROR", MB_OK | MB_ICONERROR);
		}


	} while (FindNextFile(hFind, &FindData) > 0);


	if (GetLastError() != ERROR_NO_MORE_FILES)
	{
		//   cout << "Something went wrong during searching\n";
	}
	return true;;
}