src/haptic/windows/SDL_dinputhaptic.c
changeset 9071 8e04e17c7af3
parent 9070 8973a237f360
child 9147 6bf589c8d549
equal deleted inserted replaced
9070:8973a237f360 9071:8e04e17c7af3
   600     default:
   600     default:
   601         return SDL_SetError("Haptic: Unknown direction type.");
   601         return SDL_SetError("Haptic: Unknown direction type.");
   602     }
   602     }
   603 }
   603 }
   604 
   604 
   605 #define CONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
   605 /* Clamps and converts. */
       
   606 #define CCONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
       
   607 /* Just converts. */
       
   608 #define CONVERT(x)    (((x)*10000) / 0x7FFF)
   606 /*
   609 /*
   607  * Creates the DIEFFECT from a SDL_HapticEffect.
   610  * Creates the DIEFFECT from a SDL_HapticEffect.
   608  */
   611  */
   609 static int
   612 static int
   610 SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
   613 SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
   687         if ((hap_constant->attack_length == 0)
   690         if ((hap_constant->attack_length == 0)
   688             && (hap_constant->fade_length == 0)) {
   691             && (hap_constant->fade_length == 0)) {
   689             SDL_free(dest->lpEnvelope);
   692             SDL_free(dest->lpEnvelope);
   690             dest->lpEnvelope = NULL;
   693             dest->lpEnvelope = NULL;
   691         } else {
   694         } else {
   692             envelope->dwAttackLevel = CONVERT(hap_constant->attack_level);
   695             envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
   693             envelope->dwAttackTime = hap_constant->attack_length * 1000;
   696             envelope->dwAttackTime = hap_constant->attack_length * 1000;
   694             envelope->dwFadeLevel = CONVERT(hap_constant->fade_level);
   697             envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
   695             envelope->dwFadeTime = hap_constant->fade_length * 1000;
   698             envelope->dwFadeTime = hap_constant->fade_length * 1000;
   696         }
   699         }
   697 
   700 
   698         break;
   701         break;
   699 
   702 
   734         if ((hap_periodic->attack_length == 0)
   737         if ((hap_periodic->attack_length == 0)
   735             && (hap_periodic->fade_length == 0)) {
   738             && (hap_periodic->fade_length == 0)) {
   736             SDL_free(dest->lpEnvelope);
   739             SDL_free(dest->lpEnvelope);
   737             dest->lpEnvelope = NULL;
   740             dest->lpEnvelope = NULL;
   738         } else {
   741         } else {
   739             envelope->dwAttackLevel = CONVERT(hap_periodic->attack_level);
   742             envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
   740             envelope->dwAttackTime = hap_periodic->attack_length * 1000;
   743             envelope->dwAttackTime = hap_periodic->attack_length * 1000;
   741             envelope->dwFadeLevel = CONVERT(hap_periodic->fade_level);
   744             envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
   742             envelope->dwFadeTime = hap_periodic->fade_length * 1000;
   745             envelope->dwFadeTime = hap_periodic->fade_length * 1000;
   743         }
   746         }
   744 
   747 
   745         break;
   748         break;
   746 
   749 
   761             condition[i].lPositiveCoefficient =
   764             condition[i].lPositiveCoefficient =
   762                 CONVERT(hap_condition->right_coeff[i]);
   765                 CONVERT(hap_condition->right_coeff[i]);
   763             condition[i].lNegativeCoefficient =
   766             condition[i].lNegativeCoefficient =
   764                 CONVERT(hap_condition->left_coeff[i]);
   767                 CONVERT(hap_condition->left_coeff[i]);
   765             condition[i].dwPositiveSaturation =
   768             condition[i].dwPositiveSaturation =
   766                 CONVERT(hap_condition->right_sat[i] / 2);
   769                 CCONVERT(hap_condition->right_sat[i] / 2);
   767             condition[i].dwNegativeSaturation =
   770             condition[i].dwNegativeSaturation =
   768                 CONVERT(hap_condition->left_sat[i] / 2);
   771                 CCONVERT(hap_condition->left_sat[i] / 2);
   769             condition[i].lDeadBand = CONVERT(hap_condition->deadband[i] / 2);
   772             condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
   770         }
   773         }
   771         dest->cbTypeSpecificParams = sizeof(DICONDITION) * dest->cAxes;
   774         dest->cbTypeSpecificParams = sizeof(DICONDITION) * dest->cAxes;
   772         dest->lpvTypeSpecificParams = condition;
   775         dest->lpvTypeSpecificParams = condition;
   773 
   776 
   774         /* Generics */
   777         /* Generics */
   817         /* Envelope */
   820         /* Envelope */
   818         if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) {
   821         if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) {
   819             SDL_free(dest->lpEnvelope);
   822             SDL_free(dest->lpEnvelope);
   820             dest->lpEnvelope = NULL;
   823             dest->lpEnvelope = NULL;
   821         } else {
   824         } else {
   822             envelope->dwAttackLevel = CONVERT(hap_ramp->attack_level);
   825             envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
   823             envelope->dwAttackTime = hap_ramp->attack_length * 1000;
   826             envelope->dwAttackTime = hap_ramp->attack_length * 1000;
   824             envelope->dwFadeLevel = CONVERT(hap_ramp->fade_level);
   827             envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
   825             envelope->dwFadeTime = hap_ramp->fade_length * 1000;
   828             envelope->dwFadeTime = hap_ramp->fade_length * 1000;
   826         }
   829         }
   827 
   830 
   828         break;
   831         break;
   829 
   832 
   840         custom->dwSamplePeriod = hap_custom->period * 1000;
   843         custom->dwSamplePeriod = hap_custom->period * 1000;
   841         custom->cSamples = hap_custom->samples;
   844         custom->cSamples = hap_custom->samples;
   842         custom->rglForceData =
   845         custom->rglForceData =
   843             SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
   846             SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
   844         for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) {      /* Copy data. */
   847         for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) {      /* Copy data. */
   845             custom->rglForceData[i] = CONVERT(hap_custom->data[i]);
   848             custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
   846         }
   849         }
   847         dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE);
   850         dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE);
   848         dest->lpvTypeSpecificParams = custom;
   851         dest->lpvTypeSpecificParams = custom;
   849 
   852 
   850         /* Generics */
   853         /* Generics */
   862         if ((hap_custom->attack_length == 0)
   865         if ((hap_custom->attack_length == 0)
   863             && (hap_custom->fade_length == 0)) {
   866             && (hap_custom->fade_length == 0)) {
   864             SDL_free(dest->lpEnvelope);
   867             SDL_free(dest->lpEnvelope);
   865             dest->lpEnvelope = NULL;
   868             dest->lpEnvelope = NULL;
   866         } else {
   869         } else {
   867             envelope->dwAttackLevel = CONVERT(hap_custom->attack_level);
   870             envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
   868             envelope->dwAttackTime = hap_custom->attack_length * 1000;
   871             envelope->dwAttackTime = hap_custom->attack_length * 1000;
   869             envelope->dwFadeLevel = CONVERT(hap_custom->fade_level);
   872             envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
   870             envelope->dwFadeTime = hap_custom->fade_length * 1000;
   873             envelope->dwFadeTime = hap_custom->fade_length * 1000;
   871         }
   874         }
   872 
   875 
   873         break;
   876         break;
   874 
   877