actually flycast had a bug that refused to play audio from kallistios-based programs...

This commit is contained in:
ecker 2026-07-27 07:24:14 -05:00
parent 9ac47e843f
commit d3d33383ec
6 changed files with 30 additions and 45 deletions

View File

@ -43,7 +43,11 @@ constexpr ctti::detail::cstring value()
#define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "ctti::detail::cstring ctti::pretty_function::type() [T = "
#define CTTI_TYPE_PRETTY_FUNCTION_SUFFIX "]"
#elif defined(__GNUC__) && !defined(__clang__)
#define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "constexpr ctti::detail::cstring ctti::pretty_function::type() [with T = "
#if __GNUC__ >= 16
#define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "ctti::detail::cstring ctti::pretty_function::type() [with T = "
#else
#define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "constexpr ctti::detail::cstring ctti::pretty_function::type() [with T = "
#endif
#define CTTI_TYPE_PRETTY_FUNCTION_SUFFIX "]"
#elif defined(_MSC_VER)
#define CTTI_TYPE_PRETTY_FUNCTION_PREFIX "struct ctti::detail::cstring __cdecl ctti::pretty_function::type<"
@ -60,7 +64,11 @@ constexpr ctti::detail::cstring value()
#define CTTI_VALUE_PRETTY_FUNCTION_SEPARATOR "; Value = "
#define CTTI_VALUE_PRETTY_FUNCTION_SUFFIX "]"
#elif defined(__GNUC__) && !defined(__clang__)
#define CTTI_VALUE_PRETTY_FUNCTION_PREFIX "constexpr ctti::detail::cstring ctti::pretty_function::value() [with T = "
#if __GNUC__ >= 16
#define CTTI_VALUE_PRETTY_FUNCTION_PREFIX "ctti::detail::cstring ctti::pretty_function::value() [with T = "
#else
#define CTTI_VALUE_PRETTY_FUNCTION_PREFIX "constexpr ctti::detail::cstring ctti::pretty_function::value() [with T = "
#endif
#define CTTI_VALUE_PRETTY_FUNCTION_SEPARATOR "; T Value = "
#define CTTI_VALUE_PRETTY_FUNCTION_SUFFIX "]"
#elif defined(_MSC_VER)

View File

@ -108,12 +108,21 @@
#define TYPE_SANITIZE(T) std::remove_cv_t<std::remove_reference_t<T>>
#if UF_CTTI
#if 0
#include <ctti/ctti.hpp>
#define TYPE_INDEX_T decltype(ctti::type_id_of<void>())
#define TYPE_HASH_T decltype(ctti::type_id_of<void>().hash())
#define TYPE(T) ctti::type_id_of<TYPE_SANITIZE(T)>()
#define TYPE_HASH(T) TYPE(T).hash()
#define TYPE_NAME(T) ctti::name_of<TYPE_SANITIZE(T)>()
#else
#include <ctti/type_id.hpp>
#define TYPE_INDEX_T ctti::type_id_t
#define TYPE_HASH_T ctti::detail::hash_t
#define TYPE(T) ctti::type_id<TYPE_SANITIZE(T)>()
#define TYPE_HASH(T) TYPE(T).hash()
#define TYPE_NAME(T) ctti::nameof<T>().str()
#endif
#else
#define TYPE_INDEX_T std::type_index
#define TYPE_HASH_T std::size_t

View File

@ -18,6 +18,7 @@ namespace impl {
typedef int (*fill_callback_t)(void* user_data, uint8_t* buffer, int req_bytes);
constexpr int STREAM_BUFFER_SIZE = 16384;
constexpr int DRIVER_BUFFER_SIZE = 65536;
constexpr size_t MAX_VIRTUAL_SOURCES = 256;
constexpr size_t MAX_VIRTUAL_BUFFERS = 1024;
@ -58,7 +59,6 @@ namespace impl {
mutex_t g_streamMutex = MUTEX_INITIALIZER;
void* kos_stream_callback( snd_stream_hnd_t hnd, int req_bytes, int* bytes_returned ) {
UF_MSG_DEBUG("[AICA] Requesting {} bytes", req_bytes);
auto it = g_activeStreams.find(hnd);
if ( it == g_activeStreams.end() ) {
*bytes_returned = 0;
@ -68,39 +68,14 @@ namespace impl {
impl::Buffer* buf = it->second;
if ( req_bytes > impl::STREAM_BUFFER_SIZE ) {
UF_MSG_WARNING("[AICA] Requesting more than buffer: {} > {}", req_bytes, impl::STREAM_BUFFER_SIZE);
req_bytes = impl::STREAM_BUFFER_SIZE;
}
// generate a sin wave for testing
// washdc plays this, albeit slowly because emulation speed is hindered
// flycast doesn't play audio, this callback gets called twice then never again
#if 1
float frequency = 440.0f;
float sample_rate = buf->frequency > 0 ? buf->frequency : 44100.0f;
int channels = (buf->format == AL_FORMAT_STEREO16 || buf->format == AL_FORMAT_STEREO8) ? 2 : 1;
int16_t* samples = (int16_t*)buf->stream_buffer;
int num_samples = req_bytes / sizeof(int16_t);
int half_period = (int)(sample_rate / (frequency * 2.0f));
static int sample_count = 0;
for( int i = 0; i < num_samples; i += channels ) {
int16_t sample_val = ((sample_count / half_period) % 2 == 0) ? 16000 : -16000;
samples[i] = sample_val;
if ( channels == 2 ) samples[i + 1] = sample_val;
sample_count++;
}
*bytes_returned = req_bytes;
#else
if ( buf->fill_callback && buf->user_data ) {
*bytes_returned = buf->fill_callback(buf->user_data, buf->stream_buffer, req_bytes);
} else {
*bytes_returned = 0;
}
#endif
if ( *bytes_returned == 0 ) return nullptr;
@ -281,7 +256,7 @@ void ext::al::Source::play() {
int pan = 128;
if ( buffer.aica_addr != 0 ) {
snd_sfx_play(buffer.aica_addr, vol, pan);
// snd_sfx_play(buffer.aica_addr, vol, pan); // earrape
} else if ( buffer.stream_hnd != SND_STREAM_INVALID ) {
int channels = (buffer.format == AL_FORMAT_STEREO16 || buffer.format == AL_FORMAT_STEREO8) ? 1 : 0;
@ -471,7 +446,7 @@ void ext::al::Buffer::buffer( ALuint index, ALenum format, const ALvoid* data, A
UF_MSG_ERROR("[AICA] Failed to allocate {} bytes", impl::STREAM_BUFFER_SIZE);
return;
}
buffer.stream_hnd = snd_stream_alloc( impl::kos_stream_callback, impl::STREAM_BUFFER_SIZE );
buffer.stream_hnd = snd_stream_alloc( impl::kos_stream_callback, impl::DRIVER_BUFFER_SIZE );
if ( buffer.stream_hnd == SND_STREAM_INVALID ) {
UF_MSG_ERROR("[AICA] Failed to allocate {} bytes", impl::STREAM_BUFFER_SIZE);
return;

View File

@ -568,7 +568,10 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer::
GL_ERROR_CHECK(glEnableClientState(GL_COLOR_ARRAY));
::shadowState.colorArrayEnabled = true;
}
GLenum colorType = (drawInfo.attributes.color.descriptor.size / drawInfo.attributes.color.descriptor.components == sizeof(uint8_t)) ? GL_UNSIGNED_BYTE : GL_FLOAT;
GLenum colorType = GL_FLOAT;
if ( drawInfo.attributes.color.descriptor.type == uf::renderer::enums::Type::UBYTE || drawInfo.attributes.color.descriptor.size == sizeof(uint8_t)) {
colorType = GL_UNSIGNED_BYTE;
}
GL_ERROR_CHECK(glColorPointer(drawInfo.attributes.color.descriptor.components, colorType, drawInfo.attributes.color.stride, colorPtr));
} else if ( ::shadowState.colorArrayEnabled ) {
GL_ERROR_CHECK(glDisableClientState(GL_COLOR_ARRAY));
@ -598,9 +601,9 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer::
}
GL_ERROR_CHECK(glTexCoordPointer(2, uvType, uvStride, uvPtr));
GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, drawInfo.attributes.color.pointer ? GL_MODULATE : GL_REPLACE));
//GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, drawInfo.attributes.color.pointer ? GL_MODULATE : GL_REPLACE));
// washdc works fine, flycast renders nothing if GL_MODULATE is set, although GL_REPLACE just renders the background
//GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE));
GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE));
} else {
if ( ::shadowState.tex0Enabled ) {
GL_ERROR_CHECK(glClientActiveTexture(GL_TEXTURE0));
@ -677,12 +680,6 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer::
GL_ERROR_CHECK(glDrawArrays(mode, drawInfo.descriptor.inputs.vertex.first, drawInfo.descriptor.inputs.vertex.count));
}
if ( drawInfo.descriptor.inputs.index.count ) {
GL_ERROR_CHECK(glDrawElements(mode, drawInfo.descriptor.inputs.index.count, indicesType, (static_cast<uint8_t*>(drawInfo.attributes.index.pointer) + drawInfo.attributes.index.stride * drawInfo.descriptor.inputs.index.first)));
} else {
GL_ERROR_CHECK(glDrawArrays(mode, drawInfo.descriptor.inputs.vertex.first, drawInfo.descriptor.inputs.vertex.count));
}
GL_ERROR_CHECK(glDisableClientState(GL_VERTEX_ARRAY));
}
#endif

View File

@ -3,11 +3,7 @@
#include <uf/utils/renderer/renderer.h>
#include <uf/ext/openvr/openvr.h>
#if UF_ENV_DREAMCAST
bool uf::matrix::reverseInfiniteProjection = false;
#else
bool uf::matrix::reverseInfiniteProjection = true;
#endif
bool uf::matrix::reverseInfiniteProjection = true;
pod::Vector3f uf::camera::eye( const pod::Camera& camera, int i ) {
if ( i < 0 ) i = 0;

View File

@ -9,7 +9,7 @@ FLAGS += -fdiagnostics-color=always
# MSYS2
INCS += -I/mingw64/include/
LIBS += -I/mingw64/lib/
LIBS += -L/mingw64/lib/
TARGET_EXTENSION = .exe
DLIB_EXTENSION = .dll