Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lDEVinux
GitHub Repository: lDEVinux/eaglercraft
Path: blob/main/src/lwjgl/java/paulscode/sound/SoundBuffer.java
8644 views
1
package paulscode.sound;
2
3
import javax.sound.sampled.AudioFormat;
4
5
/**
6
* The SoundBuffer class is used to wrap audio data along with the format in
7
* which the data is stored.
8
*<br><br>
9
*<b><i> SoundSystem License:</b></i><br><b><br>
10
* You are free to use this library for any purpose, commercial or otherwise.
11
* You may modify this library or source code, and distribute it any way you
12
* like, provided the following conditions are met:
13
*<br>
14
* 1) You may not falsely claim to be the author of this library or any
15
* unmodified portion of it.
16
*<br>
17
* 2) You may not copyright this library or a modified version of it and then
18
* sue me for copyright infringement.
19
*<br>
20
* 3) If you modify the source code, you must clearly document the changes
21
* made before redistributing the modified source code, so other users know
22
* it is not the original code.
23
*<br>
24
* 4) You are not required to give me credit for this library in any derived
25
* work, but if you do, you must also mention my website:
26
* http://www.paulscode.com
27
*<br>
28
* 5) I the author will not be responsible for any damages (physical,
29
* financial, or otherwise) caused by the use if this library or any part
30
* of it.
31
*<br>
32
* 6) I the author do not guarantee, warrant, or make any representations,
33
* either expressed or implied, regarding the use of this library or any
34
* part of it.
35
* <br><br>
36
* Author: Paul Lamb
37
* <br>
38
* http://www.paulscode.com
39
* </b>
40
*/
41
public class SoundBuffer
42
{
43
/**
44
* The actual audio data.
45
*/
46
public byte[] audioData;
47
/**
48
* The audio format in which the data is stored.
49
*/
50
public AudioFormat audioFormat;
51
52
/**
53
* Constructor: Wraps the specified data with the specified audio format.
54
*
55
* @param audioData The actual audio data.
56
* @param audioFormat The audio format in which the data is stored.
57
*/
58
public SoundBuffer( byte[] audioData, AudioFormat audioFormat )
59
{
60
this.audioData = audioData;
61
this.audioFormat = audioFormat;
62
}
63
64
/**
65
* Removes handles to all instantiated objects.
66
*/
67
public void cleanup()
68
{
69
audioData = null;
70
audioFormat = null;
71
}
72
73
/**
74
* Trims down the size of the audio data if it is larger than the specified
75
* maximum length.
76
*
77
* @param maxLength Maximum size this buffer may be.
78
*/
79
public void trimData( int maxLength )
80
{
81
if( audioData == null || maxLength == 0 )
82
audioData = null;
83
else if( audioData.length > maxLength )
84
{
85
byte[] trimmedArray = new byte[maxLength];
86
System.arraycopy( audioData, 0, trimmedArray, 0,
87
maxLength );
88
audioData = trimmedArray;
89
}
90
}
91
}
92
93