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