Skip to content

Commit 3d8050f

Browse files
committed
Sound (NetBSD): use kernel APIs instead of the OSS wrapper
1 parent 4d842ac commit 3d8050f

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ elseif(NetBSD)
761761
src/detection/poweradapter/poweradapter_nosupport.c
762762
src/detection/processes/processes_nbsd.c
763763
src/detection/gtk_qt/qt.c
764-
src/detection/sound/sound_bsd.c
764+
src/detection/sound/sound_nbsd.c
765765
src/detection/swap/swap_obsd.c
766766
src/detection/terminalfont/terminalfont_linux.c
767767
src/detection/terminalshell/terminalshell_linux.c
@@ -1510,7 +1510,6 @@ elseif(NetBSD)
15101510
target_link_libraries(libfastfetch
15111511
PRIVATE "m"
15121512
PRIVATE "prop"
1513-
PRIVATE "ossaudio"
15141513
)
15151514
elseif(SunOS)
15161515
target_link_libraries(libfastfetch

src/detection/sound/sound_nbsd.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "sound.h"
2+
#include "common/io/io.h"
3+
4+
#include <fcntl.h>
5+
#include <stdint.h>
6+
#include <unistd.h>
7+
#include <sys/audioio.h>
8+
#include <sys/ioctl.h>
9+
10+
const char* ffDetectSound(FFlist* devices)
11+
{
12+
int defaultDev;
13+
{
14+
char audiop[12];
15+
ssize_t plen = readlink("/dev/audio", audiop, ARRAY_SIZE(audiop));
16+
if (plen < (ssize_t) strlen("audioN"))
17+
return "readlink(/dev/audio) failed";
18+
defaultDev = audiop[plen - 1] - '0';
19+
if (defaultDev < 0 || defaultDev > 9)
20+
return "Invalid audio device";
21+
}
22+
23+
char path[] = "/dev/audio0";
24+
25+
for (int idev = 0; idev < 9; ++idev)
26+
{
27+
path[strlen("/dev/audio")] = (char) ('0' + idev);
28+
FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR);
29+
if (fd < 0) break;
30+
31+
audio_device_t ad;
32+
if (ioctl(fd, AUDIO_GETDEV, &ad) < 0)
33+
continue;
34+
35+
audio_info_t ai;
36+
if (ioctl(fd, AUDIO_GETINFO, &ai) < 0)
37+
continue;
38+
39+
FFSoundDevice* device = ffListAdd(devices);
40+
ffStrbufInitS(&device->identifier, path);
41+
ffStrbufInitS(&device->name, ad.name);
42+
ffStrbufTrimRightSpace(&device->name);
43+
ffStrbufInitF(&device->platformApi, "%s", "SunAudio");
44+
device->volume = (uint8_t) (ai.play.gain * 100 / AUDIO_MAX_GAIN);
45+
device->active = true;
46+
device->main = defaultDev == idev;
47+
}
48+
49+
return NULL;
50+
}

0 commit comments

Comments
 (0)