View difference between Paste ID: 0guN6sCr and 5zs9Szvu
SHOW: | | - or go back to the newest paste.
1
package com.example.guitar_tuner;
2
3
import android.media.AudioFormat;
4
import android.media.AudioRecord;
5
import android.media.MediaRecorder.AudioSource;
6
import android.os.Bundle;
7
import android.app.Activity;
8
import android.view.Menu;
9
import android.view.View;
10
import android.widget.TextView;
11
12
public class MainActivity extends Activity {
13
	
14-
	int audioSource = AudioSource.MIC;
14+
    int audioSource = AudioSource.MIC;
15
    int sampleRateInHz = 44100;
16
    int channelConfig = AudioFormat.CHANNEL_IN_MONO;
17
    int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
18
    int bufferSizeInShorts = 44100;
19
    int bufferSizeInBytes = 2*bufferSizeInShorts;
20
    
21
    short Data[] = new short[bufferSizeInShorts];
22
    Thread recordingThread;
23
    
24
    AudioRecord audioRecorder = new AudioRecord(audioSource,
25
						sampleRateInHz, 
26
						channelConfig, 
27
						audioFormat, 
28
						bufferSizeInBytes);
29
30
	@Override
31
	protected void onCreate(Bundle savedInstanceState) {
32
		super.onCreate(savedInstanceState);
33
		setContentView(R.layout.activity_main);
34
	}
35
36
	@Override
37
	public boolean onCreateOptionsMenu(Menu menu) {
38
		getMenuInflater().inflate(R.menu.activity_main, menu);
39
		return true;
40
	}
41
	
42
	public void changeText(View arg0) {
43
		TextView text = (TextView)findViewById(R.id.textView1);
44
		audioRecorder.startRecording();
45
		recordingThread = new Thread(new Runnable() {
46
		    public void run() {
47
		    	while (Data[bufferSizeInShorts-1] == 0) {
48
					audioRecorder.read(Data, 0, bufferSizeInShorts);
49
				}
50
		    }
51
		});
52
		audioRecorder.stop();
53
		String teksty = Short.toString(Data[bufferSizeInShorts-1]);
54
		text.setText(teksty);
55
	}
56
57
}