Annotation of nono/host/sounddriver_sndio.cpp, revision 1.1

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2025 nono project
        !             4: // Licensed under nono-license.txt
        !             5: //
        !             6: 
        !             7: //
        !             8: // サウンドの OpenBSD sndio ドライバ
        !             9: //
        !            10: 
        !            11: #include "sounddriver_sndio.h"
        !            12: #include "config.h"
        !            13: #include "sound.h"
        !            14: 
        !            15: // コンストラクタ
        !            16: SoundDriverSndIO::SoundDriverSndIO(HostDevice *hostdev_)
        !            17:        : inherited(hostdev_, "sndio")
        !            18: {
        !            19: }
        !            20: 
        !            21: // デストラクタ
        !            22: SoundDriverSndIO::~SoundDriverSndIO()
        !            23: {
        !            24:        Close();
        !            25: }
        !            26: 
        !            27: bool
        !            28: SoundDriverSndIO::InitDriver(bool startup)
        !            29: {
        !            30:        if (inherited::InitDriver(startup) == false) {
        !            31:                return false;
        !            32:        }
        !            33: 
        !            34:        sio = sio_open(SIO_DEVANY, SIO_PLAY, 0);
        !            35:        if (sio == NULL) {
        !            36:                warn("%s: sio_open() failed", __method__);
        !            37:                return false;
        !            38:        }
        !            39: 
        !            40:        struct sio_par param;
        !            41:        sio_initpar(&param);
        !            42:        param.rate = freq;
        !            43:        param.bits = 16;
        !            44:        param.sig = 1;
        !            45:        param.le = SIO_LE_NATIVE;
        !            46:        param.pchan = Sound::NCHAN;
        !            47:        param.appbufsz = freq * Sound::BLK_NSEC / 1_sec;
        !            48:        if (sio_setpar(sio, &param) != 1) {
        !            49:                warn("%s: sio_set_par() failed", __method__);
        !            50:                sio_close(sio);
        !            51:                return false;
        !            52:        }
        !            53: 
        !            54:        if (sio_start(sio) != 1) {
        !            55:                warn("%s: sio_start() failed", __method__);
        !            56:                sio_close(sio);
        !            57:                return false;
        !            58:        }
        !            59: 
        !            60:        return true;
        !            61: }
        !            62: 
        !            63: // ブロック書き出し
        !            64: void
        !            65: SoundDriverSndIO::Write(const int16 *blk)
        !            66: {
        !            67:        size_t written = 0;
        !            68:        for (; written < blkbytes;) {
        !            69:                const uint8 *buf = (const uint8 *)blk;
        !            70:                auto r = sio_write(sio, buf + written, blkbytes - written);
        !            71:                if (r == 0) {
        !            72:                        // ?
        !            73:                        break;
        !            74:                }
        !            75:                written += r;
        !            76:        }
        !            77: }
        !            78: 
        !            79: void
        !            80: SoundDriverSndIO::Close()
        !            81: {
        !            82:        sio_stop(sio);
        !            83:        sio_close(sio);
        !            84: }
        !            85: 
        !            86: void
        !            87: SoundDriverSndIO::MonitorUpdateMD(TextScreen& screen, int y)
        !            88: {
        !            89: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.