* The audio mixer is supposed to support getting/setting only a single value,
such that all channels are affected. * This fixes the "setvolume" command under Haiku. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30013 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1127,8 +1127,8 @@ AudioMixer::Gain_to_dB(float gain)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
AudioMixer::GetParameterValue(int32 id, bigtime_t *last_change,
|
AudioMixer::GetParameterValue(int32 id, bigtime_t *last_change, void *value,
|
||||||
void *value, size_t *ioSize)
|
size_t *ioSize)
|
||||||
{
|
{
|
||||||
TRACE("GetParameterValue: id 0x%08lx, ioSize %ld\n", id, *ioSize);
|
TRACE("GetParameterValue: id 0x%08lx, ioSize %ld\n", id, *ioSize);
|
||||||
int param = PARAM(id);
|
int param = PARAM(id);
|
||||||
@@ -1196,11 +1196,31 @@ AudioMixer::GetParameterValue(int32 id, bigtime_t *last_change,
|
|||||||
static_cast<float *>(value)[0] = GAIN_TO_DB((output->GetOutputChannelGain(0) + output->GetOutputChannelGain(1)) / 2);
|
static_cast<float *>(value)[0] = GAIN_TO_DB((output->GetOutputChannelGain(0) + output->GetOutputChannelGain(1)) / 2);
|
||||||
} else {
|
} else {
|
||||||
// multi channel control
|
// multi channel control
|
||||||
if (*ioSize < output->GetOutputChannelCount() * sizeof(float))
|
if (*ioSize == sizeof(float)) {
|
||||||
goto err;
|
// get combined gain for all controls
|
||||||
*ioSize = output->GetOutputChannelCount() * sizeof(float);
|
float gain = 0;
|
||||||
for (int chan = 0; chan < output->GetOutputChannelCount(); chan++)
|
for (int channel = 0;
|
||||||
static_cast<float *>(value)[chan] = GAIN_TO_DB(output->GetOutputChannelGain(chan));
|
channel < output->GetOutputChannelCount();
|
||||||
|
channel++) {
|
||||||
|
gain += GAIN_TO_DB(
|
||||||
|
output->GetOutputChannelGain(channel));
|
||||||
|
}
|
||||||
|
static_cast<float *>(value)[0] = gain
|
||||||
|
/ output->GetOutputChannelCount();
|
||||||
|
} else {
|
||||||
|
if (*ioSize < output->GetOutputChannelCount()
|
||||||
|
* sizeof(float))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
*ioSize = output->GetOutputChannelCount() * sizeof(float);
|
||||||
|
|
||||||
|
for (int channel = 0;
|
||||||
|
channel < output->GetOutputChannelCount();
|
||||||
|
channel++) {
|
||||||
|
static_cast<float *>(value)[channel]
|
||||||
|
= GAIN_TO_DB(output->GetOutputChannelGain(channel));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PARAM_IS_BALANCE(id)) {
|
if (PARAM_IS_BALANCE(id)) {
|
||||||
@@ -1313,9 +1333,10 @@ err:
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
AudioMixer::SetParameterValue(int32 id, bigtime_t when,
|
void
|
||||||
const void *value, size_t size)
|
AudioMixer::SetParameterValue(int32 id, bigtime_t when, const void *value,
|
||||||
|
size_t size)
|
||||||
{
|
{
|
||||||
TRACE("SetParameterValue: id 0x%08lx, size %ld\n", id, size);
|
TRACE("SetParameterValue: id 0x%08lx, size %ld\n", id, size);
|
||||||
bool update = false;
|
bool update = false;
|
||||||
@@ -1394,7 +1415,8 @@ AudioMixer::SetParameterValue(int32 id, bigtime_t when,
|
|||||||
}
|
}
|
||||||
if (PARAM_IS_GAIN(id)) {
|
if (PARAM_IS_GAIN(id)) {
|
||||||
// output gain control
|
// output gain control
|
||||||
if (fCore->Settings()->UseBalanceControl() && output->GetOutputChannelCount() == 2 && 1 /*channel mask is stereo */) {
|
if (fCore->Settings()->UseBalanceControl()
|
||||||
|
&& output->GetOutputChannelCount() == 2 && 1 /*channel mask is stereo */) {
|
||||||
// single channel control + balance
|
// single channel control + balance
|
||||||
float l = output->GetOutputChannelGain(0);
|
float l = output->GetOutputChannelGain(0);
|
||||||
float r = output->GetOutputChannelGain(1);
|
float r = output->GetOutputChannelGain(1);
|
||||||
@@ -1406,10 +1428,26 @@ AudioMixer::SetParameterValue(int32 id, bigtime_t when,
|
|||||||
output->SetOutputChannelGain(1, output->GetOutputChannelGain(1) * f);
|
output->SetOutputChannelGain(1, output->GetOutputChannelGain(1) * f);
|
||||||
} else {
|
} else {
|
||||||
// multi channel control
|
// multi channel control
|
||||||
if (size < output->GetOutputChannelCount() * sizeof(float))
|
if (size == sizeof(float)) {
|
||||||
goto err;
|
// set same volume for all channels
|
||||||
for (int chan = 0; chan < output->GetOutputChannelCount(); chan++)
|
float gain = static_cast<const float *>(value)[0];
|
||||||
output->SetOutputChannelGain(chan, DB_TO_GAIN(static_cast<const float *>(value)[chan]));
|
for (int channel = 0;
|
||||||
|
channel < output->GetOutputChannelCount();
|
||||||
|
channel++) {
|
||||||
|
output->SetOutputChannelGain(channel,
|
||||||
|
DB_TO_GAIN(gain));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (size < output->GetOutputChannelCount() * sizeof(float))
|
||||||
|
goto err;
|
||||||
|
for (int channel = 0;
|
||||||
|
channel < output->GetOutputChannelCount();
|
||||||
|
channel++) {
|
||||||
|
output->SetOutputChannelGain(channel,
|
||||||
|
DB_TO_GAIN(static_cast<const float *>(
|
||||||
|
value)[channel]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PARAM_IS_BALANCE(id)) {
|
if (PARAM_IS_BALANCE(id)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user