Skip to content

Instantly share code, notes, and snippets.

@grapswiz
Created January 14, 2011 17:00
Show Gist options
  • Save grapswiz/779886 to your computer and use it in GitHub Desktop.
Save grapswiz/779886 to your computer and use it in GitHub Desktop.
package ws.graps;
import android.app.Activity;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import java.util.Random;
public class RecordActivity extends Activity
{
Button playButton = null;
AudioTrack track = null;
int playCount = 0;
TextView text = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.recorder);
track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, AudioFormat.ENCODING_DEFAULT, 44100, AudioTrack.MODE_STATIC);
byte[] whiteNoise = new byte[44100];
Random rand = new Random();
rand.nextBytes(whiteNoise);
track.write(whiteNoise, 0, whiteNoise.length);
text = (TextView)findViewById(R.id.textview01);
playButton = (Button)findViewById(R.id.playButton);
playButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
text.setText(""+playCount);
if(playCount > 0) {
track.stop();
track.reloadStaticData();
}
track.play();
playCount++;
}
});
}
@Override
public void onPause()
{
super.onPause();
track.stop();
track.release();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment