Converted all libs from shared to static - it will allow closed-source apps to use LGPL-ed libsdl,

and will solve some cross-referencing problems, like SDL_init called from static constructors.
This commit is contained in:
pelya
2010-05-06 18:46:42 +03:00
parent bd017bb179
commit 24dce42157
93 changed files with 165 additions and 825 deletions

View File

@@ -1,2 +1,2 @@
APP_PROJECT_PATH := $(call my-dir)/project
APP_MODULES := stlport sdl alienblaster sdl_mixer tremor
APP_MODULES := application stlport sdl sdl_mixer tremor

View File

@@ -14,6 +14,6 @@ SDL_CURDIR_PATH := /data/data/de.schwardtnet.alienblaster/files
# this will make Up/Down/Left/Right key up events with X frames delay,
# so if application expects you to press and hold button it will process the event correctly.
# TODO: create a libsdl config file for that option and for key mapping/on-screen keyboard
SDL_TRACKBALL_KEYUP_DELAY := 4
SDL_TRACKBALL_KEYUP_DELAY := 0
include $(call all-subdir-makefiles)

View File

@@ -1,29 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := alienblaster
CG_SUBDIRS := \
src \
# Add more subdirs here, like src/subdir1 src/subdir2
LOCAL_CFLAGS := $(foreach D, $(CG_SUBDIRS), -I$(CG_SRCDIR)/$(D)) \
-I$(LOCAL_PATH)/../sdl/include \
-I$(LOCAL_PATH)/../sdl_mixer \
-I$(LOCAL_PATH)/../stlport/stlport \
#Change C++ file extension as appropriate
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := $(foreach F, $(CG_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.cc))))
# Uncomment to also add C sources
LOCAL_SRC_FILES += $(foreach F, $(CG_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.c))))
LOCAL_STATIC_LIBRARIES := sdl_mixer sdl tremor stlport
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
include $(BUILD_SHARED_LIBRARY)

View File

@@ -0,0 +1,31 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := application
APP_SUBDIRS := $(patsubst $(LOCAL_PATH)/%, %, $(shell find $(LOCAL_PATH)/src -type d))
# Add more subdirs here, like src/subdir1 src/subdir2
LOCAL_CFLAGS := -DSDL_JAVA_PACKAGE_PATH=$(SDL_JAVA_PACKAGE_PATH) \
-DSDL_CURDIR_PATH=\"$(SDL_CURDIR_PATH)\" \
$(foreach D, $(APP_SUBDIRS), -I$(LOCAL_PATH)/$(D)) \
-I$(LOCAL_PATH)/../sdl/include \
-I$(LOCAL_PATH)/../sdl_mixer \
-I$(LOCAL_PATH)/../stlport/stlport \
#Change C++ file extension as appropriate
LOCAL_CPP_EXTENSION := .cpp
LOCAL_SRC_FILES := $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.cpp))))
# Uncomment to also add C sources
LOCAL_SRC_FILES += $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.c))))
LOCAL_SHARED_LIBRARIES := sdl sdl_mixer tremor stlport
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
include $(BUILD_SHARED_LIBRARY)

View File

@@ -17,6 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
***************************************************************************/
#include "SDL_main.h"
#include "game.h"
#include "SDL.h"
#include <stdlib.h>

View File

@@ -41,5 +41,5 @@ LOCAL_SRC_FILES := $(foreach F, $(SDL_SRCS), $(addprefix $(dir $(F)),$(notdir $(
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
include $(BUILD_STATIC_LIBRARY)
include $(BUILD_SHARED_LIBRARY)

View File

@@ -27,7 +27,9 @@
#ifndef _SDL_H
#define _SDL_H
#ifndef ANDROID
#include "SDL_main.h"
#endif
#include "SDL_stdinc.h"
#include "SDL_audio.h"
#include "SDL_cdrom.h"

View File

@@ -29,8 +29,7 @@
#include <stdarg.h>
#include <stdint.h>
#include <string.h> // for memmove etc
#include <strings.h> // for bcopy etc
#include <sys/mman.h>
#define SDL_AUDIO_DRIVER_ANDROID 1
@@ -52,19 +51,81 @@
#define NO_SDL_GLEXT 1
/* FireSlash found that SDL native memcpy crashes sometimes, these defines fix it (and they are faster) */
#define HAVE_LIBC 1
#define HAVE_ALLOCA_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_STDIO_H 1
#define STDC_HEADERS 1
#define HAVE_STDLIB_H 1
#define HAVE_STDARG_H 1
#define HAVE_MALLOC_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STRING_H 1
#define HAVE_STRINGS_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_CTYPE_H 1
#define HAVE_MATH_H 1
#undef HAVE_ICONV_H
#define HAVE_SIGNAL_H 1
#undef HAVE_ALTIVEC_H
#define HAVE_MALLOC 1
#define HAVE_CALLOC 1
#define HAVE_REALLOC 1
#define HAVE_FREE 1
#define HAVE_ALLOCA 1
#define HAVE_GETENV 1
#define HAVE_PUTENV 1
#define HAVE_UNSETENV 1
#define HAVE_QSORT 1
#define HAVE_ABS 1
#define HAVE_BCOPY 1
#define HAVE_MEMSET 1
#define HAVE_MEMCPY 1
#define HAVE_MEMMOVE 1
#define HAVE_BCOPY 1
#define HAVE_MEMCMP 1
#define HAVE_STRLEN 1
#define HAVE_STRLCPY 1
#define HAVE_STRLCAT 1
#define HAVE_STRDUP 1
#undef HAVE__STRREV
#undef HAVE__STRUPR
#undef HAVE__STRLWR
#define HAVE_INDEX 1
#define HAVE_RINDEX 1
#define HAVE_STRCHR 1
#define HAVE_STRRCHR 1
#define HAVE_STRSTR 1
#undef HAVE_ITOA
#undef HAVE__LTOA
#undef HAVE__UITOA
#undef HAVE__ULTOA
#define HAVE_STRTOL
#define HAVE_STRTOUL
#undef HAVE__I64TOA
#undef HAVE__UI64TOA
#define HAVE_STRTOLL 1
#define HAVE_STRTOULL 1
#define HAVE_STRTOD 1
#define HAVE_ATOI 1
#define HAVE_ATOF 1
#define HAVE_STRCMP 1
#define HAVE_STRNCMP 1
#undef HAVE__STRICMP
#define HAVE_STRCASECMP 1
#undef HAVE__STRNICMP
#define HAVE_STRNCASECMP 1
#define HAVE_SSCANF 1
#define HAVE_SNPRINTF 1
#define HAVE_VSNPRINTF 1
#undef HAVE_ICONV
#define HAVE_SIGACTION 1
#define HAVE_SETJMP 1
#define HAVE_NANOSLEEP 1
#define HAVE_CLOCK_GETTIME 1
#define HAVE_GETPAGESIZE 1
#define HAVE_MPROTECT 1
#endif /* _SDL_config_minimal_h */

View File

@@ -103,4 +103,51 @@ extern DECLSPEC void SDLCALL SDL_InitQuickDraw(struct QDGlobals *the_qd);
#endif /* Need to redefine main()? */
#ifdef ANDROID
#include <unistd.h>
#include <jni.h>
#include "SDL_thread.h"
/* JNI-C wrapper stuff */
#ifdef __cplusplus
#define C_LINKAGE "C"
#else
#define C_LINKAGE
#endif
extern C_LINKAGE int main( int argc, char ** argv );
static int SDLCALL MainThreadWrapper(void * dummy)
{
int argc = 1;
char * argv[] = { "sdl" };
chdir(SDL_CURDIR_PATH);
return main( argc, argv );
};
#ifndef SDL_JAVA_PACKAGE_PATH
#error You have to define SDL_JAVA_PACKAGE_PATH to your package path with dots replaced with underscores, for example "com_example_SanAngeles"
#endif
#define JAVA_EXPORT_NAME2(name,package) Java_##package##_##name
#define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package)
#define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH)
extern C_LINKAGE SDL_Thread * SDL_mainThread;
extern C_LINKAGE void
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz )
{
SDL_mainThread = SDL_CreateThread( MainThreadWrapper, NULL );
}
#undef JAVA_EXPORT_NAME
#undef JAVA_EXPORT_NAME1
#undef JAVA_EXPORT_NAME2
#undef C_LINKAGE
#endif
#endif /* _SDL_main_h */

View File

@@ -103,7 +103,8 @@ static void * memBuffer1 = NULL;
static void * memBuffer2 = NULL;
static void * memBuffer = NULL;
// We have one Java thread drawing on GL surface, and another native C thread (typically main()) feeding it with video data
static SDL_Thread * mainThread = NULL;
extern SDL_Thread * SDL_mainThread;
SDL_Thread * SDL_mainThread = NULL;
// Some wicked multithreading
static SDL_mutex * WaitForNativeRender = NULL;
static SDL_cond * WaitForNativeRender1 = NULL;
@@ -411,15 +412,6 @@ int ANDROID_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
/* JNI-C++ wrapper stuff */
extern int main( int argc, char ** argv );
static int SDLCALL MainThreadWrapper(void * dummy)
{
int argc = 1;
char * argv[] = { "sdl" };
chdir(SDL_CURDIR_PATH);
return main( argc, argv );
};
#ifndef SDL_JAVA_PACKAGE_PATH
#error You have to define SDL_JAVA_PACKAGE_PATH to your package path with dots replaced with underscores, for example "com_example_SanAngeles"
#endif
@@ -427,12 +419,6 @@ static int SDLCALL MainThreadWrapper(void * dummy)
#define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package)
#define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH)
extern void
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz )
{
mainThread = SDL_CreateThread( MainThreadWrapper, NULL );
}
extern void
JAVA_EXPORT_NAME(DemoRenderer_nativeResize) ( JNIEnv* env, jobject thiz, jint w, jint h )
{
@@ -445,12 +431,12 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeResize) ( JNIEnv* env, jobject thiz, jint
extern void
JAVA_EXPORT_NAME(DemoRenderer_nativeDone) ( JNIEnv* env, jobject thiz )
{
if( mainThread )
if( SDL_mainThread )
{
__android_log_print(ANDROID_LOG_INFO, "libSDL", "quitting...");
SDL_PrivateQuit();
SDL_WaitThread(mainThread, NULL);
mainThread = NULL;
SDL_WaitThread(SDL_mainThread, NULL);
SDL_mainThread = NULL;
__android_log_print(ANDROID_LOG_INFO, "libSDL", "quit OK");
}
}

View File

@@ -12,5 +12,7 @@ LOCAL_CPP_EXTENSION := .cpp
# Note this simple makefile var substitution, you can find even simpler examples in different Android projects
LOCAL_SRC_FILES := $(notdir $(wildcard $(LOCAL_PATH)/*.c))
include $(BUILD_STATIC_LIBRARY)
LOCAL_SHARED_LIBRARIES := sdl tremor
include $(BUILD_SHARED_LIBRARY)

View File

@@ -1,229 +0,0 @@
/*
PLAYMUS: A test application for the SDL mixer library.
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
/* $Id: playmus.c 4211 2008-12-08 00:27:32Z slouken $ */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#ifdef unix
#include <unistd.h>
#endif
#include "SDL.h"
#include "SDL_mixer.h"
static int audio_open = 0;
static Mix_Music *music = NULL;
static int next_track = 0;
void CleanUp(int exitcode)
{
if( Mix_PlayingMusic() ) {
Mix_FadeOutMusic(1500);
SDL_Delay(1500);
}
if ( music ) {
Mix_FreeMusic(music);
music = NULL;
}
if ( audio_open ) {
Mix_CloseAudio();
audio_open = 0;
}
SDL_Quit();
exit(exitcode);
}
void Usage(char *argv0)
{
fprintf(stderr, "Usage: %s [-i] [-l] [-8] [-r rate] [-c channels] [-b buffers] [-v N] [-rwops] <musicfile>\n", argv0);
}
void Menu(void)
{
char buf[10];
printf("Available commands: (p)ause (r)esume (h)alt volume(v#) > ");
fflush(stdin);
scanf("%s",buf);
switch(buf[0]){
case 'p': case 'P':
Mix_PauseMusic();
break;
case 'r': case 'R':
Mix_ResumeMusic();
break;
case 'h': case 'H':
Mix_HaltMusic();
break;
case 'v': case 'V':
Mix_VolumeMusic(atoi(buf+1));
break;
}
printf("Music playing: %s Paused: %s\n", Mix_PlayingMusic() ? "yes" : "no",
Mix_PausedMusic() ? "yes" : "no");
}
void IntHandler(int sig)
{
switch (sig) {
case SIGINT:
next_track++;
break;
}
}
int main(int argc, char *argv[])
{
SDL_RWops *rwfp;
int audio_rate;
Uint16 audio_format;
int audio_channels;
int audio_buffers;
int audio_volume = MIX_MAX_VOLUME;
int looping = 0;
int interactive = 0;
int rwops = 0;
int i;
/* Initialize variables */
audio_rate = 22050;
audio_format = AUDIO_S16;
audio_channels = 2;
audio_buffers = 4096;
/* Check command line usage */
for ( i=1; argv[i] && (*argv[i] == '-'); ++i ) {
if ( (strcmp(argv[i], "-r") == 0) && argv[i+1] ) {
++i;
audio_rate = atoi(argv[i]);
} else
if ( strcmp(argv[i], "-m") == 0 ) {
audio_channels = 1;
} else
if ( (strcmp(argv[i], "-c") == 0) && argv[i+1] ) {
++i;
audio_channels = atoi(argv[i]);
} else
if ( (strcmp(argv[i], "-b") == 0) && argv[i+1] ) {
++i;
audio_buffers = atoi(argv[i]);
} else
if ( (strcmp(argv[i], "-v") == 0) && argv[i+1] ) {
++i;
audio_volume = atoi(argv[i]);
} else
if ( strcmp(argv[i], "-l") == 0 ) {
looping = -1;
} else
if ( strcmp(argv[i], "-i") == 0 ) {
interactive = 1;
} else
if ( strcmp(argv[i], "-8") == 0 ) {
audio_format = AUDIO_U8;
} else
if ( strcmp(argv[i], "-rwops") == 0 ) {
rwops = 1;
} else {
Usage(argv[0]);
return(1);
}
}
if ( ! argv[i] ) {
Usage(argv[0]);
return(1);
}
/* Initialize the SDL library */
if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
return(255);
}
signal(SIGINT, IntHandler);
signal(SIGTERM, CleanUp);
/* Open the audio device */
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
return(2);
} else {
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
printf("Opened audio at %d Hz %d bit %s (%s), %d bytes audio buffer\n", audio_rate,
(audio_format&0xFF),
(audio_channels > 2) ? "surround" : (audio_channels > 1) ? "stereo" : "mono",
(audio_format&0x1000) ? "BE" : "LE",
audio_buffers );
}
audio_open = 1;
/* Set the music volume */
Mix_VolumeMusic(audio_volume);
/* Set the external music player, if any */
Mix_SetMusicCMD(getenv("MUSIC_CMD"));
while (argv[i]) {
next_track = 0;
/* Load the requested music file */
if ( rwops ) {
rwfp = SDL_RWFromFile(argv[i], "rb");
music = Mix_LoadMUS_RW(rwfp);
} else {
music = Mix_LoadMUS(argv[i]);
}
if ( music == NULL ) {
fprintf(stderr, "Couldn't load %s: %s\n",
argv[i], SDL_GetError());
CleanUp(2);
}
/* Play and then exit */
printf("Playing %s\n", argv[i]);
Mix_FadeInMusic(music,looping,2000);
while ( !next_track && (Mix_PlayingMusic() || Mix_PausedMusic()) ) {
if(interactive)
Menu();
else
SDL_Delay(100);
}
Mix_FreeMusic(music);
if ( rwops ) {
SDL_FreeRW(rwfp);
}
music = NULL;
/* If the user presses Ctrl-C more than once, exit. */
SDL_Delay(500);
if ( next_track > 1 ) break;
i++;
}
CleanUp(0);
/* Not reached, but fixes compiler warnings */
return 0;
}

View File

@@ -1,494 +0,0 @@
/*
PLAYWAVE: A test application for the SDL mixer library.
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
/* $Id: playwave.c 5191 2009-11-05 00:02:50Z slouken $ */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#ifdef unix
#include <unistd.h>
#endif
#include "SDL.h"
#include "SDL_mixer.h"
/*
* rcg06132001 various mixer tests. Define the ones you want.
*/
/*#define TEST_MIX_DECODERS*/
/*#define TEST_MIX_VERSIONS*/
/*#define TEST_MIX_CHANNELFINISHED*/
/*#define TEST_MIX_PANNING*/
/*#define TEST_MIX_DISTANCE*/
/*#define TEST_MIX_POSITION*/
#if (defined TEST_MIX_POSITION)
#if (defined TEST_MIX_PANNING)
#error TEST_MIX_POSITION interferes with TEST_MIX_PANNING.
#endif
#if (defined TEST_MIX_DISTANCE)
#error TEST_MIX_POSITION interferes with TEST_MIX_DISTANCE.
#endif
#endif
/* rcg06192001 for debugging purposes. */
static void output_test_warnings(void)
{
#if (defined TEST_MIX_CHANNELFINISHED)
fprintf(stderr, "Warning: TEST_MIX_CHANNELFINISHED is enabled in this binary...\n");
#endif
#if (defined TEST_MIX_PANNING)
fprintf(stderr, "Warning: TEST_MIX_PANNING is enabled in this binary...\n");
#endif
#if (defined TEST_MIX_VERSIONS)
fprintf(stderr, "Warning: TEST_MIX_VERSIONS is enabled in this binary...\n");
#endif
#if (defined TEST_MIX_DISTANCE)
fprintf(stderr, "Warning: TEST_MIX_DISTANCE is enabled in this binary...\n");
#endif
#if (defined TEST_MIX_POSITION)
fprintf(stderr, "Warning: TEST_MIX_POSITION is enabled in this binary...\n");
#endif
}
static int audio_open = 0;
static Mix_Chunk *wave = NULL;
/* rcg06042009 Report available decoders. */
#if (defined TEST_MIX_DECODERS)
static void report_decoders(void)
{
int i, total;
printf("Supported decoders...\n");
total = Mix_GetNumChunkDecoders();
for (i = 0; i < total; i++) {
fprintf(stderr, " - chunk decoder: %s\n", Mix_GetChunkDecoder(i));
}
total = Mix_GetNumMusicDecoders();
for (i = 0; i < total; i++) {
fprintf(stderr, " - music decoder: %s\n", Mix_GetMusicDecoder(i));
}
}
#endif
/* rcg06192001 Check new Mixer version API. */
#if (defined TEST_MIX_VERSIONS)
static void output_versions(const char *libname, const SDL_version *compiled,
const SDL_version *linked)
{
fprintf(stderr,
"This program was compiled against %s %d.%d.%d,\n"
" and is dynamically linked to %d.%d.%d.\n", libname,
compiled->major, compiled->minor, compiled->patch,
linked->major, linked->minor, linked->patch);
}
static void test_versions(void)
{
SDL_version compiled;
const SDL_version *linked;
SDL_VERSION(&compiled);
linked = SDL_Linked_Version();
output_versions("SDL", &compiled, linked);
SDL_MIXER_VERSION(&compiled);
linked = Mix_Linked_Version();
output_versions("SDL_mixer", &compiled, linked);
}
#endif
#ifdef TEST_MIX_CHANNELFINISHED /* rcg06072001 */
static volatile int channel_is_done = 0;
static void channel_complete_callback(int chan)
{
Mix_Chunk *done_chunk = Mix_GetChunk(chan);
fprintf(stderr, "We were just alerted that Mixer channel #%d is done.\n", chan);
fprintf(stderr, "Channel's chunk pointer is (%p).\n", done_chunk);
fprintf(stderr, " Which %s correct.\n", (wave == done_chunk) ? "is" : "is NOT");
channel_is_done = 1;
}
#endif
/* rcg06192001 abstract this out for testing purposes. */
static int still_playing(void)
{
#ifdef TEST_MIX_CHANNELFINISHED
return(!channel_is_done);
#else
return(Mix_Playing(0));
#endif
}
#if (defined TEST_MIX_PANNING)
static void do_panning_update(void)
{
static Uint8 leftvol = 128;
static Uint8 rightvol = 128;
static Uint8 leftincr = -1;
static Uint8 rightincr = 1;
static int panningok = 1;
static Uint32 next_panning_update = 0;
if ((panningok) && (SDL_GetTicks() >= next_panning_update)) {
panningok = Mix_SetPanning(0, leftvol, rightvol);
if (!panningok) {
fprintf(stderr, "Mix_SetPanning(0, %d, %d) failed!\n",
(int) leftvol, (int) rightvol);
fprintf(stderr, "Reason: [%s].\n", Mix_GetError());
}
if ((leftvol == 255) || (leftvol == 0)) {
if (leftvol == 255)
printf("All the way in the left speaker.\n");
leftincr *= -1;
}
if ((rightvol == 255) || (rightvol == 0)) {
if (rightvol == 255)
printf("All the way in the right speaker.\n");
rightincr *= -1;
}
leftvol += leftincr;
rightvol += rightincr;
next_panning_update = SDL_GetTicks() + 10;
}
}
#endif
#if (defined TEST_MIX_DISTANCE)
static void do_distance_update(void)
{
static Uint8 distance = 1;
static Uint8 distincr = 1;
static int distanceok = 1;
static Uint32 next_distance_update = 0;
if ((distanceok) && (SDL_GetTicks() >= next_distance_update)) {
distanceok = Mix_SetDistance(0, distance);
if (!distanceok) {
fprintf(stderr, "Mix_SetDistance(0, %d) failed!\n", (int) distance);
fprintf(stderr, "Reason: [%s].\n", Mix_GetError());
}
if (distance == 0) {
printf("Distance at nearest point.\n");
distincr *= -1;
}
else if (distance == 255) {
printf("Distance at furthest point.\n");
distincr *= -1;
}
distance += distincr;
next_distance_update = SDL_GetTicks() + 15;
}
}
#endif
#if (defined TEST_MIX_POSITION)
static void do_position_update(void)
{
static Sint16 distance = 1;
static Sint8 distincr = 1;
static Uint16 angle = 0;
static Sint8 angleincr = 1;
static int positionok = 1;
static Uint32 next_position_update = 0;
if ((positionok) && (SDL_GetTicks() >= next_position_update)) {
positionok = Mix_SetPosition(0, angle, distance);
if (!positionok) {
fprintf(stderr, "Mix_SetPosition(0, %d, %d) failed!\n",
(int) angle, (int) distance);
fprintf(stderr, "Reason: [%s].\n", Mix_GetError());
}
if (angle == 0) {
printf("Due north; now rotating clockwise...\n");
angleincr = 1;
}
else if (angle == 360) {
printf("Due north; now rotating counter-clockwise...\n");
angleincr = -1;
}
distance += distincr;
if (distance < 0) {
distance = 0;
distincr = 3;
printf("Distance is very, very near. Stepping away by threes...\n");
} else if (distance > 255) {
distance = 255;
distincr = -3;
printf("Distance is very, very far. Stepping towards by threes...\n");
}
angle += angleincr;
next_position_update = SDL_GetTicks() + 30;
}
}
#endif
static void CleanUp(int exitcode)
{
if ( wave ) {
Mix_FreeChunk(wave);
wave = NULL;
}
if ( audio_open ) {
Mix_CloseAudio();
audio_open = 0;
}
SDL_Quit();
exit(exitcode);
}
static void Usage(char *argv0)
{
fprintf(stderr, "Usage: %s [-8] [-r rate] [-c channels] [-f] [-F] [-l] [-m] <wavefile>\n", argv0);
}
/*
* rcg06182001 This is sick, but cool.
*
* Actually, it's meant to be an example of how to manipulate a voice
* without having to use the mixer effects API. This is more processing
* up front, but no extra during the mixing process. Also, in a case like
* this, when you need to touch the whole sample at once, it's the only
* option you've got. And, with the effects API, you are altering a copy of
* the original sample for each playback, and thus, your changes aren't
* permanent; here, you've got a reversed sample, and that's that until
* you either reverse it again, or reload it.
*/
static void flip_sample(Mix_Chunk *wave)
{
Uint16 format;
int channels, i, incr;
Uint8 *start = wave->abuf;
Uint8 *end = wave->abuf + wave->alen;
Mix_QuerySpec(NULL, &format, &channels);
incr = (format & 0xFF) * channels;
end -= incr;
switch (incr) {
case 8:
for (i = wave->alen / 2; i >= 0; i -= 1) {
Uint8 tmp = *start;
*start = *end;
*end = tmp;
start++;
end--;
}
break;
case 16:
for (i = wave->alen / 2; i >= 0; i -= 2) {
Uint16 tmp = *start;
*((Uint16 *) start) = *((Uint16 *) end);
*((Uint16 *) end) = tmp;
start += 2;
end -= 2;
}
break;
case 32:
for (i = wave->alen / 2; i >= 0; i -= 4) {
Uint32 tmp = *start;
*((Uint32 *) start) = *((Uint32 *) end);
*((Uint32 *) end) = tmp;
start += 4;
end -= 4;
}
break;
default:
fprintf(stderr, "Unhandled format in sample flipping.\n");
return;
}
}
int main(int argc, char *argv[])
{
int audio_rate;
Uint16 audio_format;
int audio_channels;
int loops = 0;
int i;
int reverse_stereo = 0;
int reverse_sample = 0;
setbuf(stdout, NULL); /* rcg06132001 for debugging purposes. */
setbuf(stderr, NULL); /* rcg06192001 for debugging purposes, too. */
output_test_warnings();
/* Initialize variables */
audio_rate = MIX_DEFAULT_FREQUENCY;
audio_format = MIX_DEFAULT_FORMAT;
audio_channels = 2;
/* Check command line usage */
for ( i=1; argv[i] && (*argv[i] == '-'); ++i ) {
if ( (strcmp(argv[i], "-r") == 0) && argv[i+1] ) {
++i;
audio_rate = atoi(argv[i]);
} else
if ( strcmp(argv[i], "-m") == 0 ) {
audio_channels = 1;
} else
if ( (strcmp(argv[i], "-c") == 0) && argv[i+1] ) {
++i;
audio_channels = atoi(argv[i]);
} else
if ( strcmp(argv[i], "-l") == 0 ) {
loops = -1;
} else
if ( strcmp(argv[i], "-8") == 0 ) {
audio_format = AUDIO_U8;
} else
if ( strcmp(argv[i], "-f") == 0 ) { /* rcg06122001 flip stereo */
reverse_stereo = 1;
} else
if ( strcmp(argv[i], "-F") == 0 ) { /* rcg06172001 flip sample */
reverse_sample = 1;
} else {
Usage(argv[0]);
return(1);
}
}
if ( ! argv[i] ) {
Usage(argv[0]);
return(1);
}
/* Initialize the SDL library */
if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
return(255);
}
signal(SIGINT, CleanUp);
signal(SIGTERM, CleanUp);
/* Open the audio device */
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, 4096) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
CleanUp(2);
} else {
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
printf("Opened audio at %d Hz %d bit %s", audio_rate,
(audio_format&0xFF),
(audio_channels > 2) ? "surround" :
(audio_channels > 1) ? "stereo" : "mono");
if ( loops ) {
printf(" (looping)\n");
} else {
putchar('\n');
}
}
audio_open = 1;
#if (defined TEST_MIX_VERSIONS)
test_versions();
#endif
#if (defined TEST_MIX_DECODERS)
report_decoders();
#endif
/* Load the requested wave file */
wave = Mix_LoadWAV(argv[i]);
if ( wave == NULL ) {
fprintf(stderr, "Couldn't load %s: %s\n",
argv[i], SDL_GetError());
CleanUp(2);
}
if (reverse_sample) {
flip_sample(wave);
}
#ifdef TEST_MIX_CHANNELFINISHED /* rcg06072001 */
Mix_ChannelFinished(channel_complete_callback);
#endif
if ( (!Mix_SetReverseStereo(MIX_CHANNEL_POST, reverse_stereo)) &&
(reverse_stereo) )
{
printf("Failed to set up reverse stereo effect!\n");
printf("Reason: [%s].\n", Mix_GetError());
}
/* Play and then exit */
Mix_PlayChannel(0, wave, loops);
while (still_playing()) {
#if (defined TEST_MIX_PANNING) /* rcg06132001 */
do_panning_update();
#endif
#if (defined TEST_MIX_DISTANCE) /* rcg06192001 */
do_distance_update();
#endif
#if (defined TEST_MIX_POSITION) /* rcg06202001 */
do_position_update();
#endif
SDL_Delay(1);
} /* while still_playing() loop... */
CleanUp(0);
/* Not reached, but fixes compiler warnings */
return 0;
}
/* end of playwave.c ... */

View File

@@ -10,5 +10,5 @@ LOCAL_CPP_EXTENSION := .cpp
LOCAL_SRC_FILES := $(addprefix src/,$(notdir $(wildcard $(LOCAL_PATH)/src/*.cpp $(LOCAL_PATH)/src/*.c))))
include $(BUILD_STATIC_LIBRARY)
include $(BUILD_SHARED_LIBRARY)

View File

@@ -11,5 +11,5 @@ LOCAL_CPP_EXTENSION := .cpp
# Note this simple makefile var substitution, you can find even simpler examples in different Android projects
LOCAL_SRC_FILES := $(notdir $(wildcard $(LOCAL_PATH)/*.c))
include $(BUILD_STATIC_LIBRARY)
include $(BUILD_SHARED_LIBRARY)

View File

@@ -1,44 +1,3 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This is a small port of the "San Angeles Observation" demo
* program for OpenGL ES 1.x. For more details, see:
*
* http://jet.ro/visuals/san-angeles-observation/
*
* This program demonstrates how to use a GLSurfaceView from Java
* along with native OpenGL calls to perform frame rendering.
*
* Touching the screen will start/stop the animation.
*
* Note that the demo runs much faster on the emulator than on
* real devices, this is mainly due to the following facts:
*
* - the demo sends bazillions of polygons to OpenGL without
* even trying to do culling. Most of them are clearly out
* of view.
*
* - on a real device, the GPU bus is the real bottleneck
* that prevent the demo from getting acceptable performance.
*
* - the software OpenGL engine used in the emulator uses
* the system bus instead, and its code rocks :-)
*
* Fixing the program to send less polygons to the GPU is left
* as an exercise to the reader. As always, patches welcomed :-)
*/
package de.schwardtnet.alienblaster;
import javax.microedition.khronos.egl.EGLConfig;
@@ -73,7 +32,7 @@ import java.nio.ByteBuffer;
// TODO: export vibrator to SDL - interface is available in SDL 1.3
class Globals {
public static String ApplicationName = "alienblaster";
public static String ApplicationName = "AlienBlaster";
// Should be zip file
public static String DataDownloadUrl = "http://sites.google.com/site/xpelyax/Home/alienblaster110_data.zip?attredirects=0&d=1";
// Set DownloadToSdcard to true if your app data is bigger than 5 megabytes.
@@ -86,7 +45,11 @@ class Globals {
class LoadLibrary {
public LoadLibrary() {}
static {
System.loadLibrary(Globals.ApplicationName);
System.loadLibrary("stlport");
System.loadLibrary("tremor");
System.loadLibrary("sdl");
System.loadLibrary("sdl_mixer");
System.loadLibrary("application");
}
}

View File

@@ -38,9 +38,8 @@ In the future I'm planning to use accelerometer as a SDL joystick.
Replace all strings "alienblaster" and "de.schwardtnet.alienblaster" with
the name of your application and your reversed webpage address (or any unique string):
Application.mk:2
project/AndroidManifest.xml:3
project/src/DemoActivity.java:42 and 71
project/src/DemoActivity.java:35
project/jni/Android.mk:3 and 10
project/res/values/strings.xml:3
(that's all, maybe I forgot something)