Files
kaizen/external/SDL/test/testsurround.c
T
iris 00cc9309cb Squashed 'external/ircolib/' changes from ce3cd726c..de6e324bd
de6e324bd separate emu thread
10d3daf86 Roms List improvements
95d202f37 Let's make the rom list process on a separate thread so the emulator doesnt take ages to load.
fc306967f Wow the ROM Header was just completely busted. Game list view works now
bad1691ee fuck this shit
2b59e5f46 game list in progress
d26417b83 remappable inputs in progress
ac4af8106 input
e72abc240 update readme
430139dc9 Qt6 frontend
3080d4d45 Fix this small bug too
08cd13b85 Cop0 unused functions do not actually pose a threat (as per manual). They don't do anything, so shall we.
61bb4fb44 make idle loop detection a little more specific with where the load goes
b037de4c3 SAZDFsdff
12e81e73e need to figure out why n64-systemtest loops indefinitely at some address that appears to be valid (i think it's me not invalidating the cache properly)
204f0e13b idle skipping seems to work!
cb8bb634a sdkfjlasdf
58e5c89c1 Fix compilation issue on my machine (no idea)
24fb2898e attempting more serious idle skipping
214719577 Place rsp.Step inside cached interpreter. Gains about 3 more fps
bb97dcc23 mmmmm
920b77d38 wjkhasdfjhkasdf
430ccdab4 it's a start...
4f42a673a Cached interpreter plays Mario 64. Start looking into RSP as well
c9a030787 idle skipping works!
5fbda03ce new idea
366637aba Idle skipping... maybe?
609fa2fb0 Cache instructions implemented but broken lmao. Commented out for now
e140a6d12 - Stop using inheritance for CPU, instead use composition. - Introduce KAIZEN_JIT_ENABLED optional define instead of relying on __aarch64__ and the like. - More cache work
68e613057 prep cache impl
811b4d809 fix clang format
fda755f7d idk
d5024ebbf small MI refactor in preparation of (eventually) implementing the RDRAM interface properly
694b45341 Merge commit '206dcdedf195fb320913584180edb12c7731e396' as 'external/SDL'
206dcdedf Squashed 'external/SDL/' content from commit 4d17b99d0a
4d16e1cb4 need to update sdl
848b19920 Fix compilation error
db61b5299 Merge commit 'e94a94559f28e49678fbcf72199a5258137b0fe9' as 'external/imgui'
e94a94559 Squashed 'external/imgui/' content from commit 02e9b8cac
52edb3757 need to update imgui
c1a705e86 Emulate weird JALR behaviour
4b4c32f4b Fix exception for "unusable COP1" in 4 instructions i missed accidentally (again)
df5828142 Bug putting 0s in the log everywhere
f8b580048 Make isviewer a sink to file
8241e9735 Fix exception for "unusable COP1" in 4 instructions i missed accidentally
b29715f20 small changes
d9a620bc1 make use of my new small utility library
0d1aa938e Add 'external/ircolib/' from commit 'ce3cd726c8df8388d554abf8bb55d55020eb4450'
e64eb40b3 Fuck git

git-subtree-dir: external/ircolib
git-subtree-split: de6e324bde
2026-06-15 11:56:38 +02:00

283 lines
8.0 KiB
C

/*
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
/* Program to test surround sound audio channels */
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
static int total_channels;
static int active_channel;
#define SAMPLE_RATE_HZ 48000
#define QUICK_TEST_TIME_MSEC 100
#define CHANNEL_TEST_TIME_SEC 5
#define MAX_AMPLITUDE SDL_MAX_SINT16
#define SINE_FREQ_HZ 500
#define LFE_SINE_FREQ_HZ 50
/* The channel layout is defined in SDL_audio.h */
static const char *get_channel_name(int channel_index, int channel_count)
{
switch (channel_count) {
case 1:
return "Mono";
case 2:
switch (channel_index) {
case 0:
return "Front Left";
case 1:
return "Front Right";
}
break;
case 3:
switch (channel_index) {
case 0:
return "Front Left";
case 1:
return "Front Right";
case 2:
return "Low Frequency Effects";
}
break;
case 4:
switch (channel_index) {
case 0:
return "Front Left";
case 1:
return "Front Right";
case 2:
return "Back Left";
case 3:
return "Back Right";
}
break;
case 5:
switch (channel_index) {
case 0:
return "Front Left";
case 1:
return "Front Right";
case 2:
return "Low Frequency Effects";
case 3:
return "Back Left";
case 4:
return "Back Right";
}
break;
case 6:
switch (channel_index) {
case 0:
return "Front Left";
case 1:
return "Front Right";
case 2:
return "Front Center";
case 3:
return "Low Frequency Effects";
case 4:
return "Back Left";
case 5:
return "Back Right";
}
break;
case 7:
switch (channel_index) {
case 0:
return "Front Left";
case 1:
return "Front Right";
case 2:
return "Front Center";
case 3:
return "Low Frequency Effects";
case 4:
return "Back Center";
case 5:
return "Side Left";
case 6:
return "Side Right";
}
break;
case 8:
switch (channel_index) {
case 0:
return "Front Left";
case 1:
return "Front Right";
case 2:
return "Front Center";
case 3:
return "Low Frequency Effects";
case 4:
return "Back Left";
case 5:
return "Back Right";
case 6:
return "Side Left";
case 7:
return "Side Right";
}
break;
default:
break;
}
SDLTest_AssertCheck(false, "Invalid channel_index for channel_count: channel_count=%d channel_index=%d", channel_count, channel_index);
SDL_assert(0);
return NULL;
}
static bool is_lfe_channel(int channel_index, int channel_count)
{
return (channel_count == 3 && channel_index == 2) || (channel_count >= 6 && channel_index == 3);
}
static void SDLCALL fill_buffer(void *userdata, SDL_AudioStream *stream, int len, int totallen)
{
const int samples = len / sizeof(Sint16);
Sint16 *buffer = NULL;
static int total_samples = 0;
int i;
/* This can happen for a short time when switching devices */
if (active_channel == total_channels) {
return;
}
buffer = (Sint16 *) SDL_calloc(samples, sizeof(Sint16));
if (!buffer) {
return; /* oh well. */
}
/* Play a sine wave on the active channel only */
for (i = active_channel; i < samples; i += total_channels) {
float time = (float)total_samples++ / SAMPLE_RATE_HZ;
int sine_freq = is_lfe_channel(active_channel, total_channels) ? LFE_SINE_FREQ_HZ : SINE_FREQ_HZ;
int amplitude;
/* Gradually ramp up and down to avoid audible pops when switching between channels */
if (total_samples < SAMPLE_RATE_HZ) {
amplitude = total_samples * MAX_AMPLITUDE / SAMPLE_RATE_HZ;
} else if (total_samples > (CHANNEL_TEST_TIME_SEC - 1) * SAMPLE_RATE_HZ) {
amplitude = (CHANNEL_TEST_TIME_SEC * SAMPLE_RATE_HZ - total_samples) * MAX_AMPLITUDE / SAMPLE_RATE_HZ;
} else {
amplitude = MAX_AMPLITUDE;
}
buffer[i] = (Sint16)(SDL_sin(6.283185f * sine_freq * time) * amplitude);
/* Reset our state for next callback if this channel test is finished */
if (total_samples == CHANNEL_TEST_TIME_SEC * SAMPLE_RATE_HZ) {
total_samples = 0;
active_channel++;
break;
}
}
SDL_PutAudioStreamData(stream, buffer, samples * sizeof (Sint16));
SDL_free(buffer);
}
int main(int argc, char *argv[])
{
SDL_AudioDeviceID *devices;
SDLTest_CommonState *state;
int devcount = 0;
int i;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
return 1;
}
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
SDLTest_CommonQuit(state);
return 1;
}
if (!SDL_Init(SDL_INIT_AUDIO)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError());
return 1;
}
/* Show the list of available drivers */
SDL_Log("Available audio drivers:");
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
}
SDL_Log("Using audio driver: %s", SDL_GetCurrentAudioDriver());
devices = SDL_GetAudioPlaybackDevices(&devcount);
if (!devices) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioPlaybackDevices() failed: %s", SDL_GetError());
}
SDL_Log("Available audio devices:");
for (i = 0; i < devcount; i++) {
SDL_Log("%s", SDL_GetAudioDeviceName(devices[i]));
}
for (i = 0; i < devcount; i++) {
SDL_AudioStream *stream = NULL;
const char *devname = SDL_GetAudioDeviceName(devices[i]);
int j;
SDL_AudioSpec spec;
SDL_Log("Testing audio device: %s", devname);
if (!SDL_GetAudioDeviceFormat(devices[i], &spec, NULL)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioDeviceFormat() failed: %s", SDL_GetError());
continue;
}
SDL_Log(" (%d channels)", spec.channels);
spec.freq = SAMPLE_RATE_HZ;
spec.format = SDL_AUDIO_S16;
/* These are used by the fill_buffer callback */
total_channels = spec.channels;
active_channel = 0;
stream = SDL_OpenAudioDeviceStream(devices[i], &spec, fill_buffer, NULL);
if (!stream) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_OpenAudioDeviceStream() failed: %s", SDL_GetError());
continue;
}
SDL_ResumeAudioStreamDevice(stream);
for (j = 0; j < total_channels; j++) {
const int sine_freq = is_lfe_channel(j, total_channels) ? LFE_SINE_FREQ_HZ : SINE_FREQ_HZ;
SDL_Log("Playing %d Hz test tone on channel: %s", sine_freq, get_channel_name(j, total_channels));
/* fill_buffer() will increment the active channel */
if (SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "SDL_TESTS_QUICK") != NULL) {
SDL_Delay(QUICK_TEST_TIME_MSEC);
} else {
SDL_Delay(CHANNEL_TEST_TIME_SEC * 1000);
}
}
SDL_DestroyAudioStream(stream);
}
SDL_free(devices);
SDL_Quit();
return 0;
}