# HG changeset patch # User ranma # Date 1038179595 0 # Node ID b1c5460a81052a5ba34e7a126c83f63431e1eb82 # Parent 64786fe1a8a6b9f2e9dd9f5d196a513926a01730 Implement volume setting functionality, original patch by Nguyen Kim . Note that volume changing never worked on my system with NAS, but that seems to be a nasd problem which I did not try to track down yet... diff -r 64786fe1a8a6 -r b1c5460a8105 libao2/ao_nas.c --- a/libao2/ao_nas.c Sun Nov 24 22:26:43 2002 +0000 +++ b/libao2/ao_nas.c Sun Nov 24 23:13:15 2002 +0000 @@ -333,8 +333,53 @@ } // to set/get/query special features/parameters -static int control(int cmd,int arg){ - return -1; +static int control(int cmd, int arg) +{ + AuDeviceAttributes *dattr; + AuFixedPoint fpgain; + AuStatus as; + int gain; + ao_control_vol_t *vol = (ao_control_vol_t *)arg; + + dattr = AuGetDeviceAttributes(nas_data->aud, nas_data->dev, &as); + if (as != AuSuccess) { + nas_print_error(nas_data->aud, + "control(): AuGetDeviceAttributes", as); + return CONTROL_ERROR; + } + gain = AuFixedPointRoundDown(AuDeviceGain(dattr)); + // kn: 0 <= gain <= 100 + + switch (cmd) { + case AOCONTROL_GET_VOLUME: + + vol->right = (float) gain; + vol->left = vol->right; + + return CONTROL_OK; + + case AOCONTROL_SET_VOLUME: + /* + * kn: we should have vol->left == vol->right but i don't + * know if something can change it outside of ao_nas + * so i take the mean of both values. + */ + gain = (int) ((vol->left+vol->right)/2); + + fpgain = AuFixedPointFromSum(gain, 0); + AuDeviceGain(dattr) = fpgain; + AuSetDeviceAttributes(nas_data->aud, nas_data->dev, + AuCompDeviceGainMask, dattr, &as); + if (as != AuSuccess) { + nas_print_error(nas_data->aud, + "control(): AuSetDeviceAttributes", as); + return CONTROL_ERROR; + } + return CONTROL_OK; + + default: + return CONTROL_UNKNOWN; + }; } // open & setup audio device