Changeset 0401409 in orbit for android/src
- Timestamp:
- 11/29/12 14:26:23 (10 years ago)
- Branches:
- master, RawEEG, Raw_EEG_Plot, Servo, Tab_Interface, pyramid
- Children:
- 754dbda
- Parents:
- a0b523e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
android/src/info/puzzlebox/orbit/MainActivity.java
r1a53973 r0401409 10 10 import com.neurosky.thinkgear.TGDevice; 11 11 12 import android.media.AudioFormat; 13 import android.media.AudioManager; 14 import android.media.AudioTrack; 12 15 import android.os.Bundle; 13 16 import android.os.Handler; … … 91 94 //private static final String MAC_ADDRESS = "00:16:53:09:0B:B9"; 92 95 96 97 98 // Tone Generator 99 // http://stackoverflow.com/questions/2413426/playing-an-arbitrary-tone-with-android 100 private final int duration = 10; // seconds 101 private final int sampleRate = 8000; 102 private final int numSamples = duration * sampleRate; 103 private final double sample[] = new double[numSamples]; 104 private final double freqOfTone = 440; // hz 105 106 private final byte generatedSnd[] = new byte[2 * numSamples]; 107 108 109 void genTone(){ 110 // fill out the array 111 for (int i = 0; i < numSamples; ++i) { 112 sample[i] = Math.sin(2 * Math.PI * i / (sampleRate/freqOfTone)); 113 } 114 115 // convert to 16 bit pcm sound array 116 // assumes the sample buffer is normalized. 117 int idx = 0; 118 for (final double dVal : sample) { 119 // scale to maximum amplitude 120 final short val = (short) ((dVal * 32767)); 121 // in 16 bit wav PCM, first byte is the low order byte 122 generatedSnd[idx++] = (byte) (val & 0x00ff); 123 generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8); 124 125 } 126 } 127 128 void playSound(){ 129 @SuppressWarnings("deprecation") 130 final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 131 // sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, 132 sampleRate, AudioFormat.CHANNEL_OUT_MONO, 133 // sampleRate, AudioFormat.CHANNEL_OUT_STEREO, 134 // sampleRate, AudioFormat.CHANNEL_OUT_FRONT_RIGHT, 135 // sampleRate, AudioFormat.CHANNEL_CONFIGURATION_STEREO, 136 AudioFormat.ENCODING_PCM_16BIT, generatedSnd.length, 137 AudioTrack.MODE_STATIC); 138 audioTrack.write(generatedSnd, 0, generatedSnd.length); 139 audioTrack.play(); 140 } 141 142 93 143 /** 94 144 * The device currently in use, or {@code null}. … … 207 257 serial = new SerialDevice(); 208 258 serial.setSerialDevice(mSerialDevice); 259 260 261 genTone(); 262 //playSound(); 209 263 210 264 … … 520 574 521 575 public void demoMode(View view) { 522 523 String command = "neutral";524 576 525 appendTextAndScroll("Command for serial device: " + command + "\n"); 526 serial.setCommand(command); 527 528 try { 529 Thread.sleep(5000); 530 } catch (InterruptedException e) { 531 // TODO Auto-generated catch block 532 e.printStackTrace(); 533 } 534 535 // command = "hover"; 536 command = "idle"; 537 appendTextAndScroll("Command for serial device: " + command + "\n"); 538 serial.setCommand(command); 539 540 try { 541 Thread.sleep(2500); 542 } catch (InterruptedException e) { 543 // TODO Auto-generated catch block 544 e.printStackTrace(); 545 } 546 547 548 command = "neutral"; 549 appendTextAndScroll("Command for serial device: " + command + "\n"); 550 serial.setCommand(command); 577 playSound(); 578 579 // String command = "neutral"; 580 // 581 // appendTextAndScroll("Command for serial device: " + command + "\n"); 582 // serial.setCommand(command); 583 // 584 // try { 585 // Thread.sleep(5000); 586 // } catch (InterruptedException e) { 587 // // TODO Auto-generated catch block 588 // e.printStackTrace(); 589 // } 590 // 591 //// command = "hover"; 592 // command = "idle"; 593 // appendTextAndScroll("Command for serial device: " + command + "\n"); 594 // serial.setCommand(command); 595 // 596 // try { 597 // Thread.sleep(2500); 598 // } catch (InterruptedException e) { 599 // // TODO Auto-generated catch block 600 // e.printStackTrace(); 601 // } 602 // 603 // 604 // command = "neutral"; 605 // appendTextAndScroll("Command for serial device: " + command + "\n"); 606 // serial.setCommand(command); 551 607 552 608
Note: See TracChangeset
for help on using the changeset viewer.