Skip to content

Commit 11f1108

Browse files
axmol-bothalx99
andauthored
Committing luabindings for commit 92a59bf (#2385)
* Committing luabindings for commit 92a59bf * Fixup --------- Co-authored-by: halx99 <[email protected]> Co-authored-by: halx99 <[email protected]>
1 parent 92a59bf commit 11f1108

File tree

2 files changed

+89
-8
lines changed

2 files changed

+89
-8
lines changed

core/audio/AudioEngine.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,7 @@ void AudioEngine::setVolume(AUDIO_ID audioID, float volume)
199199
auto it = _audioIDInfoMap.find(audioID);
200200
if (it != _audioIDInfoMap.end())
201201
{
202-
if (volume < 0.0f)
203-
{
204-
volume = 0.0f;
205-
}
206-
else if (volume > 1.0f)
207-
{
208-
volume = 1.0f;
209-
}
202+
volume = std::max(volume, 0.0f);
210203

211204
if (it->second.volume != volume)
212205
{
@@ -231,6 +224,18 @@ void AudioEngine::setPitch(AUDIO_ID audioID, float pitch)
231224
}
232225
}
233226

227+
float AudioEngine::getPitch(AUDIO_ID audioID)
228+
{
229+
auto tmpIterator = _audioIDInfoMap.find(audioID);
230+
if (tmpIterator != _audioIDInfoMap.end())
231+
{
232+
return tmpIterator->second.pitch;
233+
}
234+
235+
AXLOGW("AudioEngine::getPitch-->The audio instance {} is non-existent", audioID);
236+
return 0.0f;
237+
}
238+
234239
void AudioEngine::pause(AUDIO_ID audioID)
235240
{
236241
auto it = _audioIDInfoMap.find(audioID);

extensions/scripting/lua-bindings/auto/axlua_audioengine_auto.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,80 @@ int lua_ax_audioengine_AudioEngine_getVolume(lua_State* tolua_S)
438438
#endif
439439
return 0;
440440
}
441+
int lua_ax_audioengine_AudioEngine_setPitch(lua_State* tolua_S)
442+
{
443+
int argc = 0;
444+
bool ok = true;
445+
446+
#if _AX_DEBUG >= 1
447+
tolua_Error tolua_err;
448+
#endif
449+
450+
#if _AX_DEBUG >= 1
451+
if (!tolua_isusertable(tolua_S,1,"ax.AudioEngine",0,&tolua_err)) goto tolua_lerror;
452+
#endif
453+
454+
argc = lua_gettop(tolua_S) - 1;
455+
456+
if (argc == 2)
457+
{
458+
int arg0;
459+
double arg1;
460+
ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ax.AudioEngine:setPitch");
461+
ok &= luaval_to_number(tolua_S, 3,&arg1, "ax.AudioEngine:setPitch");
462+
if(!ok)
463+
{
464+
tolua_error(tolua_S,"invalid arguments in function 'lua_ax_audioengine_AudioEngine_setPitch'", nullptr);
465+
return 0;
466+
}
467+
ax::AudioEngine::setPitch(arg0, arg1);
468+
lua_settop(tolua_S, 1);
469+
return 1;
470+
}
471+
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.AudioEngine:setPitch",argc, 2);
472+
return 0;
473+
#if _AX_DEBUG >= 1
474+
tolua_lerror:
475+
tolua_error(tolua_S,"#ferror in function 'lua_ax_audioengine_AudioEngine_setPitch'.",&tolua_err);
476+
#endif
477+
return 0;
478+
}
479+
int lua_ax_audioengine_AudioEngine_getPitch(lua_State* tolua_S)
480+
{
481+
int argc = 0;
482+
bool ok = true;
483+
484+
#if _AX_DEBUG >= 1
485+
tolua_Error tolua_err;
486+
#endif
487+
488+
#if _AX_DEBUG >= 1
489+
if (!tolua_isusertable(tolua_S,1,"ax.AudioEngine",0,&tolua_err)) goto tolua_lerror;
490+
#endif
491+
492+
argc = lua_gettop(tolua_S) - 1;
493+
494+
if (argc == 1)
495+
{
496+
int arg0;
497+
ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ax.AudioEngine:getPitch");
498+
if(!ok)
499+
{
500+
tolua_error(tolua_S,"invalid arguments in function 'lua_ax_audioengine_AudioEngine_getPitch'", nullptr);
501+
return 0;
502+
}
503+
auto&& ret = ax::AudioEngine::getPitch(arg0);
504+
tolua_pushnumber(tolua_S,(lua_Number)ret);
505+
return 1;
506+
}
507+
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.AudioEngine:getPitch",argc, 1);
508+
return 0;
509+
#if _AX_DEBUG >= 1
510+
tolua_lerror:
511+
tolua_error(tolua_S,"#ferror in function 'lua_ax_audioengine_AudioEngine_getPitch'.",&tolua_err);
512+
#endif
513+
return 0;
514+
}
441515
int lua_ax_audioengine_AudioEngine_pause(lua_State* tolua_S)
442516
{
443517
int argc = 0;
@@ -1161,6 +1235,8 @@ int lua_register_ax_audioengine_AudioEngine(lua_State* tolua_S)
11611235
tolua_function(tolua_S,"isLoop", lua_ax_audioengine_AudioEngine_isLoop);
11621236
tolua_function(tolua_S,"setVolume", lua_ax_audioengine_AudioEngine_setVolume);
11631237
tolua_function(tolua_S,"getVolume", lua_ax_audioengine_AudioEngine_getVolume);
1238+
tolua_function(tolua_S,"setPitch", lua_ax_audioengine_AudioEngine_setPitch);
1239+
tolua_function(tolua_S,"getPitch", lua_ax_audioengine_AudioEngine_getPitch);
11641240
tolua_function(tolua_S,"pause", lua_ax_audioengine_AudioEngine_pause);
11651241
tolua_function(tolua_S,"pauseAll", lua_ax_audioengine_AudioEngine_pauseAll);
11661242
tolua_function(tolua_S,"resume", lua_ax_audioengine_AudioEngine_resume);

0 commit comments

Comments
 (0)