Sound *Sound::Create(float *inData, int len, bool inForceMusic) { if (!Init()) return 0; Sound *sound = inForceMusic ? 0 : new SDLSound(inData, len); if (!sound || !sound->ok()) { if (sound) sound->DecRef(); sound = new SDLMusic(inData, len); } return sound; }
Sound *Sound::Create(const std::string &inFilename,bool inForceMusic) { if (!Init()) return 0; Sound *sound = inForceMusic ? 0 : new SDLSound(inFilename); if (!sound || !sound->ok()) { if (sound) sound->DecRef(); sound = new SDLMusic(inFilename); } return sound; }
Sound *Sound::FromFile(const std::string &inFilename, bool inForceMusic, const std::string &inEngine) { Sound *result = 0; #ifdef HX_ANDROID if (inEngine=="opensl") result = ReadAndCreate(inFilename, inForceMusic, CreateOpenSlSound); else result = CreateAndroidSound(inFilename,inForceMusic); #elif defined(IPHONE) AudioFormat format = determineFormatFromFile(inFilename); if (format==eAF_mp3 || (inForceMusic && format!=eAF_ogg && format!=eAF_mid ) || inEngine=="avplayer" ) result = CreateAvPlayerSound(inFilename); else result = ReadAndCreate(inFilename, inForceMusic, CreateOpenAlSound); #elif defined(EMSCRIPTEN) result = ReadAndCreate(inFilename, inForceMusic, CreateOpenAlSound); #else #ifdef HX_MACOS if (inEngine=="openal") result = ReadAndCreate(inFilename, inForceMusic, CreateOpenAlSound); else #endif result = CreateSdlSound(inFilename,inForceMusic); #endif if (result && !result->ok()) { result->DecRef(); result = 0; } if (!result) ELOG("Error creating sound from filename %s", inFilename.c_str() ); return result; }
Sound *Sound::FromEncodedBytes(const unsigned char *inData, int inLen, bool inForceMusic, const std::string &inEngine) { Sound *result = 0; #ifdef HX_ANDROID // Maybe use opensl here .... if (inEngine=="opensl") result = CreateOpenSlSound(inData, inLen, inForceMusic); else result = CreateAndroidSound(inData, inLen, inForceMusic); #elif defined(IPHONE) // AVPlayer must be used to play mp3 files // OpenAl must be used to play ogg and mid // OpenAl allows small files to be cached in buffers // AVPlayer as better hardware pathways AudioFormat format = determineFormatFromBytes(inData, inLen); if (format==eAF_mp3 || (inForceMusic && format!=eAF_ogg && format!=eAF_mid ) ) result = CreateAvPlayerSound(inData,inLen); else result = CreateOpenAlSound(inData, inLen, inForceMusic); #elif defined(EMSCRIPTEN) result = CreateOpenAlSound(inData, inLen, inForceMusic); if (!result || !result->ok()) { if (result) result->DecRef(); result = CreateSdlSound(inData, inLen, inForceMusic); } #else #ifdef HX_MACOS // Openal can be tested on mac if (inEngine=="openal") { result = CreateOpenAlSound(inData, inLen, inForceMusic); } else #endif result = CreateSdlSound(inData, inLen, inForceMusic); #endif if (result && !result->ok()) { result->DecRef(); result = 0; } if (!result) ELOG("Error creating sound from %d bytes", inLen); return result; }