Changeset 754dbda in orbit


Ignore:
Timestamp:
11/29/12 14:27:33 (7 years ago)
Author:
Steve Castellotti <sc@…>
Branches:
master, RawEEG, Raw_EEG_Plot, Servo, Tab_Interface, pyramid
Children:
2fc778c
Parents:
0401409 (diff), 655a816 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of ssh://puzzlebox.info/repo/orbit

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • octave/GenerateAudioCommand/flyCommand.m

    ra0b523e r655a816  
    77%sps = 96000;     % sample rate [samples/s] 
    88 
    9  
     9if length(code)==5 
    1010if code=='demo1' 
    1111        code=[1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 1 1 0 1 1 0];%minimum rotating throttle 
     
    1818        code=[1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 ];%test for Untitled 04 
    1919        endif 
     20 
     21endif 
    2022 
    2123if (length(AndroidOriOS)==3)%'iOS' 
     
    4850elseif length(AndroidOriOS)==7 %'Android' 
    4951 
    50 longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)-4;%longHIGH[us]  longHIGH_s[sample] 
    51 longLOW=729;longLOW_s=floor(longLOW*sps/1e6+3); 
    52 shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)-2; 
    53 shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6)+1; 
     52longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)-3;%longHIGH[us]  longHIGH_s[sample] 
     53longLOW=729;longLOW_s=floor(longLOW*sps/1e6+3)+1; 
     54shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)-3; 
     55shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6)+1+2; 
    5456 
    55 codeWave=[halfSineGenDirect('d',longLOW_s-1,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps);             halfSineGenDirect('d',shortLOW_s-1,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps); halfSineGenDirect('d',shortLOW_s,0,1,sps);0]; %starting 5 half period 
     57 
     58shortLOW_ss=floor(shortLOW*sps/1e6)+2; 
     59 
     60codeWave=[halfSineGenDirect('d',longLOW_s-1,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps);    halfSineGenDirect('d',shortLOW_ss+2,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps); halfSineGenDirect('d',shortLOW_ss+3,0,1,sps)]; %starting 5 half period 
    5661 
    5762% notice that the "code" here should be a 28 bit binary array. 
    58 m=0; 
    59 n=0; 
    6063for i=1:size(code,2) 
    6164codeWave = [codeWave; bitGenDirect(code(i),1,sps,longHIGH_s,   longLOW_s,shortHIGH_s,shortLOW_s)]; 
    62 if code(i)==1 
    63         n=n+1; 
    64 elseif code(i)==0 
    65         m=m+1; 
    66 endif 
    67  
    68 if n==115  
    69         n=0; 
    70         codeWave=[codeWave;0]; 
    71 endif 
    72 if m==101 
    73         m=0; 
    74         codeWave=[codeWave;0]; 
    75 endif 
    7665         
    7766endfor 
  • android/src/info/puzzlebox/orbit/MainActivity.java

    r1a53973 r0401409  
    1010import com.neurosky.thinkgear.TGDevice; 
    1111 
     12import android.media.AudioFormat; 
     13import android.media.AudioManager; 
     14import android.media.AudioTrack; 
    1215import android.os.Bundle; 
    1316import android.os.Handler; 
     
    9194        //private static final String MAC_ADDRESS = "00:16:53:09:0B:B9"; 
    9295 
     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         
    93143        /** 
    94144         * The device currently in use, or {@code null}. 
     
    207257                serial = new SerialDevice(); 
    208258                serial.setSerialDevice(mSerialDevice); 
     259                 
     260                 
     261                genTone(); 
     262                //playSound(); 
    209263 
    210264 
     
    520574 
    521575        public void demoMode(View view) { 
    522  
    523                 String command = "neutral"; 
    524576                 
    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); 
    551607 
    552608 
Note: See TracChangeset for help on using the changeset viewer.