1package com.jogamp.openal.test.junit;
3import static org.junit.Assert.*;
5import java.io.IOException;
6import java.io.InputStream;
7import java.nio.ByteBuffer;
8import java.nio.ShortBuffer;
10import org.junit.Assert;
11import org.junit.FixMethodOrder;
13import org.junit.runners.MethodSorters;
15import com.jogamp.openal.ALCConstants;
16import com.jogamp.openal.ALConstants;
17import com.jogamp.openal.ALExtConstants;
18import com.jogamp.openal.ALFactory;
19import com.jogamp.openal.AL;
20import com.jogamp.openal.ALC;
21import com.jogamp.openal.ALExt;
22import com.jogamp.openal.ALCcontext;
23import com.jogamp.openal.ALCdevice;
24import com.jogamp.openal.UnsupportedAudioFileException;
25import com.jogamp.openal.test.resources.ResourceLocation;
26import com.jogamp.openal.test.util.UITestCase;
27import com.jogamp.openal.util.WAVData;
28import com.jogamp.openal.util.WAVLoader;
30@FixMethodOrder(MethodSorters.NAME_ASCENDING)
32 static boolean dumpSamples =
false;
36 testAlCLoopbackDeviceSOFTImpl(0, 0.4f);
40 testAlCLoopbackDeviceSOFTImpl(3, 0.8f);
50 System.out.println(
"No extension ALC_SOFT_loopback present");
53 final InputStream inputStream;
54 final int fmtChannels, fmtData, sampleSize, channelCount;
55 final boolean useShort;
57 inputStream = ResourceLocation.getTestStream0();
63 }
else if( 3 == srcIdx ) {
64 inputStream = ResourceLocation.getTestStream3();
77 System.out.println(
"begin testAlCLoopbackDeviceSOFT");
82 System.err.printf(
"CreatedSoftDevice: alcError 0x%X, dev %s%n", alcDevError, dev);
88 ALCcontext context =
null;
94 wd = WAVLoader.loadFromStream(inputStream);
95 System.err.println(
"fmt "+wd.format);
96 System.err.println(
"freq "+wd.freq);
97 System.err.println(
"size "+wd.size);
100 final String msg = String.format(
"Supported channels 0x%X, data 0x%X: %b", fmtChannels, fmtData, supported);
101 System.err.println(msg);
102 Assert.assertTrue(
"Not supported: "+msg, supported);
105 ALExtConstants.ALC_FORMAT_CHANNELS_SOFT,
107 ALExtConstants.ALC_FORMAT_TYPE_SOFT,
109 ALCConstants.ALC_FREQUENCY,
115 System.err.printf(
"CreatedSoftContext: alcError 0x%X, context %s%n", alcDevError, context);
116 }
catch (
final Exception e) {
120 assertNotNull(
"ALC context null", context);
124 final int dataSize = Math.min(4096, wd.size);
126 final int[] source = { 0 };
128 assertEquals(
"Could not gen source", ALConstants.AL_NO_ERROR, al.
alGetError());
130 final int[] buffer =
new int[1];
131 final int[] tmp =
new int[1];
134 assertEquals(
"Could not generate AL buffer", ALConstants.AL_NO_ERROR, al.
alGetError());
136 al.
alBufferData(buffer[0], wd.format, wd.data, dataSize, wd.freq);
137 assertEquals(
"Could not fill AL source buffer "+buffer[0]+
", sz "+dataSize+
", "+wd.data, ALConstants.AL_NO_ERROR, al.
alGetError());
138 al.
alGetBufferi(buffer[0], ALConstants.AL_SIZE, tmp, 0);
139 assertEquals(
"Could not get buffer size "+buffer[0], ALConstants.AL_NO_ERROR, al.
alGetError());
140 System.err.println(
"Buffer size "+tmp[0]+
" of "+dataSize);
141 al.
alSourcei(source[0], ALConstants.AL_BUFFER, buffer[0]);
142 assertEquals(
"Could source buffer "+buffer[0], ALConstants.AL_NO_ERROR, al.
alGetError());
145 assertEquals(
"Could not play source "+source[0], ALConstants.AL_NO_ERROR, al.
alGetError());
147 final ByteBuffer bbSink = ByteBuffer.allocateDirect(dataSize).order(wd.data.order());
149 final ShortBuffer sbSink = bbSink.asShortBuffer();
150 final ShortBuffer sbSrc = wd.data.asShortBuffer();
154 final int samplesPerChannel = dataSize / ( ( sampleSize / 8 ) * channelCount );
156 }
catch (
final Exception e) {
163 System.err.printf(
"alcRendering: alError 0x%X, alcError 0x%X%n", alError, alcDevError);
167 srcLimit = sbSink.limit();
169 srcLimit = bbSink.limit();
175 for (
int i=0; i<srcLimit; i++) {
176 final int a, b, a_u, b_u;
180 System.err.printf(
"%n[%04d]: ", i);
186 a_u = -Short.MIN_VALUE + a;
187 b_u = -Short.MIN_VALUE + b;
188 delta = Math.abs(Math.abs(a_u - b_u) / (
float)(0xffff+1));
190 System.err.printf(
"%6d %04X-> %6d %04X (%1.5f), ", a, a_u, b, b_u, delta);
196 a_u = -Byte.MIN_VALUE + a;
197 b_u = -Byte.MIN_VALUE + b;
198 delta = Math.abs(Math.abs(a_u - b_u) / (
float)(0xff+1));
200 System.err.printf(
"%4d %02X-> %4d %02X (%1.5f), ", a, a_u, b, b_u, delta);
207 System.err.println();
210 final float deltaA = deltaT / totalSize;
211 final float accuracy = Math.abs(1f - deltaA);
212 final String msg = String.format(
"Size[%04d s, %04d b, %04d b-t], Delta T %f, A %f, Accuracy %f / %f", totalSize, dataSize, wd.size,
213 deltaT, deltaA, accuracy, expAccuracy);
214 System.err.println(msg);
215 Assert.assertTrue(
"Too many rendering artifacts: "+msg, expAccuracy <= accuracy);
225 System.out.println(
"end testAlCLoopbackDeviceSOFT");
228 public static void main(
final String args[])
throws IOException {
This class provides factory methods for generating AL and ALC objects.
static AL getAL()
Get the default AL object.
static ALExt getALExt()
Get the default ALExt object.
static ALC getALC()
Get the default ALC object.
static void main(final String args[])
static final int ALC_EXTENSIONS
Define "ALC_EXTENSIONS" with expression '0x1006', CType: int.
boolean alcMakeContextCurrent(ALCcontext context)
Entry point (through function pointer) to C language function: ALCboolean alcMakeContextCurrent(ALC...
int alcGetError(ALCdevice device)
Entry point (through function pointer) to C language function: ALCenum alcGetError(ALCdevice * dev...
String alcGetString(ALCdevice device, int param)
Entry point (through function pointer) to C language function: const ALCchar * alcGetString(ALCdevi...
boolean alcCloseDevice(ALCdevice device)
Entry point (through function pointer) to C language function: ALCboolean alcCloseDevice(ALCdevice ...
boolean alcIsExtensionPresent(ALCdevice device, String extname)
Entry point (through function pointer) to C language function: ALCboolean alcIsExtensionPresent(ALC...
ALCcontext alcCreateContext(ALCdevice device, IntBuffer attrlist)
Entry point (through function pointer) to C language function: ALCcontext * alcCreateContext(ALCdev...
static final int AL_BYTE_SOFT
Define "AL_BYTE_SOFT" with expression '0x1400', CType: int.
static final int AL_MONO_SOFT
Define "AL_MONO_SOFT" with expression '0x1500', CType: int.
static final int AL_SHORT_SOFT
Define "AL_SHORT_SOFT" with expression '0x1402', CType: int.
static final int AL_STEREO_SOFT
Define "AL_STEREO_SOFT" with expression '0x1501', CType: int.
ALCdevice alcLoopbackOpenDeviceSOFT(String deviceName)
Entry point (through function pointer) to C language function: ALCdevice * alcLoopbackOpenDeviceSOF...
void alcRenderSamplesSOFT(ALCdevice device, Buffer buffer, int samples)
Entry point (through function pointer) to C language function: void alcRenderSamplesSOFT(ALCdevice ...
boolean alcIsRenderFormatSupportedSOFT(ALCdevice device, int freq, int channels, int type)
Entry point (through function pointer) to C language function: ALCboolean alcIsRenderFormatSupporte...
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,...
int alGetError()
Entry point (through function pointer) to C language function: ALenum alGetError()
void alGenBuffers(int n, IntBuffer buffers)
Entry point (through function pointer) to C language function: void alGenBuffers(ALsizei n,...
void alSourcePlay(int source)
Entry point (through function pointer) to C language function: void alSourcePlay(ALuint source)
void alGetBufferi(int buffer, int param, IntBuffer value)
Entry point (through function pointer) to C language function: void alGetBufferi(ALuint buffer,...
void alSourcei(int source, int param, int value)
Entry point (through function pointer) to C language function: void alSourcei(ALuint source,...
void alGenSources(int n, IntBuffer sources)
Entry point (through function pointer) to C language function: void alGenSources(ALsizei n,...