aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/jogamp/common
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-05-23 01:37:01 +0200
committerSven Gothel <[email protected]>2023-05-23 01:37:01 +0200
commit6a74d16a805a4204093972bb91361b2aa633065c (patch)
tree22c8c3e8efc7a69dff73c87e8d2e54ff65591839 /src/java/jogamp/common
parentc04726720a57f8db42f2621ad58ff3bd42006c63 (diff)
AudioSink: Drop getMaxSupportedChannels(), use getNativeFormat(), getPreferredFormat() and isSupported(); Add setChannelLimit() impacting
Add setChannelLimit() impacting getPreferredFormat() and isSupported(), i.e. to limit channels for e.g. JOAL/OpenAL spatial 3D sound usage. getNativeFormat() shall be unaffected. getMaxSupportedChannels() is redudandant -> getPreferredFormat()
Diffstat (limited to 'src/java/jogamp/common')
-rw-r--r--src/java/jogamp/common/av/JavaSoundAudioSink.java43
-rw-r--r--src/java/jogamp/common/av/NullAudioSink.java14
2 files changed, 42 insertions, 15 deletions
diff --git a/src/java/jogamp/common/av/JavaSoundAudioSink.java b/src/java/jogamp/common/av/JavaSoundAudioSink.java
index d3ddda9..58f0fec 100644
--- a/src/java/jogamp/common/av/JavaSoundAudioSink.java
+++ b/src/java/jogamp/common/av/JavaSoundAudioSink.java
@@ -61,6 +61,9 @@ public final class JavaSoundAudioSink implements AudioSink {
private int bufferCount;
private final byte [] sampleData = new byte[BUFFER_SIZE];
private boolean available = false;
+ private final AudioFormat nativeFormat;
+ private int userMaxChannels = 8;
+ private AudioFormat preferredFormat = null;
private AudioFormat chosenFormat = null;
private volatile boolean playRequested = false;
@@ -79,8 +82,12 @@ public final class JavaSoundAudioSink implements AudioSink {
public JavaSoundAudioSink() {
available = false;
if( !staticAvailable ) {
+ nativeFormat = DefaultFormat;
return;
}
+ nativeFormat = new AudioFormat(DefaultFormat.sampleRate, DefaultFormat.sampleSize, getMaxSupportedChannels(),
+ DefaultFormat.signed, DefaultFormat.fixedP, DefaultFormat.planar, DefaultFormat.littleEndian);
+ preferredFormat = nativeFormat;
available = true;
}
@@ -118,11 +125,6 @@ public final class JavaSoundAudioSink implements AudioSink {
}
@Override
- public int getPreferredSampleRate() {
- return DefaultFormat.sampleRate;
- }
-
- @Override
public int getSourceCount() {
return -1;
}
@@ -138,17 +140,41 @@ public final class JavaSoundAudioSink implements AudioSink {
}
@Override
+ public final AudioFormat getNativeFormat() {
+ return nativeFormat;
+ }
+
+ @Override
public AudioFormat getPreferredFormat() {
return DefaultFormat;
}
@Override
- public final int getMaxSupportedChannels() {
- return 2;
+ public final void setChannelLimit(final int cc) {
+ userMaxChannels = Math.min(8, Math.max(1, cc));
+ preferredFormat = new AudioFormat(nativeFormat.sampleRate,
+ nativeFormat.sampleSize, getMaxSupportedChannels(),
+ nativeFormat.signed, nativeFormat.fixedP,
+ nativeFormat.planar, nativeFormat.littleEndian);
+ if( DEBUG ) {
+ System.out.println("ALAudioSink: channelLimit "+userMaxChannels+", preferredFormat "+preferredFormat);
+ }
+ }
+
+ private final int getMaxSupportedChannels() {
+ final int cc = 2;
+ return Math.min(userMaxChannels, cc);
}
@Override
public final boolean isSupported(final AudioFormat format) {
+ if( format.planar != preferredFormat.planar ||
+ format.fixedP != preferredFormat.fixedP ||
+ format.sampleRate > preferredFormat.sampleRate ||
+ format.channelCount > preferredFormat.channelCount )
+ {
+ return false;
+ }
return true;
}
@@ -157,6 +183,9 @@ public final class JavaSoundAudioSink implements AudioSink {
if( !staticAvailable ) {
return false;
}
+ if( !isSupported(requestedFormat) ) {
+ return false;
+ }
// Create the audio format we wish to use
format = new javax.sound.sampled.AudioFormat(requestedFormat.sampleRate, requestedFormat.sampleSize, requestedFormat.channelCount, requestedFormat.signed, !requestedFormat.littleEndian);
diff --git a/src/java/jogamp/common/av/NullAudioSink.java b/src/java/jogamp/common/av/NullAudioSink.java
index 19b0acb..904b863 100644
--- a/src/java/jogamp/common/av/NullAudioSink.java
+++ b/src/java/jogamp/common/av/NullAudioSink.java
@@ -84,11 +84,6 @@ public final class NullAudioSink implements AudioSink {
}
@Override
- public int getPreferredSampleRate() {
- return DefaultFormat.sampleRate;
- }
-
- @Override
public int getSourceCount() {
return -1;
}
@@ -104,16 +99,19 @@ public final class NullAudioSink implements AudioSink {
}
@Override
- public AudioFormat getPreferredFormat() {
+ public AudioFormat getNativeFormat() {
return DefaultFormat;
}
@Override
- public final int getMaxSupportedChannels() {
- return 8;
+ public AudioFormat getPreferredFormat() {
+ return DefaultFormat;
}
@Override
+ public void setChannelLimit(final int cc) { }
+
+ @Override
public final boolean isSupported(final AudioFormat format) {
/**
* If we like to emulate constraints ..