Modifying only ZgeAndroid.pas isn't sufficient.
Here's all the changes we made. I removed the ones on ZzDC.dpr
Those two changes are necessary for threads to work:
In ZgeAndroid.pas :
Code: Select all
uses
cmem,
cthreads,
jni,
ZOpenGL,
ZClasses,
In ZPlatform_Android.pas / function Platform_GetCpuCount:
replace
Code: Select all
RunObj := Env^.CallStaticObjectMethodV(Env, RunClass, Mid, nil);
by
Code: Select all
RunObj := Env^.CallStaticObjectMethod(Env, RunClass, Mid);
But with only those changes, the audio is still crashing.
So here are the changes we made for the audio:
In jni.pas:
Replace
Code: Select all
CallNonvirtualIntMethodV:function(Env:PJNIEnv;Obj:JObject;AClass:JClass;MethodID:JMethodID;Args:va_list):JInt;{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
by
Code: Select all
CallNonvirtualIntMethodV:function(Env:PJNIEnv;Obj:JObject;AClass:JClass;MethodID:JMethodID):JInt;{$ifdef mswindows}stdcall;{$else}cdecl;{$endif} varargs;
In ZPlatform_Android.inc / function AudioCallback
Replace
Code: Select all
{$IFDEF CPU64}
function AudioCallback(Data : pointer) : Int64;
{$ELSE}
function AudioCallback(P : pointer): LongInt;
{$ENDIF}
by
Code: Select all
{$IFDEF CPU64}
function AudioCallback(P: Pointer): Int64;
{$ELSE}
function AudioCallback(P : pointer): LongInt;
{$ENDIF}
replace
by
replace
Code: Select all
function C(const args : array of const) : pointer;
var
I : integer;
begin
for I := 0 to High(args) do
Params[I] := args[I].vinteger;
Result := @Params;
end;
by
Code: Select all
function C(const args : array of const) : PJValue;
var
I : integer;
begin
Fillchar(Params, SizeOf(Params), 0);
for I := 0 to High(args) do
begin
case args[I].VType of
vtInteger: Params[I].i := args[I].VInteger; // Assign integer value
vtPointer: Params[I].l := args[I].VPointer; // Assign pointer value
else
raise Exception.Create('Unsupported argument type');
end;
end;
Result := @Params;
end;
replace
Code: Select all
bufferSizeInBytes := Env^.CallStaticIntMethodV(env, cAudioTrack, mGetMinBufferSize, C([AudioPlayer.AudioRate, 3, 2]));
by
Code: Select all
bufferSizeInBytes := Env^.CallStaticIntMethodA(env, cAudioTrack, mGetMinBufferSize, C([AudioPlayer.AudioRate, 3, 12]));
replace
Code: Select all
track := env^.NewObjectV(env, cAudioTrack, mAudioTrack, C([3, AudioPlayer.AudioRate, 3, 2, bufferSizeInBytes, 1]));
by
Code: Select all
track := env^.NewObjectA(env, cAudioTrack, mAudioTrack, C([3, AudioPlayer.AudioRate, 3, 2, bufferSizeInBytes, 1]));
replace
Code: Select all
MixAndCopyData(PBuffer,OnePassSize);
by
Code: Select all
MixAndCopyData(PBuffer, Min(OnePassSize, bufferSizeInBytes));
replace
Code: Select all
env^.CallNonvirtualIntMethodV(env, track, cAudioTrack, mWrite, C([buffer, 0, OnePassSize]));
by
Code: Select all
env^.CallNonvirtualIntMethodA(env, track, cAudioTrack, mWrite, C([buffer, 0, Min(OnePassSize, bufferSizeInBytes)]));
With all those changes, I fixed the audio from the fresh git code. But should we keep all those changes?
Edit:
I built the 32 bit version of libzgeandroid.so just to be sure it is still working with all those changes. Everything's fine!