From 86a71cc6a25e288c097975dfe2e16b9cad07d963 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 6 Mar 2022 03:33:56 -0500 Subject: [PATCH] PC speaker: use evdev instead of KIOCSOUND still unsupported --- src/engine/platform/pcspkr.cpp | 40 ++++++++++++++++++++++++++++------ src/engine/platform/pcspkr.h | 4 +++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/engine/platform/pcspkr.cpp b/src/engine/platform/pcspkr.cpp index eb201c1ec..54048f90e 100644 --- a/src/engine/platform/pcspkr.cpp +++ b/src/engine/platform/pcspkr.cpp @@ -19,10 +19,13 @@ #include "pcspkr.h" #include "../engine.h" +#include #include +#include #ifdef __linux__ #include +#include #include #include #endif @@ -112,14 +115,29 @@ void DivPlatformPCSpeaker::acquire_piezo(short* bufL, short* bufR, size_t start, } } -void DivPlatformPCSpeaker::acquire_real(short* bufL, short* bufR, size_t start, size_t len) { +void DivPlatformPCSpeaker::beepFreq(int freq) { #ifdef __linux__ + static struct input_event ie; + if (beepFD>=0) { + gettimeofday(&ie.time,NULL); + ie.type=EV_SND; + ie.code=SND_TONE; + ie.value=freq; + if (write(beepFD,&ie,sizeof(struct input_event))<0) { + perror("error while writing frequency!"); + } else { + //printf("writing freq: %d\n",freq); + } + } +#endif +} + +void DivPlatformPCSpeaker::acquire_real(short* bufL, short* bufR, size_t start, size_t len) { if (lastOn!=on || lastFreq!=freq) { lastOn=on; lastFreq=freq; - ioctl(STDOUT_FILENO,KIOCSOUND,on?freq:0); + beepFreq((on && !isMuted[0])?freq:0); } -#endif for (size_t i=start; i=0) close(beepFD); +#endif } DivPlatformPCSpeaker::~DivPlatformPCSpeaker() { diff --git a/src/engine/platform/pcspkr.h b/src/engine/platform/pcspkr.h index 6197098a4..82e0f461d 100644 --- a/src/engine/platform/pcspkr.h +++ b/src/engine/platform/pcspkr.h @@ -53,7 +53,7 @@ class DivPlatformPCSpeaker: public DivDispatch { Channel chan[1]; bool isMuted[1]; bool on, flip, lastOn; - int pos, speakerType; + int pos, speakerType, beepFD; float low, band; float low2, high2, band2; float low3, band3; @@ -62,6 +62,8 @@ class DivPlatformPCSpeaker: public DivDispatch { friend void putDispatchChan(void*,int,int); + void beepFreq(int freq); + void acquire_unfilt(short* bufL, short* bufR, size_t start, size_t len); void acquire_cone(short* bufL, short* bufR, size_t start, size_t len); void acquire_piezo(short* bufL, short* bufR, size_t start, size_t len);