Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mState = State.STARTING;
- thread = new Thread()
- {
- public void run()
- {
- mPlayer.open();
- boolean started = false;
- mState = BeatMachine.State.STARTED;
- boolean wasNextBufferPlayed = true;
- int end = 0;
- while (mState == BeatMachine.State.STARTED && !areAllTracksComplete()) {
- if (wasNextBufferPlayed) {
- // calculate how much audio we can write and make sure it is an even frame (end % channels == 0)
- end = mPlayer.availableFrames() * mPlayer.getChannels();
- wasNextBufferPlayed = false;
- for (int i = 0; i < mTracks.size(); i++) {
- // get the next buffer of audio from the current track
- mTracks.get(i).nextBuffer(mMixerBuffer , end);
- // if it is the first track, overwrite the buffer,
- // otherwise mix the buffer
- for (int j = 0; j < end; j++) {
- if (i == 0) // maybe this if could be optimized out of this loop
- mMasterBuffer[j] = mMixerBuffer[j];
- else
- mMasterBuffer[j] += mMixerBuffer[j];
- }
- wasNextBufferPlayed = false;
- }
- }
- wasNextBufferPlayed = mPlayer.play(mMasterBuffer , end);
- // the buffer is completely full (could FloatAudioPlayer potentially have autostart behavior)
- if (!started && mPlayer.availableFrames() == 0) {
- mPlayer.start();
- started = true;
- }
- }
- mPlayer.close();
- mState = BeatMachine.State.STOPPED;
- System.out.println("This line prints in all scenarios");
- }
- };
- thread.start();
- }
Add Comment
Please, Sign In to add comment