-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate updated MobiVM MetalANGLE backend (#7377)
* Generate MobiVM MetalANGLE backend * feat: Add CHANGES for iOS AudioDevice --------- Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
7c6db62
commit d603706
Showing
9 changed files
with
217 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALConsts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*DO NOT EDIT THIS FILE - it is machine generated*/ | ||
|
||
package com.badlogic.gdx.backends.iosrobovm.objectal; | ||
|
||
/** DO NOT EDIT THIS FILE - it is machine generated */ | ||
public class ALConsts { | ||
|
||
public static int AL_FORMAT_MONO16 = 0x1101; | ||
|
||
public static int AL_FORMAT_STEREO16 = 0x1103; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*DO NOT EDIT THIS FILE - it is machine generated*/ | ||
|
||
package com.badlogic.gdx.backends.iosrobovm.objectal; | ||
|
||
import org.robovm.apple.foundation.NSObject; | ||
import org.robovm.objc.ObjCRuntime; | ||
import org.robovm.objc.annotation.Method; | ||
import org.robovm.objc.annotation.NativeClass; | ||
import org.robovm.rt.bro.annotation.Library; | ||
import org.robovm.rt.bro.ptr.VoidPtr; | ||
|
||
/** DO NOT EDIT THIS FILE - it is machine generated | ||
* @author Jile Gao */ | ||
@Library(Library.INTERNAL) | ||
@NativeClass | ||
public class ALWrapper extends NSObject { | ||
|
||
static { | ||
ObjCRuntime.bind(ALWrapper.class); | ||
} | ||
|
||
@Method(selector = "bufferData:format:data:size:frequency:") | ||
public static native boolean bufferData (int bufferId, int format, VoidPtr data, int size, int frequency); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
...robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALIOSAudioDevice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/*DO NOT EDIT THIS FILE - it is machine generated*/ | ||
|
||
package com.badlogic.gdx.backends.iosrobovm.objectal; | ||
|
||
import com.badlogic.gdx.audio.AudioDevice; | ||
import org.robovm.rt.bro.Struct; | ||
import org.robovm.rt.bro.ptr.ShortPtr; | ||
import org.robovm.rt.bro.ptr.VoidPtr; | ||
import java.nio.ShortBuffer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import static com.badlogic.gdx.backends.iosrobovm.objectal.ALConsts.AL_FORMAT_MONO16; | ||
import static com.badlogic.gdx.backends.iosrobovm.objectal.ALConsts.AL_FORMAT_STEREO16; | ||
|
||
/** DO NOT EDIT THIS FILE - it is machine generated | ||
* @author Jile Gao | ||
* @author Berstanio */ | ||
class OALIOSAudioDevice implements AudioDevice { | ||
|
||
private ALSource alSource; | ||
|
||
private List<ALBuffer> alBuffers = new ArrayList<>(); | ||
|
||
private List<ALBuffer> alBuffersFree = new ArrayList<>(); | ||
|
||
private final int samplingRate; | ||
|
||
private final boolean isMono; | ||
|
||
private final int format; | ||
|
||
private final ShortBuffer tmpBuffer; | ||
|
||
private final int minSize; | ||
|
||
private final int latency; | ||
|
||
OALIOSAudioDevice (int samplingRate, boolean isMono, int minSize, int bufferCount) { | ||
this.samplingRate = samplingRate; | ||
this.isMono = isMono; | ||
this.format = isMono ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; | ||
this.minSize = minSize; | ||
tmpBuffer = ShortBuffer.allocate(minSize); | ||
latency = minSize / (isMono ? 1 : 2) / bufferCount; | ||
alSource = new ALSource(); | ||
for (int i = 0; i < bufferCount; i++) { | ||
ALBuffer buffer = new ALBuffer().initWithNameDataSizeFormatFrequency("test", Struct.allocate(VoidPtr.class, 1), 2, | ||
format, samplingRate); | ||
alBuffersFree.add(buffer); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isMono () { | ||
return isMono; | ||
} | ||
|
||
@Override | ||
public void writeSamples (short[] samples, int offset, int numSamples) { | ||
if (numSamples < 0) throw new IllegalArgumentException("numSamples cannot be < 0."); | ||
ShortPtr shortPtr; | ||
if (numSamples + tmpBuffer.position() >= minSize) { | ||
shortPtr = Struct.allocate(ShortPtr.class, numSamples + tmpBuffer.position()); | ||
shortPtr.set(tmpBuffer.array(), 0, tmpBuffer.position()); | ||
shortPtr.next(tmpBuffer.position()).set(samples, offset, numSamples); | ||
numSamples += tmpBuffer.position(); | ||
tmpBuffer.position(0); | ||
} else { | ||
tmpBuffer.put(samples, offset, numSamples); | ||
return; | ||
} | ||
while (alBuffersFree.isEmpty()) { | ||
if (OALAudioSession.sharedInstance().interrupted()) { | ||
try { | ||
Thread.sleep(2); | ||
} catch (InterruptedException ignored) { | ||
} | ||
return; | ||
} | ||
int toFree = Math.min(alSource.buffersProcessed(), alBuffers.size()); | ||
for (int j = 0; j < toFree; j++) { | ||
ALBuffer alBuffer = alBuffers.get(0); | ||
if (alSource.unqueueBuffer(alBuffer)) { | ||
alBuffersFree.add(alBuffer); | ||
alBuffers.remove(alBuffer); | ||
} else { | ||
break; | ||
} | ||
} | ||
if (alBuffersFree.isEmpty()) { | ||
try { | ||
Thread.sleep(2); | ||
} catch (InterruptedException ignored) { | ||
} | ||
} | ||
} | ||
ALBuffer buffer = alBuffersFree.remove(0); | ||
ALWrapper.bufferData(buffer.bufferId(), format, shortPtr.as(VoidPtr.class), numSamples * 2, samplingRate); | ||
if (alSource.queueBuffer(buffer)) { | ||
alBuffers.add(buffer); | ||
} | ||
if (!alSource.playing()) { | ||
alSource.play(); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeSamples (float[] samples, int offset, int numSamples) { | ||
short[] shortSamples = new short[samples.length]; | ||
for (int i = offset, j = 0; i < samples.length; i++, j++) { | ||
float fValue = samples[i]; | ||
if (fValue > 1) fValue = 1; | ||
if (fValue < -1) fValue = -1; | ||
short value = (short)(fValue * Short.MAX_VALUE); | ||
shortSamples[j] = value; | ||
} | ||
writeSamples(shortSamples, offset, numSamples); | ||
} | ||
|
||
@Override | ||
public int getLatency () { | ||
return latency; | ||
} | ||
|
||
@Override | ||
public void dispose () { | ||
alSource.stop(); | ||
alBuffers = null; | ||
alBuffersFree = null; | ||
alSource = null; | ||
} | ||
|
||
@Override | ||
public void setVolume (float volume) { | ||
alSource.setVolume(volume); | ||
} | ||
|
||
@Override | ||
public void pause () { | ||
alSource.setPaused(true); | ||
} | ||
|
||
@Override | ||
public void resume () { | ||
alSource.setPaused(false); | ||
} | ||
} |