Fix speaker peripheral API

This commit is contained in:
Restioson 2017-05-07 18:43:29 +02:00
parent 2444245b80
commit 2899246dbc
1 changed files with 7 additions and 7 deletions

View File

@ -104,8 +104,8 @@ public Object[] callMethod(IComputerAccess computerAccess, ILuaContext context,
private Object[] playNote(Object[] arguments) throws LuaException
{
float volume = 1f;
float pitch = 1f;
double volume = 1f;
double pitch = 1f;
// Check if arguments are correct
if (arguments.length == 0) // Too few args
@ -114,7 +114,7 @@ private Object[] playNote(Object[] arguments) throws LuaException
}
if (!(arguments[0] instanceof String)) // Arg wrong type
{
{
throw new LuaException("Expected string, number (optional), number (optional)");
}
@ -125,7 +125,7 @@ private Object[] playNote(Object[] arguments) throws LuaException
if (arguments.length > 1)
{
if (!(arguments[1] instanceof Double)) // Arg wrong type
if (!(arguments[1] instanceof Double)) // Arg wrong type
{
throw new LuaException("Expected string, number (optional), number (optional)");
}
@ -135,7 +135,7 @@ private Object[] playNote(Object[] arguments) throws LuaException
if (arguments.length > 2)
{
if (!(arguments[2] instanceof Double)) // Arg wrong type
if (!(arguments[1] instanceof Double)) // Arg wrong type
{
throw new LuaException("Expected string, number (optional), number (optional)");
}
@ -147,7 +147,7 @@ private Object[] playNote(Object[] arguments) throws LuaException
throw new LuaException("Expected string, number (optional), number (optional)");
}
return playSound(new Object[] {"block.note." + arguments[0], volume, pitch});
return playSound(new Object[] {"block.note." + arguments[0], volume, Math.pow(2d, (pitch - 12) / 12d)});
}
@ -180,7 +180,7 @@ private Object[] playSound(Object[] arguments) throws LuaException
if (arguments.length > 2)
{
if (!(arguments[2] instanceof Double)) // Arg wrong type
if (!(arguments[1] instanceof Double)) // Arg wrong type
{
throw new LuaException("Expected string, number (optional), number (optional)");
}