Ignore:
Timestamp:
07/31/13 17:02:07 (7 years ago)
Author:
Jonathon Horsman <jonathon@…>
Branches:
master, RawEEG, Servo, Tab_Interface, pyramid
Children:
de10cbc, 0ab8242
Parents:
9015b1e
Message:

Port Android AudioService? to iOS
Dummy page for tutorial
icons for tabs (which don't work)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • iOS/Orbit/Orbit/SignalConverter.m

    r9015b1e rce0a7ee  
    2727     
    2828    int signalStrength, attentionLevel, meditationLevel; // the latest readings from the headset 
     29    int yaw, throttle, pitch; 
    2930} 
    3031 
     
    3940        [[TGAccessoryManager sharedTGAccessoryManager] setupManagerWithInterval:0.05]; 
    4041        [[TGAccessoryManager sharedTGAccessoryManager] setDelegate:self]; 
     42        audioPlayer = [[AudioGenerator alloc] init]; 
     43         
     44        // defaults 
     45        throttle = 80; 
     46        yaw = 78; 
     47        pitch = 31; 
    4148    } 
    4249    return self; 
     
    4855    meditationThreshold = meditation; 
    4956    [self calculatePowerValues]; 
    50 } 
    51  
    52 - (void) prepare 
    53 { 
    54     NSURL *audioFilePath = [[NSBundle mainBundle] URLForResource:AUDIO_FILE_NAME withExtension:nil]; 
    55     audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFilePath error:nil]; 
    56     if (audioPlayer) { 
    57         [audioPlayer prepareToPlay]; 
    58     } 
    5957} 
    6058 
     
    142140{ 
    143141    float volume = [[AVAudioSession sharedInstance] outputVolume]; 
    144 //    Float32 volume; 
    145 //    UInt32 dataSize = sizeof(Float32); 
    146 //     
    147 //    AudioSessionGetProperty ( 
    148 //                             kAudioSessionProperty_CurrentHardwareOutputVolume, 
    149 //                             &dataSize, 
    150 //                             &volume 
    151 //                             ); 
    152142    return volume == 1.0; 
    153143} 
     
    171161{ 
    172162    [self appStopped]; 
    173     [self prepare];     
    174163} 
    175164 
     
    187176} 
    188177 
     178- (void) setYaw:(int)y throttle:(int)t pitch:(int)p 
     179{ 
     180    yaw = y; 
     181    throttle = t; 
     182    pitch = p; 
     183} 
     184 
    189185- (void) playAudio 
    190186{ 
    191     //   audioPlayer.volume = [self currentPowerLevel]; 
    192187    if ([self currentPowerLevel] > 0) { 
    193         audioPlayer.volume = 1.0; 
    194         [audioPlayer play]; 
     188        [audioPlayer playWithThrottle:throttle yaw:yaw pitch:pitch]; 
    195189    } else { 
    196190        [audioPlayer stop]; 
    197         [self prepare]; 
    198191         
    199192    } 
     
    229222} 
    230223 
    231 // calculate the checksum for the generated code used to generate the WAV array 
    232 - (int) codeChecksum:(int)code 
    233 { 
    234     int checksum = 0; 
    235     for (int i = 0; i < 7; i++) { 
    236         checksum += (code >> 4*i) & 15; 
    237     } 
    238     return 16 - (checksum & 15); 
    239 } 
    240  
    241 // Generate the code used to create the WAV file based on the given throttle, yaw and pitch. 
    242 // Copied from AudioService.java in the Android app 
    243 // throttle: 0~127, nothing will happen if this value is below 30. 
    244 // yaw: 0~127, normally 78 will keep orbit from rotating. 
    245 // pitch: 0~63, normally 31 will stop the top propeller. 
    246 // channel: 1=Channel A, 0=Channel B 2= Channel C, depend on which channel you want to pair to the orbit. You can fly at most 3 orbit in a same room. 
    247 - (int) generateCodeFromThrottle: (int)throttle yaw: (int)yaw pitch: (int)pitch channel: (int)channel 
    248 { 
    249     int code = (throttle << 21) + 1048576 + (yaw << 12) + (pitch << 4) + (((channel >> 1) & 1) << 19) + ((channel & 1) << 11); 
    250     return code;// + codeChecksum(code); 
    251 } 
    252  
    253224@end 
Note: See TracChangeset for help on using the changeset viewer.