|
|
1.1 ! root 1: // ! 2: // nono ! 3: // Copyright (C) 2025 nono project ! 4: // Licensed under nono-license.txt ! 5: // ! 6: ! 7: // ! 8: // サウンドの NetBSD audio(4) ドライバ ! 9: // ! 10: ! 11: #include "sounddriver_netbsd.h" ! 12: #include "config.h" ! 13: #include "mainapp.h" ! 14: #include "sound.h" ! 15: #include <fcntl.h> ! 16: #include <unistd.h> ! 17: #include <sys/audioio.h> ! 18: #include <sys/ioctl.h> ! 19: ! 20: // コンストラクタ ! 21: SoundDriverNetBSD::SoundDriverNetBSD(HostDevice *hostdev_) ! 22: : inherited(hostdev_, "netbsd") ! 23: { ! 24: } ! 25: ! 26: // デストラクタ ! 27: SoundDriverNetBSD::~SoundDriverNetBSD() ! 28: { ! 29: fd.Close(); ! 30: } ! 31: ! 32: bool ! 33: SoundDriverNetBSD::InitDriver(bool startup) ! 34: { ! 35: if (inherited::InitDriver(startup) == false) { ! 36: return false; ! 37: } ! 38: ! 39: // NetBSD audio(4) はオープンしたまま保持してても困らないので ! 40: // 生存期間中ずっとオープンしておく。 ! 41: ! 42: const ConfigItem& item = gConfig->Find("hostsound-netbsd-device"); ! 43: device = item.AsString(); ! 44: ! 45: if (device.empty()) { ! 46: item.Err(); ! 47: return false; ! 48: } ! 49: ! 50: // device は '/'(スラッシュ) から始まっていればフルパス。 ! 51: // そうでなければ "/dev/" を接頭する。 ! 52: if (device[0] != '/') { ! 53: device = "/dev/" + device; ! 54: } ! 55: ! 56: fd = open(device.c_str(), O_WRONLY); ! 57: if (fd < 0) { ! 58: warn("%s: open %s failed", __method__, device.c_str()); ! 59: return false; ! 60: } ! 61: ! 62: struct audio_info info; ! 63: AUDIO_INITINFO(&info); ! 64: info.play.sample_rate = freq; ! 65: info.play.channels = Sound::NCHAN; ! 66: info.play.precision = 16; ! 67: info.play.encoding = AUDIO_ENCODING_SLINEAR; // ホストエンディアン ! 68: if (ioctl(fd, AUDIO_SETINFO, &info) < 0) { ! 69: warn("%s: %s: AUDIO_SETINFO failed", __method__, device.c_str()); ! 70: return false; ! 71: } ! 72: ! 73: return true; ! 74: } ! 75: ! 76: // ブロック書き出し ! 77: void ! 78: SoundDriverNetBSD::Write(const int16 *blk) ! 79: { ! 80: size_t written = 0; ! 81: for (; written < blkbytes;) { ! 82: const uint8 *buf = (const uint8 *)blk; ! 83: auto r = write(fd, buf + written, blkbytes - written); ! 84: if (r < 0) { ! 85: if (errno == EINTR) { ! 86: continue; ! 87: } ! 88: warn("%s: write failed", __method__); ! 89: return; ! 90: } ! 91: written += r; ! 92: } ! 93: } ! 94: ! 95: void ! 96: SoundDriverNetBSD::MonitorUpdateMD(TextScreen& screen, int y) ! 97: { ! 98: screen.Print(0, y, "Device path: %s", device.c_str()); ! 99: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.