Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds additional sound options #94

Merged
merged 1 commit into from
Oct 10, 2021

Conversation

neonloop
Copy link
Contributor

No description provided.

@inactive123 inactive123 merged commit 75c85fa into libretro:master Oct 10, 2021
@ghost
Copy link

ghost commented Oct 10, 2021

This will cause issue with game like tapper ect without updating the audio code.

@neonloop
Copy link
Contributor Author

@grant2258 isn't the behavior unchanged if the setting stays at default?

@ghost
Copy link

ghost commented Oct 10, 2021

we had to deal with this on 2003-plus we which we ported to mame 2003 let me double check its an issue

@ghost
Copy link

ghost commented Oct 10, 2021

yes its still an issue.

there are two things that can happen.

  1. The memory isint allocated properly for the sound buffer in certain conditions.
  2. the timing can be changed

for the examples start tapper with 32000 listen it broken
again with tapper
set 44100 start tapper again its running far too fast.

you need to restart after changing the sample rate.

ps the default was bad at 32000 no idea who changed it to that. it was always coded for 30000

ive pasted some code below you need to look at. See what I done in mame2003_plus for the sound if you want to port it over here.

22050 is a sweetspot for everything 30000 will get you there as well.

@ghost
Copy link

ghost commented Oct 10, 2021

int osd_start_audio_stream(int stereo)
{
usestereo = stereo ? 1 : 0;
/* determine the number of samples per frame */
samples_per_frame = Machine->sample_rate / Machine->drv->frames_per_second;
if (Machine->sample_rate == 0) return 0;
samples_buffer = (short *) calloc(samples_per_frame, 2 + usestereo * 2);
if (!usestereo) conversion_buffer = (short *) calloc(samples_per_frame, 4);
return samples_per_frame;
}
void osd_stop_audio_stream(void)
{
samples_per_frame = 0;
}
int osd_update_audio_stream(INT16 *buffer)
{
memcpy(samples_buffer, buffer, samples_per_frame * (usestereo ? 4 : 2));
hook_audio_done();
return samples_per_frame;
}

Machine->sample_rate = options.samplerate;

@neonloop
Copy link
Contributor Author

Yes, it was intended to require restart -- the option is only read in retro_load_game. Maybe there could still be a problem if a game is reloaded without reinitializing the core? I have not been able to test this because mame2000 will not run after unloading a game for me (libco_quit is set to 1 and never set back to 0)

I can continue to look into it, though...

@ghost
Copy link

ghost commented Oct 10, 2021

wget https://patch-diff.githubusercontent.com/raw/libretro/mame2000-libretro/pull/86.diff
git apply 86.diff

This segfaults most like causing your restart issues

you need to close the content as the sample rate isint re initialized on reload so you wouldnt notice the bug. ill look into sorting that out.

@neonloop
Copy link
Contributor Author

The restart issue comes from retro_unload_game

This sets libco_quit to 1

Then after loading a new game retro_run hits this check and stops doing work:

void retro_run(void)
{
int i, j;
#ifdef WANT_LIBCO
if(libco_quit==0)co_switch(core_thread);
else printf("running dead emulator");
#else
lock_mame();

Anyway, other than loading new game without reinit core I don't see how changing sound option would change active behavior, because core option value set by update_variables is only ever read in retro_load_game

But I haven't spent too much time with this code. So if there is a way to break it is OK to revert until a better way is found

@ghost
Copy link

ghost commented Oct 10, 2021

I know a bit about what going on in the mame end here.

[INFO] [Config]: Saved new config to "/home/grant/.config/retroarch/retroarch.cfg".
[INFO] [Core]: Content ran for a total of: 00 hours, 00 minutes, 01 seconds.
[INFO] [Core]: Unloading game..
running dead emulatorrunning dead emulatorrunning dead emulatorrunning dead emulatorrunning dead emulatorrunning dead emulatorrunning dead emulatorrunning dead emulatoresc pressed quit!

this is what happens with the patch above. It does close with no issues just shows you the message a few times.

without the segfault patch you get this
x619000007780 is located 0 bytes to the right of 1024-byte region [0x619000007380,0x619000007780)
allocated by thread T0 here:
#0 0x7f41d0134279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x7f41b5e90770 in retro_load_game (/home/grant/Source/mame2000-libretro/mame2000_libretro.so+0x74e770)

SUMMARY: AddressSanitizer: heap-buffer-overflow /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:740 in __interceptor_strrchr
Shadow bytes around the buggy address:
0x0c327fff8ea0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8eb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8ec0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8ed0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8ee0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c327fff8ef0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c327fff8f00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c327fff8f10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8f20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8f30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c327fff8f40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==39793==ABORTING

segfaults can be deceitful as to where the problem is. There is no need to revert just set the sample rate to 22050 of 30000 the patch above is needed causes segfaults all over the place. This segfault is unrelated to your code anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants