OpenAlUtil.java

com.mojang.blaze3d.audio.OpenAlUtil

信息

  • 全限定名:com.mojang.blaze3d.audio.OpenAlUtil
  • 类型:public class
  • 包:com.mojang.blaze3d.audio
  • 源码路径:src/main/java/com/mojang/blaze3d/audio/OpenAlUtil.java
  • 起始行号:L13
  • 职责:

    TODO

字段/常量

  • LOGGER
    • 类型: Logger
    • 修饰符: private static final
    • 源码定位: L14
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

private static String alErrorToString(int error) @ L16

  • 方法名:alErrorToString
  • 源码定位:L16
  • 返回类型:String
  • 修饰符:private static

参数:

  • error: int

说明:

TODO

static boolean checkALError(String location) @ L33

  • 方法名:checkALError
  • 源码定位:L33
  • 返回类型:boolean
  • 修饰符:static

参数:

  • location: String

说明:

TODO

private static String alcErrorToString(int error) @ L43

  • 方法名:alcErrorToString
  • 源码定位:L43
  • 返回类型:String
  • 修饰符:private static

参数:

  • error: int

说明:

TODO

static boolean checkALCError(long device, String location) @ L60

  • 方法名:checkALCError
  • 源码定位:L60
  • 返回类型:boolean
  • 修饰符:static

参数:

  • device: long
  • location: String

说明:

TODO

static int audioFormatToOpenAl(AudioFormat audioFormat) @ L70

  • 方法名:audioFormatToOpenAl
  • 源码定位:L70
  • 返回类型:int
  • 修饰符:static

参数:

  • audioFormat: AudioFormat

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class OpenAlUtil {
    private static final Logger LOGGER = LogUtils.getLogger();
 
    private static String alErrorToString(int error) {
        switch (error) {
            case 40961:
                return "Invalid name parameter.";
            case 40962:
                return "Invalid enumerated parameter value.";
            case 40963:
                return "Invalid parameter parameter value.";
            case 40964:
                return "Invalid operation.";
            case 40965:
                return "Unable to allocate memory.";
            default:
                return "An unrecognized error occurred.";
        }
    }
 
    static boolean checkALError(String location) {
        int error = AL10.alGetError();
        if (error != 0) {
            LOGGER.error("{}: {}", location, alErrorToString(error));
            return true;
        } else {
            return false;
        }
    }
 
    private static String alcErrorToString(int error) {
        switch (error) {
            case 40961:
                return "Invalid device.";
            case 40962:
                return "Invalid context.";
            case 40963:
                return "Illegal enum.";
            case 40964:
                return "Invalid value.";
            case 40965:
                return "Unable to allocate memory.";
            default:
                return "An unrecognized error occurred.";
        }
    }
 
    static boolean checkALCError(long device, String location) {
        int error = ALC10.alcGetError(device);
        if (error != 0) {
            LOGGER.error("{} ({}): {}", location, device, alcErrorToString(error));
            return true;
        } else {
            return false;
        }
    }
 
    static int audioFormatToOpenAl(AudioFormat audioFormat) {
        Encoding encoding = audioFormat.getEncoding();
        int channels = audioFormat.getChannels();
        int sampleSizeInBits = audioFormat.getSampleSizeInBits();
        if (encoding.equals(Encoding.PCM_UNSIGNED) || encoding.equals(Encoding.PCM_SIGNED)) {
            if (channels == 1) {
                if (sampleSizeInBits == 8) {
                    return 4352;
                }
 
                if (sampleSizeInBits == 16) {
                    return 4353;
                }
            } else if (channels == 2) {
                if (sampleSizeInBits == 8) {
                    return 4354;
                }
 
                if (sampleSizeInBits == 16) {
                    return 4355;
                }
            }
        }
 
        throw new IllegalArgumentException("Invalid audio format: " + audioFormat);
    }
}

引用的其他类