Splitted Java sources to many small files, fixed tabulation, splitted input source file from video in libSDL.
This commit is contained in:
95
alienblaster/project/src/Audio.java
Normal file
95
alienblaster/project/src/Audio.java
Normal file
@@ -0,0 +1,95 @@
|
||||
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
|
||||
package de.schwardtnet.alienblaster;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.media.AudioTrack;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioFormat;
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
class AudioThread extends Thread {
|
||||
|
||||
private Activity mParent;
|
||||
private AudioTrack mAudio;
|
||||
private byte[] mAudioBuffer;
|
||||
private ByteBuffer mAudioBufferNative;
|
||||
|
||||
public AudioThread(Activity parent)
|
||||
{
|
||||
mParent = parent;
|
||||
mAudio = null;
|
||||
mAudioBuffer = null;
|
||||
this.setPriority(Thread.MAX_PRIORITY);
|
||||
this.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while( !isInterrupted() )
|
||||
{
|
||||
if( mAudio == null )
|
||||
{
|
||||
int[] initParams = nativeAudioInit();
|
||||
if( initParams == null )
|
||||
{
|
||||
try {
|
||||
sleep(200);
|
||||
} catch( java.lang.InterruptedException e ) { };
|
||||
}
|
||||
else
|
||||
{
|
||||
int rate = initParams[0];
|
||||
int channels = initParams[1];
|
||||
channels = ( channels == 1 ) ? AudioFormat.CHANNEL_CONFIGURATION_MONO :
|
||||
AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
||||
int encoding = initParams[2];
|
||||
encoding = ( encoding == 1 ) ? AudioFormat.ENCODING_PCM_16BIT :
|
||||
AudioFormat.ENCODING_PCM_8BIT;
|
||||
int bufSize = AudioTrack.getMinBufferSize( rate, channels, encoding );
|
||||
if( initParams[3] > bufSize )
|
||||
bufSize = initParams[3];
|
||||
mAudioBuffer = new byte[bufSize];
|
||||
nativeAudioInit2(mAudioBuffer);
|
||||
mAudio = new AudioTrack(AudioManager.STREAM_MUSIC,
|
||||
rate,
|
||||
channels,
|
||||
encoding,
|
||||
bufSize,
|
||||
AudioTrack.MODE_STREAM );
|
||||
mAudio.play();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int len = nativeAudioBufferLock();
|
||||
if( len > 0 )
|
||||
mAudio.write( mAudioBuffer, 0, len );
|
||||
if( len < 0 )
|
||||
break;
|
||||
nativeAudioBufferUnlock();
|
||||
}
|
||||
}
|
||||
if( mAudio != null )
|
||||
{
|
||||
mAudio.stop();
|
||||
mAudio.release();
|
||||
mAudio = null;
|
||||
}
|
||||
}
|
||||
|
||||
private native int[] nativeAudioInit();
|
||||
private native int nativeAudioInit2(byte[] buf);
|
||||
private native int nativeAudioBufferLock();
|
||||
private native int nativeAudioBufferUnlock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user