JOAL v2.6.0-rc-20250706
JOAL, OpenAL® API Binding for Java™ (public API).
Buffer.java
Go to the documentation of this file.
1/**
2* Copyright (c) 2010-2023 JogAmp Community. All rights reserved.
3* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7*
8* -Redistribution of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10*
11* -Redistribution in binary form must reproduce the above copyright notice,
12* this list of conditions and the following disclaimer in the documentation
13* and/or other materials provided with the distribution.
14*
15* Neither the name of Sun Microsystems, Inc. or the names of contributors may
16* be used to endorse or promote products derived from this software without
17* specific prior written permission.
18*
19* This software is provided "AS IS," without a warranty of any kind.
20* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
21* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
22* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS
23* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
24* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
25* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
26* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
27* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
28* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
29* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
30*
31* You acknowledge that this software is not designed or intended for use in the
32* design, construction, operation or maintenance of any nuclear facility.
33*/
34
35package com.jogamp.openal.sound3d;
36
37import com.jogamp.openal.AL;
38import com.jogamp.openal.ALConstants;
39import java.nio.ByteBuffer;
40
41
42/**
43 * The Sound3D Buffer is a container for audio data used in the Sound3D
44 * environment.
45 *
46 * @author Athomas Goldberg, Sven Gothel, et al.
47 */
48public final class Buffer {
49 public final static int FORMAT_MONO8 = AL.AL_FORMAT_MONO8;
50
51 public final static int FORMAT_MONO16 = AL.AL_FORMAT_MONO16;
52
53 public final static int FORMAT_STEREO8 = AL.AL_FORMAT_STEREO8;
54
55 public final static int FORMAT_STEREO16 = AL.AL_FORMAT_STEREO16;
56
57 private int alBufferID;
58 private ByteBuffer data;
59
60 public Buffer(final int bufferID) {
61 this.alBufferID = bufferID;
62 }
63
64 /** Return the OpenAL buffer ID, -1 if invalid. */
65 public int getID() { return alBufferID; }
66
67 /** Returns whether {@link #getID()} is valid, i.e. not {@link #delete()}'ed */
68 public boolean isValid() {
69 return 0 <= alBufferID && AudioSystem3D.al.alIsBuffer(alBufferID);
70 }
71
72 /**
73 * Delete this buffer, and free its resources.
74 */
75 public void delete() {
76 data = null;
77 if( 0 <= alBufferID ) {
78 AudioSystem3D.al.alDeleteBuffers(1, new int[] { alBufferID }, 0);
79 alBufferID = -1;
80 }
81 }
82
83 /**
84 * Configure the Sound3D buffer
85 *
86 * @param data the raw audio data
87 * @param alFormat the OpenAL format of the data, e.g. <code>FORMAT_MONO8, FORMAT_MONO16,
88 * FORMAT_STEREO8</code> and <code>FORMAT_STEREO16</code>
89 * @param freq the frequency of the data
90 */
91 public void configure(final ByteBuffer data, final int alFormat, final int freq) {
92 this.data = data;
93 AudioSystem3D.al.alBufferData(alBufferID, alFormat, data, data.capacity(), freq);
94 }
95
96 /**
97 * Get the bit-depth of the data, (8 or 16)
98 *
99 * @return the bit-depth of the data
100 */
101 public int getBitDepth() {
102 final int[] i = new int[1];
103 AudioSystem3D.al.alGetBufferi(alBufferID, ALConstants.AL_BITS, i, 0);
104
105 return i[0];
106 }
107
108 /**
109 * Get the number of channels of the data (1-Mono, 2-Stereo)
110 *
111 * @return the number of audio channels.
112 */
113 public int getNumChannels() {
114 final int[] i = new int[1];
116
117 return i[0];
118 }
119
120 /**
121 * Gets the raw data contained in this buffer.
122 *
123 * @return the raw buffer data.
124 */
125 public ByteBuffer getData() {
126 return data;
127 }
128
129 /**
130 * Gets the audio frequency of the data contained in this buffer.
131 *
132 * @return the frequency of the data
133 */
134 public int getFrequency() {
135 final int[] i = new int[1];
137
138 return i[0];
139 }
140
141 /**
142 * Gets the size (in bytes) of the raw data containe in this buffer.
143 *
144 * @return the size of the data.
145 */
146 public int getSize() {
147 final int[] i = new int[1];
148 AudioSystem3D.al.alGetBufferi(alBufferID, ALConstants.AL_SIZE, i, 0);
149
150 return i[0];
151 }
152
153 @Override
154 public String toString() {
155 return "ALBuffer[id "+alBufferID+"]";
156 }
157}
The AudioSystem3D class provides a set of methods for creating and manipulating a 3D audio environmen...
The Sound3D Buffer is a container for audio data used in the Sound3D environment.
Definition: Buffer.java:48
ByteBuffer getData()
Gets the raw data contained in this buffer.
Definition: Buffer.java:125
void delete()
Delete this buffer, and free its resources.
Definition: Buffer.java:75
int getBitDepth()
Get the bit-depth of the data, (8 or 16)
Definition: Buffer.java:101
int getNumChannels()
Get the number of channels of the data (1-Mono, 2-Stereo)
Definition: Buffer.java:113
static final int FORMAT_MONO8
Definition: Buffer.java:49
static final int FORMAT_MONO16
Definition: Buffer.java:51
static final int FORMAT_STEREO8
Definition: Buffer.java:53
boolean isValid()
Returns whether getID() is valid, i.e.
Definition: Buffer.java:68
int getID()
Return the OpenAL buffer ID, -1 if invalid.
Definition: Buffer.java:65
int getFrequency()
Gets the audio frequency of the data contained in this buffer.
Definition: Buffer.java:134
int getSize()
Gets the size (in bytes) of the raw data containe in this buffer.
Definition: Buffer.java:146
void configure(final ByteBuffer data, final int alFormat, final int freq)
Configure the Sound3D buffer.
Definition: Buffer.java:91
static final int FORMAT_STEREO16
Definition: Buffer.java:55
Buffer(final int bufferID)
Definition: Buffer.java:60
static final int AL_CHANNELS
Define "AL_CHANNELS" with expression '0x2003', CType: int.
static final int AL_BITS
Define "AL_BITS" with expression '0x2002', CType: int.
static final int AL_FREQUENCY
Define "AL_FREQUENCY" with expression '0x2001', CType: int.
static final int AL_FORMAT_MONO8
Define "AL_FORMAT_MONO8" with expression '0x1100', CType: int.
static final int AL_SIZE
Define "AL_SIZE" with expression '0x2004', CType: int.
static final int AL_FORMAT_STEREO16
Define "AL_FORMAT_STEREO16" with expression '0x1103', CType: int.
static final int AL_FORMAT_STEREO8
Define "AL_FORMAT_STEREO8" with expression '0x1102', CType: int.
static final int AL_FORMAT_MONO16
Define "AL_FORMAT_MONO16" with expression '0x1101', CType: int.
void alBufferData(int buffer, int format, Buffer data, int size, int samplerate)
Entry point (through function pointer) to C language function: void alBufferData(ALuint buffer,...
boolean alIsBuffer(int buffer)
Entry point (through function pointer) to C language function: ALboolean alIsBuffer(ALuint buffer)
void alGetBufferi(int buffer, int param, IntBuffer value)
Entry point (through function pointer) to C language function: void alGetBufferi(ALuint buffer,...
void alDeleteBuffers(int n, IntBuffer buffers)
Entry point (through function pointer) to C language function: void alDeleteBuffers(ALsizei n,...