output/PipeWire: move code to ::SetVolume()
This commit is contained in:
parent
6857286b42
commit
f55bc6682f
@ -309,6 +309,23 @@ PipeWireOutput::PipeWireOutput(const ConfigBlock &block)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws on error.
|
||||||
|
*
|
||||||
|
* @param volume a volume level between 0.0 and 1.0
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
SetVolume(struct pw_stream &stream, unsigned channels, float volume)
|
||||||
|
{
|
||||||
|
float value[MAX_CHANNELS];
|
||||||
|
std::fill_n(value, channels, volume * volume * volume);
|
||||||
|
|
||||||
|
if (pw_stream_set_control(&stream,
|
||||||
|
SPA_PROP_channelVolumes, channels, value,
|
||||||
|
0) != 0)
|
||||||
|
throw std::runtime_error("pw_stream_set_control() failed");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PipeWireOutput::SetVolume(float _volume)
|
PipeWireOutput::SetVolume(float _volume)
|
||||||
{
|
{
|
||||||
@ -322,17 +339,8 @@ PipeWireOutput::SetVolume(float _volume)
|
|||||||
|
|
||||||
const PipeWire::ThreadLoopLock lock(thread_loop);
|
const PipeWire::ThreadLoopLock lock(thread_loop);
|
||||||
|
|
||||||
float newvol = _volume*_volume*_volume;
|
if (stream != nullptr && !restore_volume)
|
||||||
|
::SetVolume(*stream, channels, _volume);
|
||||||
if (stream != nullptr && !restore_volume) {
|
|
||||||
float vol[MAX_CHANNELS];
|
|
||||||
std::fill_n(vol, channels, newvol);
|
|
||||||
|
|
||||||
if (pw_stream_set_control(stream,
|
|
||||||
SPA_PROP_channelVolumes, channels, vol,
|
|
||||||
0) != 0)
|
|
||||||
throw std::runtime_error("pw_stream_set_control() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
volume = _volume;
|
volume = _volume;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user