src/haptic/darwin/SDL_syshaptic.c
branchgsoc2008_force_feedback
changeset 2628 bfbda6c656e5
parent 2627 265ced2079bd
child 2629 43a0416b3707
equal deleted inserted replaced
2627:265ced2079bd 2628:bfbda6c656e5
   580          SDL_SetError("Haptic: Unknown direction type.");
   580          SDL_SetError("Haptic: Unknown direction type.");
   581          return -1;
   581          return -1;
   582    }
   582    }
   583 }
   583 }
   584 
   584 
   585 #define CONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
   585 
       
   586 /* Clamps and converts. */
       
   587 #define CCONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
       
   588 /* Just converts. */
       
   589 #define CONVERT(x)    (((x)*10000) / 0x7FFF)
   586 /*
   590 /*
   587  * Creates the FFEFFECT from a SDL_HapticEffect.
   591  * Creates the FFEFFECT from a SDL_HapticEffect.
   588  */
   592  */
   589 static int
   593 static int
   590 SDL_SYS_ToFFEFFECT( SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src )
   594 SDL_SYS_ToFFEFFECT( SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src )
   670          if ((hap_constant->attack_length==0) && (hap_constant->fade_length==0)) {
   674          if ((hap_constant->attack_length==0) && (hap_constant->fade_length==0)) {
   671             SDL_free(envelope);
   675             SDL_free(envelope);
   672             dest->lpEnvelope = NULL;
   676             dest->lpEnvelope = NULL;
   673          }
   677          }
   674          else {
   678          else {
   675             envelope->dwAttackLevel = CONVERT(hap_constant->attack_level);
   679             envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
   676             envelope->dwAttackTime = hap_constant->attack_length * 1000;
   680             envelope->dwAttackTime = hap_constant->attack_length * 1000;
   677             envelope->dwFadeLevel = CONVERT(hap_constant->fade_level);
   681             envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
   678             envelope->dwFadeTime = hap_constant->fade_length * 1000;
   682             envelope->dwFadeTime = hap_constant->fade_length * 1000;
   679          }
   683          }
   680 
   684 
   681          break;
   685          break;
   682 
   686 
   716          if ((hap_periodic->attack_length==0) && (hap_periodic->fade_length==0)) {
   720          if ((hap_periodic->attack_length==0) && (hap_periodic->fade_length==0)) {
   717             SDL_free(envelope);
   721             SDL_free(envelope);
   718             dest->lpEnvelope = NULL;
   722             dest->lpEnvelope = NULL;
   719          }
   723          }
   720          else {
   724          else {
   721             envelope->dwAttackLevel = CONVERT(hap_periodic->attack_level);
   725             envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
   722             envelope->dwAttackTime = hap_periodic->attack_length * 1000;
   726             envelope->dwAttackTime = hap_periodic->attack_length * 1000;
   723             envelope->dwFadeLevel = CONVERT(hap_periodic->fade_level);
   727             envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
   724             envelope->dwFadeTime = hap_periodic->fade_length * 1000;
   728             envelope->dwFadeTime = hap_periodic->fade_length * 1000;
   725          }
   729          }
   726 
   730 
   727          break;
   731          break;
   728 
   732 
   741          /* Specifics */
   745          /* Specifics */
   742          for (i=0; i<dest->cAxes; i++) {
   746          for (i=0; i<dest->cAxes; i++) {
   743             condition[i].lOffset = CONVERT(hap_condition->center[i]);
   747             condition[i].lOffset = CONVERT(hap_condition->center[i]);
   744             condition[i].lPositiveCoefficient = CONVERT(hap_condition->right_coeff[i]);
   748             condition[i].lPositiveCoefficient = CONVERT(hap_condition->right_coeff[i]);
   745             condition[i].lNegativeCoefficient = CONVERT(hap_condition->left_coeff[i]);
   749             condition[i].lNegativeCoefficient = CONVERT(hap_condition->left_coeff[i]);
   746             condition[i].dwPositiveSaturation = CONVERT(hap_condition->right_sat[i]);
   750             condition[i].dwPositiveSaturation = CCONVERT(hap_condition->right_sat[i]);
   747             condition[i].dwNegativeSaturation = CONVERT(hap_condition->left_sat[i]);
   751             condition[i].dwNegativeSaturation = CCONVERT(hap_condition->left_sat[i]);
   748             condition[i].lDeadBand = CONVERT(hap_condition->deadband[i]);
   752             condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i]);
   749          }
   753          }
   750          dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
   754          dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
   751          dest->lpvTypeSpecificParams = condition;
   755          dest->lpvTypeSpecificParams = condition;
   752 
   756 
   753          /* Generics */
   757          /* Generics */
   763                                       
   767                                       
   764          /* Envelope */
   768          /* Envelope */
   765          SDL_free(dest->lpEnvelope);
   769          SDL_free(dest->lpEnvelope);
   766          dest->lpEnvelope = NULL;
   770          dest->lpEnvelope = NULL;
   767 /* TODO Check is envelope actually used.
   771 /* TODO Check is envelope actually used.
   768          envelope->dwAttackLevel = CONVERT(hap_condition->attack_level);
   772          envelope->dwAttackLevel = CCONVERT(hap_condition->attack_level);
   769          envelope->dwAttackTime = hap_condition->attack_length * 1000;
   773          envelope->dwAttackTime = hap_condition->attack_length * 1000;
   770          envelope->dwFadeLevel = CONVERT(hap_condition->fade_level);
   774          envelope->dwFadeLevel = CCONVERT(hap_condition->fade_level);
   771          envelope->dwFadeTime = hap_condition->fade_length * 1000;
   775          envelope->dwFadeTime = hap_condition->fade_length * 1000;
   772 */
   776 */
   773 
   777 
   774          break;
   778          break;
   775 
   779 
   803          if ((hap_ramp->attack_length==0) && (hap_ramp->fade_length==0)) {
   807          if ((hap_ramp->attack_length==0) && (hap_ramp->fade_length==0)) {
   804             SDL_free(envelope);
   808             SDL_free(envelope);
   805             dest->lpEnvelope = NULL;
   809             dest->lpEnvelope = NULL;
   806          }
   810          }
   807          else {
   811          else {
   808             envelope->dwAttackLevel = CONVERT(hap_ramp->attack_level);
   812             envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
   809             envelope->dwAttackTime = hap_ramp->attack_length * 1000;
   813             envelope->dwAttackTime = hap_ramp->attack_length * 1000;
   810             envelope->dwFadeLevel = CONVERT(hap_ramp->fade_level);
   814             envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
   811             envelope->dwFadeTime = hap_ramp->fade_length * 1000;
   815             envelope->dwFadeTime = hap_ramp->fade_length * 1000;
   812          }
   816          }
   813 
   817 
   814          break;
   818          break;
   815 
   819 
   826          custom->cChannels = hap_custom->channels;
   830          custom->cChannels = hap_custom->channels;
   827          custom->dwSamplePeriod = hap_custom->period * 1000;
   831          custom->dwSamplePeriod = hap_custom->period * 1000;
   828          custom->cSamples = hap_custom->samples;
   832          custom->cSamples = hap_custom->samples;
   829          custom->rglForceData = SDL_malloc(sizeof(LONG)*custom->cSamples*custom->cChannels);
   833          custom->rglForceData = SDL_malloc(sizeof(LONG)*custom->cSamples*custom->cChannels);
   830          for (i=0; i<hap_custom->samples*hap_custom->channels; i++) { /* Copy data. */
   834          for (i=0; i<hap_custom->samples*hap_custom->channels; i++) { /* Copy data. */
   831             custom->rglForceData[i] = CONVERT(hap_custom->data[i]);
   835             custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
   832          }
   836          }
   833          dest->cbTypeSpecificParams = sizeof(FFCUSTOMFORCE);
   837          dest->cbTypeSpecificParams = sizeof(FFCUSTOMFORCE);
   834          dest->lpvTypeSpecificParams = custom;
   838          dest->lpvTypeSpecificParams = custom;
   835 
   839 
   836          /* Generics */
   840          /* Generics */
   848          if ((hap_custom->attack_length==0) && (hap_custom->fade_length==0)) {
   852          if ((hap_custom->attack_length==0) && (hap_custom->fade_length==0)) {
   849             SDL_free(envelope);
   853             SDL_free(envelope);
   850             dest->lpEnvelope = NULL;
   854             dest->lpEnvelope = NULL;
   851          }
   855          }
   852          else {
   856          else {
   853             envelope->dwAttackLevel = CONVERT(hap_custom->attack_level);
   857             envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
   854             envelope->dwAttackTime = hap_custom->attack_length * 1000;
   858             envelope->dwAttackTime = hap_custom->attack_length * 1000;
   855             envelope->dwFadeLevel = CONVERT(hap_custom->fade_level);
   859             envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
   856             envelope->dwFadeTime = hap_custom->fade_length * 1000;
   860             envelope->dwFadeTime = hap_custom->fade_length * 1000;
   857          }
   861          }
   858 
   862 
   859          break;
   863          break;
   860 
   864