Fixed MIDI music in OpenTTD

This commit is contained in:
pelya
2010-11-18 19:45:26 +02:00
parent 79af9388f8
commit 517b630d7c
11 changed files with 114 additions and 50 deletions

2
.gitignore vendored
View File

@@ -8,4 +8,4 @@ project/src
project/res/values*
project/AndroidManifest.xml
project/jni/Settings.mk
libapplication.so

View File

@@ -4,15 +4,15 @@
# export PATH=$PATH:~/src/endless_space/android-ndk-r4b
# Set environment to CrystaX NDK with RTTI and exceptions instead of original NDK
# export PATH=$PATH:~/src/endless_space/android-ndk-r4-crystax/ndk-build
NDKBUILD=ndk-build
NDKBUILDPATH=$PATH
if grep "AppUseCrystaXToolchain=y" AndroidAppSettings.cfg > /dev/null ; then
NDKBUILD=`which ndk-build | sed 's@/[^/]*/ndk-build@/android-ndk-r4-crystax@'`/ndk-build
NDKBUILDPATH=`which ndk-build | sed 's@/[^/]*/ndk-build@/android-ndk-r4-crystax@'`:$PATH
fi
[ -e project/bin/lib ] || ln -s ../libs project/bin/lib
cd project && \
$NDKBUILD -j2 V=1 && \
env PATH=$NDKBUILDPATH ndk-build -j2 V=1 && \
cd bin && \
rm -rf DemoActivity-debug-unaligned.apk && \
cp DemoActivity.ap_ DemoActivity-debug-unaligned.apk && \

View File

@@ -5,7 +5,7 @@ AppName="OpenTTD"
AppFullName=org.openttd.sdl
ScreenOrientation=h
InhibitSuspend=n
AppDataDownloadUrl="Data files size is 19 Mb|http://sites.google.com/site/andgamdev/openttd-1.0.4-data.zip?attredirects=0&d=1^OpenTTD fonts 4MB|http://sites.google.com/site/andgamdev/openttd-1.0.4-fonts-data.zip?attredirects=0&d=1^MIDI music support (18 Mb)|http://sourceforge.net/projects/libsdl-android/files/timidity.zip/download"
AppDataDownloadUrl="Data files - 20 Mb|http://sourceforge.net/projects/libsdl-android/files/OpenTTD/openttd-data-2.zip/download^Localization files and fonts (7 MB)|http://sourceforge.net/projects/libsdl-android/files/OpenTTD/openttd-lang-2.zip/download^MIDI music support (18 Mb)|http://sourceforge.net/projects/libsdl-android/files/timidity.zip/download"
SdlVideoResize=y
SdlVideoResizeKeepAspect=n
NeedDepthBuffer=n
@@ -29,5 +29,5 @@ AppCflags=''
AppLdflags=''
AppSubdirsBuild=''
AppUseCrystaXToolchain=y
AppCmdline=''
AppCmdline='openttd'
ReadmeText='^You may press "Home" now - the data will be downloaded in background'

View File

@@ -1,33 +0,0 @@
diff -ru orig/openttd-1.0.4/src/network/core/os_abstraction.h openttd-1.0.4/src/network/core/os_abstraction.h
--- orig/openttd-1.0.4/src/network/core/os_abstraction.h 2010-05-18 17:49:59.000000000 -0400
+++ openttd-1.0.4/src/network/core/os_abstraction.h 2010-11-13 16:35:45.000000000 -0500
@@ -159,7 +159,7 @@
# include <net/if.h>
/* According to glibc/NEWS, <ifaddrs.h> appeared in glibc-2.3. */
# if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) && !defined(__HAIKU__) && !defined(__INNOTEK_LIBC__) \
- && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX)
+ && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX) && !defined(ANDROID)
/* If for any reason ifaddrs.h does not exist on your system, comment out
* the following two lines and an alternative way will be used to fetch
* the list of IPs from the system. */
diff -ru orig/openttd-1.0.4/src/os/unix/unix.cpp openttd-1.0.4/src/os/unix/unix.cpp
--- orig/openttd-1.0.4/src/os/unix/unix.cpp 2010-05-18 17:44:47.000000000 -0400
+++ openttd-1.0.4/src/os/unix/unix.cpp 2010-11-13 18:06:14.000000000 -0500
@@ -25,7 +25,7 @@
#ifdef __APPLE__
#include <sys/mount.h>
#elif (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__)
- #define HAS_STATVFS
+// #define HAS_STATVFS
#endif
#ifdef HAS_STATVFS
@@ -239,6 +239,8 @@
void cocoaReleaseAutoreleasePool();
#endif
+#include <SDL.h>
+extern "C" int CDECL main(int, char *[]);
int CDECL main(int argc, char *argv[])
{
int ret;

View File

@@ -1,3 +1,67 @@
Index: src/sound/sdl_s.cpp
===================================================================
--- src/sound/sdl_s.cpp (revision 21200)
+++ src/sound/sdl_s.cpp (working copy)
@@ -20,9 +20,16 @@
static FSoundDriver_SDL iFSoundDriver_SDL;
+#ifdef ANDROID
+extern void Android_MidiMixMusic(Sint16 *stream, int len);
+#endif
+
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
{
MxMixSamples(stream, len / 4);
+#ifdef ANDROID
+ Android_MidiMixMusic((Sint16 *)stream, len / 2);
+#endif
}
const char *SoundDriver_SDL::Start(const char * const *parm)
Index: src/music/libtimidity.cpp
===================================================================
--- src/music/libtimidity.cpp (revision 21200)
+++ src/music/libtimidity.cpp (working copy)
@@ -22,10 +22,13 @@
#include <sys/stat.h>
#include <errno.h>
#include <timidity.h>
+#include <SDL.h>
+
#if defined(PSP)
#include <pspaudiolib.h>
#endif /* PSP */
+
enum MidiState {
MIDI_STOPPED = 0,
MIDI_PLAYING = 1,
@@ -50,6 +53,24 @@
}
}
#endif /* PSP */
+#ifdef ANDROID
+#define MIN(X ,Y) ((X) < (Y) ? (X) : (Y))
+void Android_MidiMixMusic(Sint16 *stream, int len)
+{
+ if (_midi.status == MIDI_PLAYING) {
+ Sint16 buf[16384];
+ while( len > 0 )
+ {
+ int minlen = MIN(sizeof(buf), len);
+ mid_song_read_wave(_midi.song, stream, MIN(sizeof(buf), len*2));
+ for( Uint16 i = 0; i < minlen; i++ )
+ stream[i] += buf[i];
+ stream += minlen;
+ len -= minlen;
+ }
+ }
+}
+#endif
static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity;
Index: src/os/unix/unix.cpp
===================================================================
--- src/os/unix/unix.cpp (revision 21200)
@@ -36,3 +100,27 @@ Index: src/network/core/os_abstraction.h
/* If for any reason ifaddrs.h does not exist on your system, comment out
* the following two lines and an alternative way will be used to fetch
* the list of IPs from the system. */
Index: src/debug.cpp
===================================================================
--- src/debug.cpp (revision 21200)
+++ src/debug.cpp (working copy)
@@ -16,6 +16,9 @@
#include "string_func.h"
#include "fileio_func.h"
#include "settings_type.h"
+#ifdef ANDROID
+#include <android/log.h>
+#endif
#include <time.h>
@@ -76,6 +79,9 @@
*/
static void debug_print(const char *dbg, const char *buf)
{
+#ifdef ANDROID
+ __android_log_print(ANDROID_LOG_INFO, "OpenTTD", "[%s] %s", dbg, buf);
+#endif
#if defined(ENABLE_NETWORK)
if (_debug_socket != INVALID_SOCKET) {
char buf2[1024 + 32];

View File

@@ -1 +1 @@
scummvm
openttd

View File

@@ -83,11 +83,12 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring
}
}
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Calling SDL_main(\"%s\")", str);
(*env)->ReleaseStringUTFChars(env, cmdline, jstr);
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Calling SDL_main(\"%s\")", str);
//for( i = 0; i < argc; i++ )
// __android_log_print(ANDROID_LOG_INFO, "libSDL", "param %d = \"%s\"", i, argv[i]);
for( i = 0; i < argc; i++ )
__android_log_print(ANDROID_LOG_INFO, "libSDL", "param %d = \"%s\"", i, argv[i]);
main( argc, argv );

View File

@@ -19,6 +19,6 @@ LOCAL_SHARED_LIBRARIES :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_LDLIBS :=
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

View File

@@ -548,6 +548,7 @@ void pre_resample(MidSong *song, MidSample *sp)
sint32 incr, ofs, newlen, count;
sint16 *newdata, *dest, *src = (sint16 *) sp->data;
sint16 v1, v2, v3, v4, *vptr;
/*
#ifdef DEBUG_CHATTER
static const char note_name[12][3] =
{
@@ -555,9 +556,11 @@ void pre_resample(MidSong *song, MidSample *sp)
};
#endif
DEBUG_MSG(" * pre-resampling for note %d (%s%d)\n",
sp->note_to_use,
note_name[sp->note_to_use % 12], (sp->note_to_use & 0x7F) / 12);
*/
a = ((double) (sp->sample_rate) * freq_table[(int) (sp->note_to_use)]) /
((double) (sp->root_freq) * song->rate);

View File

@@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <android/log.h>
#include "timidity.h"
#include "timidity_internal.h"
@@ -90,7 +91,11 @@ static int read_config_file(char *name)
}
if (!(fp=open_file(name)))
{
__android_log_print(ANDROID_LOG_INFO, "libSDL", "libTimidity: read_config_file(%s) failure", name);
return -1;
}
__android_log_print(ANDROID_LOG_INFO, "libSDL", "libTimidity: read_config_file(%s) opened config success", name);
while (__fgets(tmp, sizeof(tmp), fp))
{
@@ -391,6 +396,9 @@ static int read_config_file(char *name)
}
}
fclose(fp);
__android_log_print(ANDROID_LOG_INFO, "libSDL", "libTimidity: read_config_file(%s) success", name);
return 0;
}
@@ -422,8 +430,7 @@ int mid_init(char *config_file)
#ifdef WIN32
add_to_pathlist("\\TIMIDITY");
#else
add_to_pathlist("/usr/local/lib/timidity");
add_to_pathlist("/etc");
add_to_pathlist("timidity");
#endif
mid_init_no_config();

View File

@@ -1,6 +1,7 @@
#ifndef TIMIDITY_INTERNAL_H
#define TIMIDITY_INTERNAL_H
#include <android/log.h>
#include "timidity.h"
#if defined(__i386__) || defined(__ia64__) || defined(WIN32) || \
@@ -49,11 +50,8 @@
#define SWAPLE32(x) XCHG_LONG(x)
#endif
#ifdef DEBUG
#define DEBUG_MSG(...) fprintf(stderr, __VA_ARGS__)
#else
//#define DEBUG_MSG(...) __android_log_print(ANDROID_LOG_INFO, "libSDL", __VA_ARGS__)
#define DEBUG_MSG(...)
#endif
#define MID_VIBRATO_SAMPLE_INCREMENTS 32