Audio support for droid. No idea how the latencies are. Probably terrible.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3903 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
7ef66ea01a
commit
8d2cc63faf
8 changed files with 90 additions and 10 deletions
|
@ -60,9 +60,17 @@ ifeq ($(FTE_TARGET),droid)
|
||||||
NDK_PATH:=$(shell echo $(DROID_NDK_PATH))
|
NDK_PATH:=$(shell echo $(DROID_NDK_PATH))
|
||||||
SDK_PATH:=$(shell echo $(DROID_SDK_PATH))
|
SDK_PATH:=$(shell echo $(DROID_SDK_PATH))
|
||||||
|
|
||||||
|
DROID_API_LEVEL=3
|
||||||
|
|
||||||
|
#there are 3 ABI targets
|
||||||
|
#armv5 (works on all arm droids)
|
||||||
|
#armv7 (more common on 2.2+ droids)
|
||||||
|
#armv7+neon
|
||||||
|
DROID_ABI?=-mfloat-abi=softfp
|
||||||
|
|
||||||
STRIP=$(NDK_PATH)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-strip
|
STRIP=$(NDK_PATH)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-strip
|
||||||
CC=$(NDK_PATH)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -I$(NDK_PATH)/platforms/android-8/arch-arm/usr/include/ -DANDROID
|
CC=$(NDK_PATH)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -I$(NDK_PATH)/platforms/android-$(DROID_API_LEVEL)/arch-arm/usr/include/ -DANDROID $(DROID_ABI)
|
||||||
DO_LD=$(CC) -Wl,-soname,libftedroid.so -shared -Wl,--no-undefined -Wl,-z,noexecstack --sysroot=$(NDK_PATH)/platforms/android-8/arch-arm -L$(NDK_PATH)/platforms/android-8/arch-arm/usr/lib -o $@ $(LTO_LD) $(WCFLAGS) $(CFLAGS) -llog -lc -lz -lm
|
DO_LD=$(CC) -Wl,-soname,libftedroid.so -shared -Wl,--no-undefined -Wl,-z,noexecstack --sysroot=$(NDK_PATH)/platforms/android-$(DROID_API_LEVEL)/arch-arm -L$(NDK_PATH)/platforms/android-$(DROID_API_LEVEL)/arch-arm/usr/lib -o $@ $(LTO_LD) $(WCFLAGS) $(CFLAGS) -llog -lc -lz -lm
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#correct the gcc build when cross compiling
|
#correct the gcc build when cross compiling
|
||||||
|
@ -845,7 +853,7 @@ ifeq ($(FTE_TARGET),droid)
|
||||||
|
|
||||||
SV_LDFLAGS=
|
SV_LDFLAGS=
|
||||||
|
|
||||||
GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) gl_viddroid.o sys_droid.o cd_null.o
|
GLCL_OBJS=$(GL_OBJS) $(GLQUAKE_OBJS) gl_viddroid.o sys_droid.o cd_null.o snd_droid.o
|
||||||
GL_LDFLAGS=$(GLLDFLAGS)
|
GL_LDFLAGS=$(GLLDFLAGS)
|
||||||
GLB_DIR=gl_droid
|
GLB_DIR=gl_droid
|
||||||
GL_EXE_NAME=../libftedroid.so
|
GL_EXE_NAME=../libftedroid.so
|
||||||
|
|
|
@ -1737,7 +1737,11 @@ void CL_InitInput (void)
|
||||||
Cmd_AddCommand (vahunk("p%i", sp+1), CL_Split_f);
|
Cmd_AddCommand (vahunk("p%i", sp+1), CL_Split_f);
|
||||||
Cmd_AddCommand (vahunk("+p%i", sp+1), CL_Split_f);
|
Cmd_AddCommand (vahunk("+p%i", sp+1), CL_Split_f);
|
||||||
Cmd_AddCommand (vahunk("-p%i", sp+1), CL_Split_f);
|
Cmd_AddCommand (vahunk("-p%i", sp+1), CL_Split_f);
|
||||||
|
|
||||||
|
/*default mlook to pressed, unless on android where we expect a touch-screen and wouldn't be able to move forwards*/
|
||||||
|
#ifndef ANDROID
|
||||||
in_mlook.state[sp] = 1;
|
in_mlook.state[sp] = 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Cmd_AddCommand ("+moveup", IN_UpDown);
|
Cmd_AddCommand ("+moveup", IN_UpDown);
|
||||||
|
@ -1774,7 +1778,7 @@ void CL_InitInput (void)
|
||||||
Cmd_AddCommand ("+klook", IN_KLookDown);
|
Cmd_AddCommand ("+klook", IN_KLookDown);
|
||||||
Cmd_AddCommand ("-klook", IN_KLookUp);
|
Cmd_AddCommand ("-klook", IN_KLookUp);
|
||||||
Cmd_AddCommand ("+mlook", IN_MLookDown);
|
Cmd_AddCommand ("+mlook", IN_MLookDown);
|
||||||
Cmd_AddCommand ("-mlooks", IN_MLookUp);
|
Cmd_AddCommand ("-mlook", IN_MLookUp);
|
||||||
|
|
||||||
Cmd_AddCommand ("+button3", IN_Button3Down);
|
Cmd_AddCommand ("+button3", IN_Button3Down);
|
||||||
Cmd_AddCommand ("-button3", IN_Button3Up);
|
Cmd_AddCommand ("-button3", IN_Button3Up);
|
||||||
|
|
|
@ -620,6 +620,7 @@ sounddriver pOSS_InitCard;
|
||||||
sounddriver pMacOS_InitCard;
|
sounddriver pMacOS_InitCard;
|
||||||
sounddriver pSDL_InitCard;
|
sounddriver pSDL_InitCard;
|
||||||
sounddriver pWAV_InitCard;
|
sounddriver pWAV_InitCard;
|
||||||
|
sounddriver pDroid_InitCard;
|
||||||
sounddriver pAHI_InitCard;
|
sounddriver pAHI_InitCard;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -632,6 +633,7 @@ sdriver_t drivers[] = {
|
||||||
|
|
||||||
{"DSound", &pDSOUND_InitCard}, //prefered on windows
|
{"DSound", &pDSOUND_InitCard}, //prefered on windows
|
||||||
{"MacOS", &pMacOS_InitCard}, //prefered on mac
|
{"MacOS", &pMacOS_InitCard}, //prefered on mac
|
||||||
|
{"Droid", &pDroid_InitCard}, //prefered on android (java thread)
|
||||||
{"AHI", &pAHI_InitCard}, //prefered on morphos
|
{"AHI", &pAHI_InitCard}, //prefered on morphos
|
||||||
|
|
||||||
{"SDL", &pSDL_InitCard}, //prefered on linux
|
{"SDL", &pSDL_InitCard}, //prefered on linux
|
||||||
|
|
|
@ -46,7 +46,7 @@ JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_init(JNIEnv *env, jobject o
|
||||||
if (!sys_running)
|
if (!sys_running)
|
||||||
{
|
{
|
||||||
quakeparms_t parms;
|
quakeparms_t parms;
|
||||||
parms.basedir = "/sdcard";
|
parms.basedir = "/sdcard/fte";
|
||||||
parms.argc = 0;
|
parms.argc = 0;
|
||||||
parms.argv = NULL;
|
parms.argv = NULL;
|
||||||
parms.memsize = sys_memheap = 8*1024*1024;
|
parms.memsize = sys_memheap = 8*1024*1024;
|
||||||
|
@ -76,8 +76,9 @@ JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_keypress(JNIEnv *env, jobje
|
||||||
Key_Event(0, keycode, unicode, down);
|
Key_Event(0, keycode, unicode, down);
|
||||||
}
|
}
|
||||||
|
|
||||||
float mousecursor_x, mousecursor_y;
|
int mousecursor_x, mousecursor_y;
|
||||||
float mouse_x, mouse_y;
|
float mouse_x, mouse_y;
|
||||||
|
static float omouse_x, omouse_y;
|
||||||
JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_motion(JNIEnv *env, jobject obj,
|
JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_motion(JNIEnv *env, jobject obj,
|
||||||
jint act, jfloat x, jfloat y)
|
jint act, jfloat x, jfloat y)
|
||||||
{
|
{
|
||||||
|
@ -85,8 +86,10 @@ JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_motion(JNIEnv *env, jobject
|
||||||
static qboolean down;
|
static qboolean down;
|
||||||
float dx, dy;
|
float dx, dy;
|
||||||
|
|
||||||
dx = x - mousecursor_x;
|
dx = x - omouse_x;
|
||||||
dy = y - mousecursor_y;
|
dy = y - omouse_y;
|
||||||
|
omouse_x = x;
|
||||||
|
omouse_y = y;
|
||||||
mousecursor_x = x;
|
mousecursor_x = x;
|
||||||
mousecursor_y = y;
|
mousecursor_y = y;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
package="com.fteqw"
|
package="com.fteqw"
|
||||||
android:versionCode="1"
|
android:versionCode="1"
|
||||||
android:versionName="1.0">
|
android:versionName="1.0">
|
||||||
<uses-sdk android:minSdkVersion="8" />
|
<uses-sdk android:minSdkVersion="3" />
|
||||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
||||||
|
|
||||||
|
@ -17,4 +17,4 @@
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -18,6 +18,10 @@ import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
|
|
||||||
|
import android.media.AudioFormat;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.media.AudioTrack;
|
||||||
|
|
||||||
public class FTEDroidActivity extends Activity
|
public class FTEDroidActivity extends Activity
|
||||||
{
|
{
|
||||||
private SensorManager sensorman;
|
private SensorManager sensorman;
|
||||||
|
@ -50,6 +54,56 @@ public class FTEDroidActivity extends Activity
|
||||||
{
|
{
|
||||||
private final FTERenderer rndr;
|
private final FTERenderer rndr;
|
||||||
|
|
||||||
|
private byte[] audbuf;
|
||||||
|
private AudioTrack at;
|
||||||
|
|
||||||
|
private void audioInit()
|
||||||
|
{
|
||||||
|
final int notifframes = 2048;
|
||||||
|
if (at != null)
|
||||||
|
at.stop();
|
||||||
|
int sspeed = 11025;
|
||||||
|
int speakers = 1;
|
||||||
|
int sz = 4*AudioTrack.getMinBufferSize(sspeed, ((speakers==2)?AudioFormat.CHANNEL_CONFIGURATION_STEREO:AudioFormat.CHANNEL_CONFIGURATION_MONO), AudioFormat.ENCODING_PCM_16BIT);
|
||||||
|
if (sz < notifframes*2)
|
||||||
|
sz = notifframes*2;
|
||||||
|
|
||||||
|
at = new AudioTrack(AudioManager.STREAM_MUSIC, sspeed, ((speakers==2)?AudioFormat.CHANNEL_CONFIGURATION_STEREO:AudioFormat.CHANNEL_CONFIGURATION_MONO), AudioFormat.ENCODING_PCM_16BIT, sz, AudioTrack.MODE_STREAM);
|
||||||
|
final int framesz = 2; /*mono 16bit*/
|
||||||
|
audbuf = new byte[notifframes*framesz];
|
||||||
|
|
||||||
|
at.setPlaybackPositionUpdateListener(new AudioTrack.OnPlaybackPositionUpdateListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onMarkerReached(AudioTrack track)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onPeriodicNotification(AudioTrack track)
|
||||||
|
{
|
||||||
|
int avail = FTEDroidEngine.paintaudio(audbuf, audbuf.length);
|
||||||
|
at.write(audbuf, 0, notifframes*framesz);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
at.setPositionNotificationPeriod(notifframes);
|
||||||
|
|
||||||
|
at.setStereoVolume(1, 1);
|
||||||
|
|
||||||
|
at.play();
|
||||||
|
/*buffer needs to be completely full before it'll start playing*/
|
||||||
|
while(sz > 0)
|
||||||
|
{
|
||||||
|
at.write(audbuf, 0, notifframes*framesz);
|
||||||
|
sz -= notifframes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void resume()
|
||||||
|
{
|
||||||
|
/*poke audio into submission*/
|
||||||
|
if (at != null)
|
||||||
|
at.play();
|
||||||
|
}
|
||||||
|
|
||||||
public FTEView(Context context)
|
public FTEView(Context context)
|
||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -58,6 +112,8 @@ public class FTEDroidActivity extends Activity
|
||||||
setRenderer(rndr);
|
setRenderer(rndr);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
setFocusableInTouchMode(true);
|
setFocusableInTouchMode(true);
|
||||||
|
|
||||||
|
audioInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendKey(final boolean presseddown, final int qcode, final int unicode)
|
private void sendKey(final boolean presseddown, final int qcode, final int unicode)
|
||||||
|
@ -208,6 +264,8 @@ public class FTEDroidActivity extends Activity
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
sensorman.registerListener((SensorEventListener)view, sensoracc, SensorManager.SENSOR_DELAY_GAME);
|
sensorman.registerListener((SensorEventListener)view, sensoracc, SensorManager.SENSOR_DELAY_GAME);
|
||||||
|
|
||||||
|
view.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,6 +7,8 @@ public class FTEDroidEngine
|
||||||
public static native void keypress(int down, int qkey, int unicode);
|
public static native void keypress(int down, int qkey, int unicode);
|
||||||
public static native void motion(int act, float x, float y);
|
public static native void motion(int act, float x, float y);
|
||||||
public static native void accelerometer(float x, float y, float z);
|
public static native void accelerometer(float x, float y, float z);
|
||||||
|
public static native int paintaudio(byte[] stream, int len);
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
System.loadLibrary("ftedroid");
|
System.loadLibrary("ftedroid");
|
||||||
|
|
|
@ -48,6 +48,9 @@ void ClearBounds (vec3_t mins, vec3_t maxs);
|
||||||
#if defined(ANDROID) /*FIXME: actually just to use standard GLES headers instead of full GL*/
|
#if defined(ANDROID) /*FIXME: actually just to use standard GLES headers instead of full GL*/
|
||||||
#if 1
|
#if 1
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
|
#ifndef GL_CLIP_PLANE0
|
||||||
|
#define GL_CLIP_PLANE0 0x3000
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <GLES2/gl2.h>
|
#include <GLES2/gl2.h>
|
||||||
/*gles has no fixed function*/
|
/*gles has no fixed function*/
|
||||||
|
|
Loading…
Reference in a new issue