Some code cleanup

This commit is contained in:
snow 2020-08-30 08:46:28 -07:00
parent 452c648f15
commit 653d5a769c

View file

@ -13,7 +13,6 @@
#include <libaudcore/ringbuf.h> #include <libaudcore/ringbuf.h>
#include <libaudcore/runtime.h> #include <libaudcore/runtime.h>
class NetBSDOutput : public OutputPlugin class NetBSDOutput : public OutputPlugin
{ {
public: public:
@ -34,19 +33,16 @@ public:
void close_audio (); void close_audio ();
int write_audio (const void * data, int size); int write_audio (const void * data, int size);
void pause (bool pause);
void period_wait (); void period_wait ();
int get_delay ();
void drain ();
void set_volume(StereoVolume volume); void set_volume(StereoVolume volume);
StereoVolume get_volume(); StereoVolume get_volume();
int get_delay ();
void pause (bool pause);
void flush (); void flush ();
void drain ();
}; };
__attribute__((visibility("default"))) NetBSDOutput aud_plugin_instance; __attribute__((visibility("default"))) NetBSDOutput aud_plugin_instance;
@ -114,16 +110,21 @@ NetBSDOutput::cleanup ()
close (audio_fd); close (audio_fd);
} }
/*
* Converts the format libaudcore provides to something usable
* in audio_info_t, then passes along the information to the
* audio device.
*/
bool bool
NetBSDOutput::open_audio (int format, NetBSDOutput::open_audio (int format,
int rate, int rate,
int chans, int chans,
String & error) String & error)
{ {
// TODO: /* TODO: Use FMT_S24_* or FMT_S24_3* */
audio_info_t info; audio_info_t info;
int props; int props;
// Audacious->NetBSD format table /* Audacious->NetBSD format table */
static const struct fmt_conv fmt_table[] = { static const struct fmt_conv fmt_table[] = {
{FMT_S8, AUDIO_ENCODING_SLINEAR, 8}, {FMT_S8, AUDIO_ENCODING_SLINEAR, 8},
{FMT_U8, AUDIO_ENCODING_ULINEAR, 8}, {FMT_U8, AUDIO_ENCODING_ULINEAR, 8},
@ -153,6 +154,7 @@ NetBSDOutput::open_audio (int format,
AUDIO_INITINFO (&info); AUDIO_INITINFO (&info);
/* Loop to find the right format, if it's supported */
for (auto & conv : fmt_table) { for (auto & conv : fmt_table) {
if (conv.aud_format == format) { if (conv.aud_format == format) {
cur_format = conv; cur_format = conv;
@ -165,13 +167,14 @@ NetBSDOutput::open_audio (int format,
return false; return false;
} }
info.play.channels = chans;
info.play.encoding = cur_format.encoding; info.play.encoding = cur_format.encoding;
info.play.precision = cur_format.bits; info.play.precision = cur_format.bits;
/* Channels and sample rate are straightforward, at least */
info.play.channels = chans;
info.play.sample_rate = rate; info.play.sample_rate = rate;
info.mode = AUMODE_PLAY; info.mode = AUMODE_PLAY;
if (ioctl (audio_fd, AUDIO_SETINFO, & info) == -1) { if (ioctl (audio_fd, AUDIO_SETINFO, & info) == -1) {
error = String (str_printf error = String (str_printf
("Failed to set track info on %s: %s.\n", ("Failed to set track info on %s: %s.\n",
@ -185,7 +188,7 @@ NetBSDOutput::open_audio (int format,
void void
NetBSDOutput::close_audio () NetBSDOutput::close_audio ()
{ {
AUDDBG ("close_audio is a stub!\n"); // XXX AUDDBG ("close_audio is a stub!\n"); /* XXX */
} }
int int
@ -330,7 +333,7 @@ NetBSDOutput::flush ()
StereoVolume StereoVolume
NetBSDOutput::get_volume () NetBSDOutput::get_volume ()
{ {
// too noisy, even for debug... /* too noisy, even for debug... */
// AUDDBG ("get_volume: Stub!\n"); // AUDDBG ("get_volume: Stub!\n");
return {100, 100}; // XXX return {100, 100}; // XXX