| 8519 | |
| 8520 | |
| 8521 | ResultType Line::SoundSetWaveVolume(char *aVolume, HWAVEOUT aDeviceID) |
| 8522 | { |
| 8523 | double volume = ATOF(aVolume); |
| 8524 | if (volume < -100) |
| 8525 | volume = -100; |
| 8526 | else if (volume > 100) |
| 8527 | volume = 100; |
| 8528 | |
| 8529 | // Make this an int vs. WORD so that negative values are supported (e.g. adjust volume by -10%). |
| 8530 | int specified_vol_per_channel = (int)(0xFFFF * (volume / 100)); |
| 8531 | DWORD vol_new; |
| 8532 | |
| 8533 | // For v1.0.25, the first char of RAW_ARG is also checked in case this is an expression intended |
| 8534 | // to be a positive offset, such as +(var + 10) |
| 8535 | if (*aVolume == '-' || *aVolume == '+' || *RAW_ARG1 == '+') // User wants to adjust the current level by a certain amount. |
| 8536 | { |
| 8537 | DWORD current_vol; |
| 8538 | if (waveOutGetVolume(aDeviceID, ¤t_vol) != MMSYSERR_NOERROR) |
| 8539 | return g_ErrorLevel->Assign(ERRORLEVEL_ERROR); |
| 8540 | // Adjust left & right independently so that we at least attempt to retain the user's |
| 8541 | // balance setting (if overflow or underflow occurs, the relative balance might be lost): |
| 8542 | int vol_left = LOWORD(current_vol); // Make them ints so that overflow/underflow can be detected. |
| 8543 | int vol_right = HIWORD(current_vol); |
| 8544 | vol_left += specified_vol_per_channel; |
| 8545 | vol_right += specified_vol_per_channel; |
| 8546 | // Handle underflow or overflow: |
| 8547 | if (vol_left < 0) |
| 8548 | vol_left = 0; |
| 8549 | else if (vol_left > 0xFFFF) |
| 8550 | vol_left = 0xFFFF; |
| 8551 | if (vol_right < 0) |
| 8552 | vol_right = 0; |
| 8553 | else if (vol_right > 0xFFFF) |
| 8554 | vol_right = 0xFFFF; |
| 8555 | vol_new = MAKELONG((WORD)vol_left, (WORD)vol_right); // Left is low-order, right is high-order. |
| 8556 | } |
| 8557 | else // User wants the volume level set to an absolute level (i.e. ignore its current level). |
| 8558 | vol_new = MAKELONG((WORD)specified_vol_per_channel, (WORD)specified_vol_per_channel); |
| 8559 | |
| 8560 | if (waveOutSetVolume(aDeviceID, vol_new) == MMSYSERR_NOERROR) |
| 8561 | return g_ErrorLevel->Assign(ERRORLEVEL_NONE); |
| 8562 | else |
| 8563 | return g_ErrorLevel->Assign(ERRORLEVEL_ERROR); |
| 8564 | } |
| 8565 | |
| 8566 | |
| 8567 | |