From 31d16e714feeb6597773a20008b39c60e6d903c4 Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Sun, 6 Apr 2025 12:25:30 +0200 Subject: [PATCH] Add untested preliminary audio backend for Solaris --- src/Backends/Audio/SoftwareMixer/Solaris.cpp | 88 ++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/Backends/Audio/SoftwareMixer/Solaris.cpp diff --git a/src/Backends/Audio/SoftwareMixer/Solaris.cpp b/src/Backends/Audio/SoftwareMixer/Solaris.cpp new file mode 100644 index 00000000..c8a3999f --- /dev/null +++ b/src/Backends/Audio/SoftwareMixer/Solaris.cpp @@ -0,0 +1,88 @@ +// Released under the MIT licence. +// See LICENCE.txt for details. + +#include "Backend.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int sndfp; +void (*parent_callback)(long *stream, size_t frames_total); + +static void* soundcheckthread(void*) { + unsigned long for_as_long_as_it_seems_we_should = 0; + uint16_t out[0x400 * 2]; + while(1) { + bool ready = false; + audio_prinfo_t audioInfo; + ioctl(sndfp, AUDIO_GETINFO, &audioInfo); + int oldeof = audioInfo.eof; + + usleep(for_as_long_as_it_seems_we_should); + + while(ready == false) { + ioctl(sndfp, AUDIO_GETINFO, &audioInfo); + if(audioInfo.eof > oldeof) { + ready = true; + } + } + + long mix[0x400 * 2]; + memset(mix, 0, 0x400 * 2); + parent_callback(mix, 0x400 * 2); + + write(sndfp, mix, 0x400 * 2); + + for_as_long_as_it_seems_we_should = (0x400 / 48000) * 1000000; + } +} + +unsigned long SoftwareMixerBackend_Init(void (*callback)(long *stream, size_t frames_total)) { + sndfp = open("/dev/audio", 0, O_WRONLY); + + audio_prinfo_t audioInfo; + ioctl(sndfp, AUDIO_GETINFO, &audioInfo); + audioInfo.sample_rate = 48000; + audioInfo.channels = 2; + audioInfo.precision = 16; + audioInfo.encoding = AUDIO_ENCODING_LINEAR; + audioInfo.port = AUDIO_SPEAKER; + ioctl(sndfp, AUDIO_SETINFO, &audioInfo); + + pthread_t thread; + pthread_attr_t thread_attr; + pthread_attr_init(&thread_attr); + + pthread_create(&thread, &thread_attr, soundcheckthread, (void*)NULL); + + return 48000; // return the sampling rate +} + +void SoftwareMixerBackend_Deinit(void) { + close(sndfp); +} + +bool SoftwareMixerBackend_Start(void) { + return true; +} + +void SoftwareMixerBackend_LockMixerMutex(void) { +} + +void SoftwareMixerBackend_UnlockMixerMutex(void) { +} + +void SoftwareMixerBackend_LockOrganyaMutex(void) { +} + +void SoftwareMixerBackend_UnlockOrganyaMutex(void) { +}