AudioSource* AudioSource::clone(NodeCloneContext &context) const { GP_ASSERT(_buffer); ALuint alSource = 0; AL_CHECK( alGenSources(1, &alSource) ); if (AL_LAST_ERROR()) { GP_ERROR("Error generating audio source."); return NULL; } AudioSource* audioClone = new AudioSource(_buffer, alSource); _buffer->addRef(); audioClone->setLooped(isLooped()); audioClone->setGain(getGain()); audioClone->setPitch(getPitch()); audioClone->setVelocity(getVelocity()); if (Node* node = getNode()) { Node* clonedNode = context.findClonedNode(node); if (clonedNode) { audioClone->setNode(clonedNode); } } return audioClone; }
int lua_AudioSource_setPitch(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA) && lua_type(state, 2) == LUA_TNUMBER) { // Get parameter 1 off the stack. float param1 = (float)luaL_checknumber(state, 2); AudioSource* instance = getInstance(state); instance->setPitch(param1); return 0; } lua_pushstring(state, "lua_AudioSource_setPitch - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; }
AudioSource* AudioSource::create(Properties* properties) { // Check if the properties is valid and has a valid namespace. assert(properties); if (!properties || !(strcmp(properties->getNamespace(), "audio") == 0)) { WARN("Failed to load audio source from properties object: must be non-null object and have namespace equal to \'audio\'."); return NULL; } const char* path = properties->getString("path"); if (path == NULL) { WARN("Audio file failed to load; the file path was not specified."); return NULL; } // Create the audio source. AudioSource* audio = AudioSource::create(path); if (audio == NULL) { WARN_VARG("Audio file '%s' failed to load properly.", path); return NULL; } // Set any properties that the user specified in the .audio file. if (properties->getString("looped") != NULL) { audio->setLooped(properties->getBool("looped")); } if (properties->getString("gain") != NULL) { audio->setGain(properties->getFloat("gain")); } if (properties->getString("pitch") != NULL) { audio->setPitch(properties->getFloat("pitch")); } Vector3 v; if (properties->getVector3("velocity", &v)) { audio->setVelocity(v); } return audio; }
AudioSource* AudioSource::create(Properties* properties) { // Check if the properties is valid and has a valid namespace. GP_ASSERT(properties); if (!properties || !(strcmp(properties->getNamespace(), "audio") == 0)) { GP_ERROR("Failed to load audio source from properties object: must be non-null object and have namespace equal to 'audio'."); return NULL; } std::string path; if (!properties->getPath("path", &path)) { GP_ERROR("Audio file failed to load; the file path was not specified."); return NULL; } // Create the audio source. AudioSource* audio = AudioSource::create(path.c_str()); if (audio == NULL) { GP_ERROR("Audio file '%s' failed to load properly.", path.c_str()); return NULL; } // Set any properties that the user specified in the .audio file. if (properties->exists("looped")) { audio->setLooped(properties->getBool("looped")); } if (properties->exists("gain")) { audio->setGain(properties->getFloat("gain")); } if (properties->exists("pitch")) { audio->setPitch(properties->getFloat("pitch")); } Vector3 v; if (properties->getVector3("velocity", &v)) { audio->setVelocity(v); } return audio; }