Update the Android support once again. (#2)

Co-authored-by: Nikita Krapivin <alienoom@yandex.ru>
Reviewed-on: MoonsideGames/FAudioGMS#2
Co-authored-by: Nikita Krapivin <nik@noreply.example.org>
Co-committed-by: Nikita Krapivin <nik@noreply.example.org>
Nikita Krapivin 2022-01-10 02:42:58 +00:00 committed by cosmonaut
parent 3b39ed9d10
commit ec2d47ac5b
13 changed files with 178 additions and 41 deletions

View File

@ -94,14 +94,14 @@ Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1StaticSound_1Destroy
JNIEXPORT jdouble JNICALL
Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1StreamingSound_1LoadOGG
(JNIEnv* jniEnv, jclass jniThis, jstring _filepath)
(JNIEnv* jniEnv, jclass jniThis, jstring _filepath, jdouble _bufferSizeInBytes)
{
jboolean isCopy;
const char* filepath;
jdouble ret;
filepath = (*jniEnv)->GetStringUTFChars(jniEnv, _filepath, &isCopy);
ret = FAudioGMS_StreamingSound_LoadOGG((char *)filepath);
ret = FAudioGMS_StreamingSound_LoadOGG((char *)filepath, _bufferSizeInBytes);
(*jniEnv)->ReleaseStringUTFChars(jniEnv, _filepath, filepath);
return ret;
}
@ -130,6 +130,22 @@ Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1SoundInstance_1Stop
return NOTHING;
}
JNIEXPORT jdouble JNICALL
Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1SoundInstance_1QueueSyncPlay
(JNIEnv* jniEnv, jclass jniThis, jdouble _soundInstanceID)
{
FAudioGMS_SoundInstance_QueueSyncPlay(_soundInstanceID);
return NOTHING;
}
JNIEXPORT jdouble JNICALL
Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1SoundInstance_1SyncPlay
(JNIEnv* jniEnv, jclass jniThis)
{
FAudioGMS_SoundInstance_SyncPlay();
return NOTHING;
}
JNIEXPORT jdouble JNICALL
Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1SoundInstance_1SetPlayRegion
(JNIEnv* jniEnv, jclass jniThis, jdouble _soundInstanceID, jdouble _startInMilliseconds, jdouble _endInMilliseconds)
@ -186,6 +202,14 @@ Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1SoundInstance_1Set3DVelo
return NOTHING;
}
JNIEXPORT jdouble JNICALL
Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1SoundInstance_1Set3DOrientation
(JNIEnv* jniEnv, jclass jniThis, jdouble _soundInstanceID, jdouble _xFront, jdouble _yFront, jdouble _zFront, jdouble _xTop, jdouble _yTop, jdouble _zTop)
{
FAudioGMS_SoundInstance_Set3DOrientation(_soundInstanceID, _xFront, _yFront, _zFront, _xTop, _yTop, _zTop);
return NOTHING;
}
JNIEXPORT jdouble JNICALL
Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1SoundInstance_1SetTrackPositionInSeconds
(JNIEnv* jniEnv, jclass jniThis, jdouble _soundInstanceID, jdouble _trackPositionInSeconds)
@ -327,8 +351,7 @@ Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1EffectChain_1AddReverb
_reverbGain,
_decayTime,
_density,
_roomSize
);
_roomSize);
return NOTHING;
}
@ -388,6 +411,14 @@ Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1SetListenerVelocity
return NOTHING;
}
JNIEXPORT jdouble JNICALL
Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1SetListenerOrientation
(JNIEnv* jniEnv, jclass jniThis, jdouble _xFront, jdouble _yFront, jdouble _zFront, jdouble _xTop, jdouble _yTop, jdouble _zTop)
{
FAudioGMS_SetListenerOrientation(_xFront, _yFront, _zFront, _xTop, _yTop, _zTop);
return NOTHING;
}
JNIEXPORT jdouble JNICALL
Java_org_screwyoyo_faudiogms_FAudioGMSNative_FAudioGMS_1PauseAll
(JNIEnv* jniEnv, jclass jniThis)

View File

@ -12,30 +12,73 @@ public class FAudioGMSNative
/* exactly as in FAudioGMS_JNI.c: */
public native double FAudioGMS_Init(double spatialDistanceScale, double timestep);
public native double FAudioGMS_StaticSound_LoadWAV(String filePath);
public native double FAudioGMS_StaticSound_CreateSoundInstance(double staticSoundID);
public native double FAudioGMS_StaticSound_LoadWAV(
String filePath); /* returns a static sound ID */
public native double FAudioGMS_StaticSound_CreateSoundInstance(
double staticSoundID); /* returns a sound instance ID */
public native double FAudioGMS_StaticSound_Destroy(double staticSoundID);
public native double FAudioGMS_StreamingSound_LoadOGG(String filepath);
/* returns a sound instance ID */
public native double FAudioGMS_StreamingSound_LoadOGG(
String filepath,
double bufferSizeInBytes); /* if 0 is passed we will use a sensible default*/
public native double FAudioGMS_SoundInstance_Play(double soundInstanceID);
public native double FAudioGMS_SoundInstance_Pause(double soundInstanceID);
public native double FAudioGMS_SoundInstance_Stop(double soundInstanceID);
public native double FAudioGMS_SoundInstance_SetPlayRegion(double soundInstanceID, double startInMilliseconds, double endInMilliseconds);
public native double FAudioGMS_SoundInstance_QueueSyncPlay(double soundInstanceID);
public native double FAudioGMS_SoundInstance_SyncPlay();
public native double FAudioGMS_SoundInstance_SetPlayRegion(
double soundInstanceID,
double startInMilliseconds,
double endInMilliseconds);
public native double FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop);
public native double FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan);
public native double FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch);
public native double FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume);
public native double FAudioGMS_SoundInstance_Set3DPosition(double soundInstanceID, double x, double y, double z);
public native double FAudioGMS_SoundInstance_Set3DVelocity(double soundInstanceID, double xVelocity, double yVelocity, double zVelocity);
public native double FAudioGMS_SoundInstance_SetTrackPositionInSeconds(double soundInstanceID, double trackPositionInSeconds);
public native double FAudioGMS_SoundInstance_SetVolumeOverTime(double soundInstanceID, double volume, double milliseconds);
public native double FAudioGMS_SoundInstance_SetLowPassFilter(double soundInstanceID, double lowPassFilter, double Q);
public native double FAudioGMS_SoundInstance_SetHighPassFilter(double soundInstanceID, double highPassFilter, double Q);
public native double FAudioGMS_SoundInstance_SetBandPassFilter(double soundInstanceID, double bandPassFilter, double Q);
public native double FAudioGMS_SoundInstance_Set3DPosition(
double soundInstanceID,
double x,
double y,
double z);
public native double FAudioGMS_SoundInstance_Set3DVelocity(
double soundInstanceID,
double xVelocity,
double yVelocity,
double zVelocity);
public native double FAudioGMS_SoundInstance_Set3DOrientation(
double soundInstanceID,
double xFront,
double yFront,
double zFront,
double xTop,
double yTop,
double zTop);
public native double FAudioGMS_SoundInstance_SetTrackPositionInSeconds(
double soundInstanceID,
double trackPositionInSeconds);
public native double FAudioGMS_SoundInstance_SetVolumeOverTime(
double soundInstanceID,
double volume,
double milliseconds);
public native double FAudioGMS_SoundInstance_SetLowPassFilter(
double soundInstanceID,
double lowPassFilter,
double Q);
public native double FAudioGMS_SoundInstance_SetHighPassFilter(
double soundInstanceID,
double highPassFilter,
double Q);
public native double FAudioGMS_SoundInstance_SetBandPassFilter(
double soundInstanceID,
double bandPassFilter,
double Q);
public native double FAudioGMS_SoundInstance_QueueSoundInstance(double soundInstanceID, double queueSoundInstanceID);
public native double FAudioGMS_SoundInstance_QueueSoundInstance(
double soundInstanceID,
double queueSoundInstanceID);
public native double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID);
public native double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID);
@ -62,25 +105,41 @@ public class FAudioGMSNative
double reverbGain,
double decayTime,
double density,
double roomSize
);
double roomSize);
public native double FAudioGMS_EffectChain_Destroy(double effectChainID);
/*
* NOTE: Any changes to the effect chain will NOT apply after this is set!
* You MUST call SetEffectChain again if you make changes to the effect chain parameters!
* You MUST call SetEffectChain again if you make changes to the effect
* chain parameters!
*/
public native double FAudioGMS_SoundInstance_SetEffectChain(double soundInstanceID, double effectChainID, double effectGain);
public native double FAudioGMS_SoundInstance_SetEffectGain(double soundInstanceID, double effectGain);
public native double FAudioGMS_SoundInstance_SetEffectChain(
double soundInstanceID,
double effectChainID,
double effectGain);
public native double FAudioGMS_SoundInstance_SetEffectGain(
double soundInstanceID,
double effectGain);
public native double FAudioGMS_SetMasteringEffectChain(double effectChainID, double effectGain);
public native double FAudioGMS_SetMasteringEffectGain(double effectGain);
public native double FAudioGMS_SetListenerPosition(double x, double y, double z);
public native double FAudioGMS_SetListenerVelocity(double xVelocity, double yVelocity, double zVelocity);
public native double FAudioGMS_SetListenerVelocity(
double xVelocity,
double yVelocity,
double zVelocity);
public native double FAudioGMS_SetListenerOrientation(
double xFront,
double yFront,
double zFront,
double xTop,
double yTop,
double zTop);
public native double FAudioGMS_PauseAll(); /* mobile platforms, man... */
public native double FAudioGMS_ResumeAll(); /* same thing here */
public native double FAudioGMS_PauseAll(); /* useful for mobile platforms, etc
*/
public native double FAudioGMS_ResumeAll(); /* same as above */
public native double FAudioGMS_StopAll();
public native double FAudioGMS_Update();

Binary file not shown.

View File

@ -190,8 +190,7 @@
2,
2,
],"resourceVersion":"1.0","name":"FAudioGMS_SoundInstance_Set3DOrientation","tags":[],"resourceType":"GMExtensionFunction",},
{"externalName":"FAudioGMS_SetListenerOrientation","kind":1,"help":"FAudioGMS_SetListenerOrientation(soundInstanceID, xFront, yFront, zFront, xTop, yTop, zTop)","hidden":false,"returnType":2,"argCount":0,"args":[
2,
{"externalName":"FAudioGMS_SetListenerOrientation","kind":1,"help":"FAudioGMS_SetListenerOrientation(xFront, yFront, zFront, xTop, yTop, zTop)","hidden":false,"returnType":2,"argCount":0,"args":[
2,
2,
2,

View File

@ -1 +1,17 @@
/// @description Clean up all resources when the game is about to end.
/* Destroy sound instances first: */
// sndInst.Stop();
// sndInst.Destroy();
// sndInst = undefined;
/* Only then destroy static sounds: */
// snd.Destroy();
// snd = undefined;
/* And only then, destroy effect chains */
effChain.Destroy();
effChain = undefined;
/* Finish up the system */
FAudioGMS_Destroy();

View File

@ -1,6 +1,15 @@
/// @description Initialize audio.
/* First initialize the system: */
var spatialDistanceScale = 50; // makes "3D" audio louder
FAudioGMS_Init(spatialDistanceScale, 1 / 60);
var timestep = game_get_speed(gamespeed_microseconds) / 1000000; // default, autodetect from GM timestep.
FAudioGMS_Init(spatialDistanceScale, timestep);
/* Init Effects Chains Here */
effChain = new EffectChain();
effChain.AddDefaultReverb();
/* Load Audio Assets Here */
// snd = LoadStaticSound("go-go-go-tigerblood.wav");
// sndInst = snd.Play();
// sndInst.SetEffectChain(effChain, 1); // apply default reverb to the instance.

View File

@ -1 +1,2 @@
/// @description MUST be called once per frame!
FAudioGMS_Update();

View File

@ -88,10 +88,10 @@ function StaticSound(_staticSoundID) constructor
// The audio is streamed off the disk, so only a small amount of memory is used at a time.
// Good for things like music or voiceover playback.
// Note that StreamingSounds are SoundInstances.
function LoadStreamingSound(filename)
function LoadStreamingSound(filename, bufferSizeInBytes = 0)
{
var filePath = GetPathPrepend() + "audio/streaming/" + filename;
soundInstanceID = FAudioGMS_StreamingSound_LoadOGG(filePath);
soundInstanceID = FAudioGMS_StreamingSound_LoadOGG(filePath, bufferSizeInBytes);
return new SoundInstance(soundInstanceID);
}
@ -129,6 +129,12 @@ function SoundInstance(_soundInstanceID) constructor
FAudioGMS_SoundInstance_Set3DVelocity(soundInstanceID, xVelocity, yVelocity, zVelocity);
}
// Sets the 3-dimensional orientation of the sound.
static Set3DOrientation = function(xFront, yFront, zFront, xTop, yTop, zTop)
{
FAudioGMS_SoundInstance_Set3DOrientation(soundInstanceID, xFront, yFront, zFront, xTop, yTop, zTop);
}
// Sets whether the sound instance loops (true) or does not (false).
static SetLoop = function(loop)
{
@ -168,6 +174,12 @@ function SoundInstance(_soundInstanceID) constructor
FAudioGMS_SoundInstance_SetTrackPositionInSeconds(soundInstanceID, seconds);
}
// Queues this sound instance for playing in sync.
static QueueSyncPlay = function()
{
FAudioGMS_SoundInstance_QueueSyncPlay(soundInstanceID);
}
// Sets the playback region for the sound instance.
static SetPlayRegion = function(loopStartInMilliseconds, loopEndInMilliseconds)
{
@ -216,7 +228,7 @@ function SoundInstance(_soundInstanceID) constructor
static QueueSoundInstance = function(queueSoundInstance)
{
FAudioGMS_SoundInstance_QueueSoundInstance(soundInstanceID, queueSoundInstance.soundInstanceID);
FAudioGMS_SoundInstance_QueueSoundInstance(soundInstanceID, queueSoundInstance.soundInstanceID);
}
// Gets the pitch of the sound.
@ -263,6 +275,12 @@ function SoundInstance(_soundInstanceID) constructor
SetVolume(1);
}
// Plays the sound instance queue.
function SyncPlay()
{
FAudioGMS_SoundInstance_SyncPlay();
}
// Effect chains allow you to modify sound playback using audio effects.
// Right now only reverb is implemented, but more effects will probably come later.
function EffectChain() constructor
@ -348,6 +366,12 @@ function SetListenerVelocity(xVelocity, yVelocity, zVelocity)
FAudioGMS_SetListenerVelocity(xVelocity, yVelocity, zVelocity);
}
// Sets the orientation of the listener for 3D audio.
function SetListenerOrientation(xFront, yFront, zFront, xTop, yTop, zTop)
{
FAudioGMS_SetListenerOrientation(xFront, yFront, zFront, xTop, yTop, zTop);
}
// Stops all audio playback.
function StopAllAudio()
{

View File

@ -1664,7 +1664,6 @@ void FAudioGMS_SetListenerVelocity(double xVelocity, double yVelocity, double zV
}
void FAudioGMS_SetListenerOrientation(
double soundInstanceID,
double xFront,
double yFront,
double zFront,

View File

@ -160,7 +160,6 @@ extern "C"
double yVelocity,
double zVelocity);
FAUDIOGMSAPI void FAudioGMS_SetListenerOrientation(
double soundInstanceID,
double xFront,
double yFront,
double zFront,