Guest User

Untitled

a guest
Nov 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. mState = State.STARTING;
  2.  
  3. thread = new Thread()
  4. {
  5. public void run()
  6. {
  7. mPlayer.open();
  8. boolean started = false;
  9.  
  10. mState = BeatMachine.State.STARTED;
  11.  
  12. boolean wasNextBufferPlayed = true;
  13. int end = 0;
  14.  
  15. while (mState == BeatMachine.State.STARTED && !areAllTracksComplete()) {
  16.  
  17. if (wasNextBufferPlayed) {
  18. // calculate how much audio we can write and make sure it is an even frame (end % channels == 0)
  19. end = mPlayer.availableFrames() * mPlayer.getChannels();
  20. wasNextBufferPlayed = false;
  21.  
  22. for (int i = 0; i < mTracks.size(); i++) {
  23. // get the next buffer of audio from the current track
  24. mTracks.get(i).nextBuffer(mMixerBuffer , end);
  25.  
  26. // if it is the first track, overwrite the buffer,
  27. // otherwise mix the buffer
  28. for (int j = 0; j < end; j++) {
  29. if (i == 0) // maybe this if could be optimized out of this loop
  30. mMasterBuffer[j] = mMixerBuffer[j];
  31. else
  32. mMasterBuffer[j] += mMixerBuffer[j];
  33. }
  34. wasNextBufferPlayed = false;
  35. }
  36. }
  37.  
  38. wasNextBufferPlayed = mPlayer.play(mMasterBuffer , end);
  39.  
  40. // the buffer is completely full (could FloatAudioPlayer potentially have autostart behavior)
  41. if (!started && mPlayer.availableFrames() == 0) {
  42. mPlayer.start();
  43. started = true;
  44. }
  45. }
  46. mPlayer.close();
  47. mState = BeatMachine.State.STOPPED;
  48. System.out.println("This line prints in all scenarios");
  49. }
  50. };
  51.  
  52. thread.start();
  53. }
Add Comment
Please, Sign In to add comment