SoundBuffer .java

com.mojang.blaze3d.audio.SoundBuffer (class): members: discardAlBuffer, releaseAlBuffer, hasAlBuffer, alBuffer, isValid, format, data, size. imports: AL10.

com.mojang.blaze3d.audioclass80 linesclient1.8 KB

API Surface (5)

void discardAlBuffer()
OptionalInt releaseAlBuffer()
AudioFormat format()
int size()
boolean isValid()

Fields & Constants (5)

data
format
hasAlBuffer
alBuffer
size

String literals (3)

"Creating buffer"
"Assigning buffer data"
"Deleting stream buffers"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SoundBuffer.java80 lines · Minecraft 26.3 · verbatim
1
package com.mojang.blaze3d.audio;
2
3
import java.nio.ByteBuffer;
4
import java.util.OptionalInt;
5
import javax.sound.sampled.AudioFormat;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import org.jspecify.annotations.Nullable;
9
import org.lwjgl.openal.AL10;
10
11
@Environment(EnvType.CLIENT)
12
public class SoundBuffer {
13
	private @Nullable ByteBuffer data;
14
	private final AudioFormat format;
15
	private boolean hasAlBuffer;
16
	private int alBuffer;
17
	private final int size;
18
19
	public SoundBuffer(final ByteBuffer data, final AudioFormat format) {
20
		this.data = data;
21
		this.format = format;
22
		this.size = data.limit();
23
	}
24
25
	OptionalInt getAlBuffer() {
26
		if (!this.hasAlBuffer) {
27
			if (this.data == null) {
28
				return OptionalInt.empty();
29
			}
30
31
			int audioFormat = OpenAlUtil.audioFormatToOpenAl(this.format);
32
			int[] intBuffer = new int[1];
33
			AL10.alGenBuffers(intBuffer);
34
			if (OpenAlUtil.checkALError("Creating buffer")) {
35
				return OptionalInt.empty();
36
			}
37
38
			AL10.alBufferData(intBuffer[0], audioFormat, this.data, (int)this.format.getSampleRate());
39
			if (OpenAlUtil.checkALError("Assigning buffer data")) {
40
				return OptionalInt.empty();
41
			}
42
43
			this.alBuffer = intBuffer[0];
44
			this.hasAlBuffer = true;
45
			this.data = null;
46
		}
47
48
		return OptionalInt.of(this.alBuffer);
49
	}
50
51
	public void discardAlBuffer() {
52
		if (this.hasAlBuffer) {
53
			AL10.alDeleteBuffers(new int[]{this.alBuffer});
54
			if (OpenAlUtil.checkALError("Deleting stream buffers")) {
55
				return;
56
			}
57
		}
58
59
		this.hasAlBuffer = false;
60
	}
61
62
	public OptionalInt releaseAlBuffer() {
63
		OptionalInt result = this.getAlBuffer();
64
		this.hasAlBuffer = false;
65
		return result;
66
	}
67
68
	public AudioFormat format() {
69
		return this.format;
70
	}
71
72
	public int size() {
73
		return this.size;
74
	}
75
76
	public boolean isValid() {
77
		return this.data != null || this.hasAlBuffer;
78
	}
79
}
80

Decompiled Minecraft 26.3 source of SoundBuffer (com/mojang/blaze3d/audio/SoundBuffer.java) with Mojang official mappings, stored verbatim on the site.