Add get_volume and set_volume methods

This uses the global volume for the audio/mixer device. This isn't
ideal, but to my understanding follows what the alsa and oss plugins
do as well. Audacious already provides a software volume control in
Settings -> Audio, which despite saying "not recommended," doesn't
seem to have any issues.
This commit is contained in:
snow 2020-08-30 16:53:20 -07:00
parent 276fe1a24d
commit efea009b02
2 changed files with 29 additions and 13 deletions

1
TODO
View file

@ -1,6 +1,5 @@
* Determine if audio open/close should happen in open_audio
and close_audio
* Support get_volume/set_volume
* Support 24-bit LPCM -> 32-bit
* Create a settings panel so users can select their output
device

View file

@ -50,7 +50,7 @@ __attribute__((visibility("default"))) NetBSDOutput aud_plugin_instance;
static String audio_path;
static int audio_fd;
static bool audio_paused, audio_prebuffer, audio_flushed;
static bool audio_paused, audio_flushed;
static pthread_mutex_t nbout_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t nbout_cond = PTHREAD_COND_INITIALIZER;
@ -97,7 +97,7 @@ NetBSDOutput::init ()
audio_fd = open (audio_path, O_WRONLY);
if (audio_fd == -1) {
AUDERR ("Failed to open %s: %s.\n", audio_path, strerror (errno));
AUDERR ("Failed to open %s: %s.\n", (const char *) audio_path, strerror (errno));
return false;
}
@ -142,14 +142,14 @@ NetBSDOutput::open_audio (int format,
if (ioctl (audio_fd, AUDIO_GETPROPS, & props) == -1) {
error = String (str_printf
("Failed to get audio properties on %s: %s.",
audio_path, strerror (errno)));
(const char *) audio_path, strerror (errno)));
return false;
}
if (props | AUDIO_PROP_PLAYBACK != AUDIO_PROP_PLAYBACK) {
if ((props | AUDIO_PROP_PLAYBACK) != AUDIO_PROP_PLAYBACK) {
error = String (str_printf
("Device %s does not support playback.",
audio_path));
(const char *) audio_path));
}
AUDIO_INITINFO (&info);
@ -178,7 +178,7 @@ NetBSDOutput::open_audio (int format,
if (ioctl (audio_fd, AUDIO_SETINFO, & info) == -1) {
error = String (str_printf
("Failed to set track info on %s: %s.\n",
audio_path, strerror (errno)));
(const char *) audio_path, strerror (errno)));
return false;
}
@ -238,8 +238,7 @@ NetBSDOutput::period_wait ()
void
NetBSDOutput::pause (bool pause)
{
int res, len;
audio_info_t info;
int res;
AUDDBG ("Setting pause = %s.\n", pause ? "true" : "false");
@ -333,14 +332,32 @@ NetBSDOutput::flush ()
StereoVolume
NetBSDOutput::get_volume ()
{
/* too noisy, even for debug... */
// AUDDBG ("get_volume: Stub!\n");
audio_info_t info;
int aud_vol;
return {100, 100}; // XXX
if (ioctl (audio_fd, AUDIO_GETINFO, & info) != 0) {
AUDERR ("Unable to get volume: %s.\n", strerror (errno));
return { 0, 0 };
}
aud_vol = aud::rescale ((int)info.play.gain - AUDIO_MIN_GAIN,
AUDIO_MAX_GAIN - AUDIO_MIN_GAIN,
100);
return { aud_vol, aud_vol };
}
void
NetBSDOutput::set_volume (StereoVolume volume)
{
AUDDBG ("set_volume: Stub!\n"); // XXX
audio_info_t info;
AUDIO_INITINFO (& info);
info.play.gain = aud::rescale (aud::max
(volume.left, volume.right), 100,
AUDIO_MAX_GAIN) + AUDIO_MIN_GAIN;
if (ioctl(audio_fd, AUDIO_SETINFO, & info) != 0) {
AUDERR ("Unable to set volume: %s.\n", strerror (errno));
}
}