mirror of
https://github.com/DrBeef/DVR.git
synced 2025-02-15 00:11:21 +00:00
Multiple changes
- Improves handling of sound pool so sounds don't cut out - Proper exit when user quits - Keep playing title music while selecting WAD
This commit is contained in:
parent
cc28497ed2
commit
219311a246
11 changed files with 141 additions and 68 deletions
|
@ -11,6 +11,6 @@ rename libs.zip libs.jar
|
|||
|
||||
REM Create an archive of the source
|
||||
cd ..\src\main\assets\source
|
||||
REM del DVRSource.zip
|
||||
REM 7z a -r -x!.git* -x!*.o -x!*.d -x!obj -x!*.bin -x!app\build -x!app\libs -x!*.jar -x!*.so -x!*.log -x!*.jks -x!*.apk DVRSource.zip ..\..\..\..\..\*
|
||||
del DVRSource.zip
|
||||
7z a -r -x!.git* -x!*.o -x!*.d -x!obj -x!*.bin -x!app\build -x!app\libs -x!*.jar -x!*.so -x!*.log -x!*.jks -x!*.apk DVRSource.zip ..\..\..\..\..\*
|
||||
cd ..\..\..\..\jni
|
||||
|
|
|
@ -84,6 +84,12 @@
|
|||
#define CB_CLASS_SETMV_CB "OnSetMusicVolume"
|
||||
#define CB_CLASS_SETMV_SIG "(I)V"
|
||||
|
||||
/**
|
||||
* prboom4android.jni.Natives.OnQuit (int code)
|
||||
*/
|
||||
#define CB_CLASS_QUIT_CB "OnQuit"
|
||||
#define CB_CLASS_QUIT_SIG "(I)V"
|
||||
|
||||
/* debug macros */
|
||||
#define DEBUG_PREFIX printf("JNI__DEBUG ");
|
||||
#define DEBUG0(X) if (debug_jni) {DEBUG_PREFIX printf(X);}
|
||||
|
|
|
@ -23,6 +23,7 @@ jmethodID jStartMusic = 0;
|
|||
jmethodID jStopMusic = 0;
|
||||
jmethodID jInitGraphics = 0;
|
||||
jmethodID jSendStr = 0;
|
||||
jmethodID jQuit = 0;
|
||||
|
||||
// Java image pixels: int ARGB
|
||||
jintArray jImage = 0;
|
||||
|
@ -87,6 +88,15 @@ int loadJNIMethods(JNIEnv * env)
|
|||
return -1;
|
||||
}
|
||||
|
||||
jQuit = (*env)->GetStaticMethodID(env, jNativesCls
|
||||
, CB_CLASS_QUIT_CB
|
||||
, CB_CLASS_QUIT_SIG);
|
||||
|
||||
if ( jQuit == 0 ) {
|
||||
jni_printf("Unable to find method OnQuit sig: %s ", CB_CLASS_QUIT_SIG);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Load OnInfoMessage(String name, boolean longDisplay)
|
||||
jSendInfoMessage = (*env)->GetStaticMethodID(env, jNativesCls
|
||||
, CB_CLASS_INFMSG_CB
|
||||
|
@ -603,4 +613,22 @@ void jni_set_music_volume (int vol) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bg msic vol callback
|
||||
*/
|
||||
void jni_quit (int code) {
|
||||
|
||||
JNIEnv *env;
|
||||
if (((*g_VM)->GetEnv(g_VM, (void**) &env, JNI_VERSION_1_4))<0)
|
||||
{
|
||||
(*g_VM)->AttachCurrentThread(g_VM, &env, NULL);
|
||||
}
|
||||
|
||||
if (jQuit) {
|
||||
(*env)->CallStaticVoidMethod(env, jNativesCls
|
||||
, jQuit
|
||||
, (jint) code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1028,6 +1028,8 @@ int quitsounds2[8] =
|
|||
sfx_sgtatk
|
||||
};
|
||||
|
||||
extern void jni_quit(int code);
|
||||
|
||||
static void M_QuitResponse(int ch)
|
||||
{
|
||||
if (ch != 'y' && ch != 0x0d)
|
||||
|
@ -1051,7 +1053,8 @@ static void M_QuitResponse(int ch)
|
|||
i--;
|
||||
}
|
||||
}
|
||||
exit(0); // killough
|
||||
|
||||
jni_quit(0);
|
||||
}
|
||||
|
||||
void M_QuitDOOM(int choice)
|
||||
|
|
|
@ -298,7 +298,7 @@ default_t defaults[] =
|
|||
def_bool,ss_none}, // enables variable pitch in sound effects (from id's original code)
|
||||
{"samplerate",{&snd_samplerate},{22050},11025,48000, def_int,ss_none},
|
||||
{"sfx_volume",{&snd_SfxVolume},{15},0,15, def_int,ss_none},
|
||||
{"music_volume",{&snd_MusicVolume},{15},0,15, def_int,ss_none},
|
||||
{"music_volume",{&snd_MusicVolume},{5},0,15, def_int,ss_none},
|
||||
{"mus_pause_opt",{&mus_pause_opt},{2},0,2, // CPhipps - music pausing
|
||||
def_int, ss_none}, // 0 = kill music when paused, 1 = pause music, 2 = let music continue
|
||||
{"snd_channels",{&default_numChannels},{8},1,32,
|
||||
|
|
|
@ -83,9 +83,7 @@ static channel_t *channels;
|
|||
// Maximum volume of a sound effect.
|
||||
// Internal default is max out of 0-15.
|
||||
int snd_SfxVolume = 15;
|
||||
|
||||
// Maximum volume of music. Useless so far.
|
||||
int snd_MusicVolume = 15;
|
||||
int snd_MusicVolume = 5;
|
||||
|
||||
// whether songs are mus_paused
|
||||
static boolean mus_paused;
|
||||
|
|
|
@ -71,7 +71,7 @@ music_card -1
|
|||
pitched_sounds 0
|
||||
samplerate 22050
|
||||
sfx_volume 15
|
||||
music_volume 15
|
||||
music_volume 5
|
||||
mus_pause_opt 2
|
||||
snd_channels 8
|
||||
|
||||
|
|
|
@ -307,6 +307,12 @@ public class MainActivity
|
|||
String dvr= DoomTools.GetDVRFolder();
|
||||
Natives.DoomInit(argv, dvr);
|
||||
mDVRInitialised = true;
|
||||
|
||||
if (mPlayer != null) {
|
||||
mPlayer.stop();
|
||||
mPlayer.release();
|
||||
mPlayer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -492,10 +498,7 @@ public class MainActivity
|
|||
private void dismissSplashScreen()
|
||||
{
|
||||
if (mShowingSpashScreen) {
|
||||
mPlayer.stop();
|
||||
mPlayer.release();
|
||||
mShowingSpashScreen = false;
|
||||
|
||||
mWADChooser.Initialise(this.getAssets());
|
||||
}
|
||||
}
|
||||
|
@ -659,10 +662,11 @@ public class MainActivity
|
|||
@Override
|
||||
public void OnQuit(int code) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(250);
|
||||
}
|
||||
catch (InterruptedException ie){
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import android.net.Uri;
|
|||
* @author Owner
|
||||
*
|
||||
*/
|
||||
public class AudioClip
|
||||
public class AudioClip
|
||||
{
|
||||
static final String TAG = "AudioClip";
|
||||
|
||||
|
@ -52,36 +52,38 @@ public class AudioClip
|
|||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean isPlaying() {
|
||||
return mPlaying;
|
||||
}
|
||||
|
||||
//For music
|
||||
public synchronized void play () {
|
||||
if (mPlaying) {
|
||||
if (mPlaying) {
|
||||
mPlayer.seekTo(0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (mPlayer != null ) {
|
||||
mPlaying = true;
|
||||
mPlayer.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//For SFX
|
||||
public synchronized void play (int vol) {
|
||||
if (mPlaying) {
|
||||
mPlayer.seekTo(0);
|
||||
// return;
|
||||
}
|
||||
|
||||
mPlayer.seekTo(0);
|
||||
|
||||
if (mPlayer != null ) {
|
||||
mPlaying = true;
|
||||
|
||||
//Log.d(TAG, "Play " + name + " vol=" + vol);
|
||||
float log1=1.0f - (float)(Math.log(101-vol)/Math.log(101));
|
||||
mPlayer.setVolume(log1, log1);
|
||||
|
||||
setVolume(vol);
|
||||
mPlayer.start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public synchronized void stop() {
|
||||
try {
|
||||
|
@ -120,6 +122,8 @@ public class AudioClip
|
|||
*/
|
||||
public void setVolume (int vol) {
|
||||
if ( mPlayer != null) {
|
||||
if (vol > 100)
|
||||
vol = 100;
|
||||
float log1=1.0f - (float)(Math.log(101-vol)/Math.log(101));
|
||||
mPlayer.setVolume(log1, log1);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package doom.audio;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
@ -16,16 +19,17 @@ import doom.util.DoomTools;
|
|||
public class AudioManager
|
||||
{
|
||||
static final String TAG = "AudioMgr";
|
||||
public static final int MAX_CLIPS = 50;
|
||||
public static final int MAX_CLIPS = 20;
|
||||
|
||||
static private AudioManager am ;
|
||||
|
||||
// Game sound (WAVs)
|
||||
private volatile HashMap<String, AudioClip> mSounds = new HashMap<String, AudioClip>();
|
||||
private volatile HashMap<String, List<AudioClip>> mSounds = new HashMap<String, List<AudioClip>>();
|
||||
private Context mContext;
|
||||
private int mClipCount = 0;
|
||||
private boolean mPaused = false;
|
||||
|
||||
private int mMusicVolume = 0;
|
||||
|
||||
// BG music
|
||||
private AudioClip music;
|
||||
|
||||
|
@ -55,12 +59,35 @@ public class AudioManager
|
|||
// The sound key as stored in the FS -> DS[NAME-UCASE].wav
|
||||
//String key = "DS" + name.toUpperCase() + ".wav";
|
||||
String key = name + ".wav";
|
||||
|
||||
|
||||
AudioClip clip = null;
|
||||
if ( mSounds.containsKey(key)) {
|
||||
//Log.d(TAG, "Playing " + key + " from cache vol:" + vol);
|
||||
mSounds.get(key).play();
|
||||
List<AudioClip> clipList = mSounds.get(key);
|
||||
|
||||
for (AudioClip c: clipList) {
|
||||
if (!c.isPlaying())
|
||||
{
|
||||
clip = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (clip == null &&
|
||||
clipList.size() >= 2)
|
||||
{
|
||||
//Limit to 2 of the same sound
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
List<AudioClip> clipList = new LinkedList<AudioClip>();
|
||||
mSounds.put(key, clipList);
|
||||
}
|
||||
|
||||
if (clip == null)
|
||||
{
|
||||
// load clip from disk
|
||||
File folder = DoomTools.GetSoundFolder(); //DoomTools.DOOM_WADS[mWadIdx]);
|
||||
File sound = new File(folder.getAbsolutePath() + File.separator + key);
|
||||
|
@ -74,30 +101,39 @@ public class AudioManager
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If the sound table is full remove a random entry
|
||||
if ( mClipCount > MAX_CLIPS) {
|
||||
// Remove a last key
|
||||
int idx = mSounds.size() - 1; //(int)(Math.random() * (mSounds.size() - 1));
|
||||
|
||||
//Log.d(TAG, "Removing cached sound " + idx
|
||||
// + " HashMap size=" + mSounds.size());
|
||||
|
||||
String k = (String)mSounds.keySet().toArray()[idx];
|
||||
AudioClip clip = mSounds.remove(k);
|
||||
clip.release();
|
||||
clip = null;
|
||||
mClipCount--;
|
||||
}
|
||||
|
||||
//Log.d(TAG, "Play & Cache " + key + " u:" + Uri.fromFile(sound));
|
||||
|
||||
AudioClip clip = new AudioClip(mContext, Uri.fromFile(sound));
|
||||
clip.play(vol);
|
||||
|
||||
mSounds.put(key, clip);
|
||||
AudioClip newClip = new AudioClip(mContext, Uri.fromFile(sound));
|
||||
newClip.play(vol);
|
||||
|
||||
List<AudioClip> clipList = mSounds.get(key);
|
||||
clipList.add(newClip);
|
||||
mClipCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip.play(vol);
|
||||
}
|
||||
|
||||
// If the sound table is full remove a random entry
|
||||
boolean firstLoop = true;
|
||||
while ( mClipCount > MAX_CLIPS) {
|
||||
for (Map.Entry<String, List<AudioClip>> entry : mSounds.entrySet()) {
|
||||
if (entry.getValue().size() > 1 || !firstLoop) {
|
||||
for (AudioClip c : entry.getValue()) {
|
||||
if (!c.isPlaying()) {
|
||||
if (entry.getValue().remove(c)) {
|
||||
c.release();
|
||||
c = null;
|
||||
mClipCount--;
|
||||
//Done, move to next list
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
firstLoop = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,7 +160,7 @@ public class AudioManager
|
|||
Log.d(TAG, "Starting music " + sound + " loop=" + loop);
|
||||
music = new AudioClip(ctx, Uri.fromFile( sound ));
|
||||
|
||||
music.setVolume(100);
|
||||
music.setVolume(mMusicVolume);
|
||||
if (loop != 0)
|
||||
music.loop();
|
||||
music.play();
|
||||
|
@ -135,22 +171,17 @@ public class AudioManager
|
|||
* @param key
|
||||
*/
|
||||
public void stopMusic (String key) {
|
||||
File file = new File(DoomTools.GetDVRFolder() + File.separator + key + ".mid");
|
||||
Uri sound = Uri.fromFile(file);
|
||||
|
||||
if ( music != null ) {
|
||||
if ( !sound.equals(Uri.parse(music.getName()))) {
|
||||
Log.w(TAG, "Stop music uri " + sound + " different than " + music.getName());
|
||||
}
|
||||
music.stop();
|
||||
music.release();
|
||||
music = null;
|
||||
}
|
||||
music.stop();
|
||||
music.release();
|
||||
music = null;
|
||||
}
|
||||
|
||||
public void setMusicVolume (int vol) {
|
||||
if ( music != null)
|
||||
music.setVolume(vol);
|
||||
//Store
|
||||
mMusicVolume = vol;
|
||||
if ( music != null) {
|
||||
music.setVolume(mMusicVolume);
|
||||
}
|
||||
else
|
||||
Log.e(TAG, "setMusicVolume " + vol + " called with NULL music player");
|
||||
}
|
||||
|
|
|
@ -120,7 +120,6 @@ public class Natives
|
|||
|
||||
/**
|
||||
* Fires when Doom Quits
|
||||
* TODO: No yet implemented in the JNI lib
|
||||
* @param code
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
|
|
Loading…
Reference in a new issue