Audio working, yay!
This commit is contained in:
@@ -148,22 +148,32 @@ class AudioThread extends Thread {
|
||||
private Activity mParent;
|
||||
private AudioTrack mAudio;
|
||||
private byte[] mAudioBuffer;
|
||||
public int mLibraryLoaded;
|
||||
|
||||
public AudioThread(Activity parent)
|
||||
{
|
||||
android.util.Log.i("SDL Java", "AudioThread created");
|
||||
mParent = parent;
|
||||
mAudio = null;
|
||||
mAudioBuffer = null;
|
||||
mLibraryLoaded = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
android.util.Log.i("SDL Java", "AudioThread::Run(): enter");
|
||||
while( !isInterrupted() )
|
||||
{
|
||||
android.util.Log.i("SDL Java", "AudioThread::Run(): loop");
|
||||
if( mAudio == null )
|
||||
{
|
||||
int[] initParams = nativeAudioInit();
|
||||
int[] initParams = null;
|
||||
if( mLibraryLoaded != 0 )
|
||||
{
|
||||
android.util.Log.i("SDL Java", "AudioThread::Run(): call nativeAudioInit()");
|
||||
initParams = nativeAudioInit();
|
||||
}
|
||||
if( initParams == null )
|
||||
{
|
||||
try {
|
||||
@@ -172,6 +182,7 @@ class AudioThread extends Thread {
|
||||
}
|
||||
else
|
||||
{
|
||||
android.util.Log.i("SDL Java", "AudioThread::Run(): !!!INIT!!!");
|
||||
int rate = initParams[0];
|
||||
int channels = initParams[1];
|
||||
channels = ( channels == 1 ) ? AudioFormat.CHANNEL_CONFIGURATION_MONO :
|
||||
@@ -194,6 +205,7 @@ class AudioThread extends Thread {
|
||||
}
|
||||
else
|
||||
{
|
||||
android.util.Log.i("SDL Java", "AudioThread::Run(): playing");
|
||||
int len = nativeAudioBuffer( mAudioBuffer );
|
||||
if( len > 0 )
|
||||
mAudio.write( mAudioBuffer, 0, len );
|
||||
@@ -213,9 +225,13 @@ public class DemoActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mLoadLibraryStub = new LoadLibrary();
|
||||
// Wicked - we have to create audio thread before loading library
|
||||
// because audio is initialized even before main() (how's that even possible?)
|
||||
mLoadLibraryStub = null;
|
||||
mAudioThread = new AudioThread(this);
|
||||
mAudioThread.start();
|
||||
mLoadLibraryStub = new LoadLibrary();
|
||||
mAudioThread.mLibraryLoaded = 1;
|
||||
mGLView = new DemoGLSurfaceView(this);
|
||||
setContentView(mGLView);
|
||||
// Receive keyboard events
|
||||
|
||||
Reference in New Issue
Block a user