skjelten / emusc

A software synthesizer emulating the Sound Canvas SC-55 lineup
GNU General Public License v3.0
194 stars 15 forks source link

Sound buffer issue and possble lag? #3

Open ThatRetroGuy opened 2 years ago

ThatRetroGuy commented 2 years ago

The software work's great in the start and seems alright, but if there come's multiple instruments's, it will eventually crackle and pop in the audio, is that being worked on? it could be a memory issue in likely plausible cause.

I know somebody on discord who would gladly aid with a real sc 55.

skjelten commented 2 years ago

What OS are you using? I just noticed that this problem is especially problematic on Windows. Since all development is done on Linux it can be weeks or even months between each time I check the windows build.

My first guess is that we for some reason get buffer underruns in the audio output driver when multiple tones are played at the same time. This problem might have been there all the time and just become more noticeable now with longer tones due to the volume envelopes that was just added. I will have a look at it and see if I can figure out a solution.

ThatRetroGuy commented 2 years ago

Hello! im using windows, its my main daily driver system, would there need to be a separate dev build going for window's? wish I could help on that occasion, but yes, on window's audio start's to lag badly, I'm open we can discuss further on discord, the issue at hand.

a good bunch of the instruments are also out of tune, but you are getting that fixed to?

skjelten commented 2 years ago

I'm pretty sure we won't need any separate build environment for Windows. I also think I have the information I need to work on this particular issue, so I'll give an update when I have figured out something.

ThatRetroGuy commented 2 years ago

thats great to hear on the issue being worked about, did you know somebody on here has worked on some sound canvas screen simulation?

ThatRetroGuy commented 2 years ago

Also here's an recording from a native windows 10 machine I did not to long ago, performance is a bit choppy in some place's mario express.zip

Kappa971 commented 2 years ago

thats great to hear on the issue being worked about, did you know somebody on here has worked on some sound canvas screen simulation?

I'm not an expert, but for me it is already fantastic that this emulator is able to emit sounds (considering that until now nobody has ever worked in a Roland SC-55 emulator) and, according to my ears, I'm sure they are still missing all effects like reverb and chorus and who knows how much other stuff, in addition to the wrong "tone" of many instruments (I don't know the technical name). As already said, it is comforting that someone is working on it and maybe in a few years we will finally have an accurate and fully functional emulator. Thanks @skjelten

ts-korhonen commented 2 years ago

It seems to be a problem when building 32bit executable (msys2, i686-w64-mingw32) while with the 64bit build (x86_64-w64-mingw32) the problem is not present.

edit: clarification; the problem being popping sound. The "lag" is still present, though to my ear it sounds like imprecise timing so maybe the timer method needs to be different on Windows etc.

Kappa971 commented 2 years ago

It seems to be a problem when building 32bit executable (msys2, i686-w64-mingw32) while with the 64bit build (x86_64-w64-mingw32) the problem is not present.

edit: clarification; the problem being popping sound. The "lag" is still present, though to my ear it sounds like imprecise timing so maybe the timer method needs to be different on Windows etc.

Try Duke Nukem 3D midis and you'll hear the pops even with the 64-bit build. However, I think the emulator is still incomplete, the project is very recent, so it seems obvious to me that there are problems... we could probably define it as an alpha.

ts-korhonen commented 2 years ago

you'll hear the pops even with the 64-bit build

Ok. But the build architecture still has significant impact on my end. With Roland SC demo midis they go from very prominent to unnoticeable.

the emulator is still incomplete, the project is very recent, so it seems obvious to me that there are problems

Of course. I'm not complaining, only trying to provide extra information to help diagnose the problems 😃

ThatRetroGuy commented 2 years ago

It seems to be a problem when building 32bit executable (msys2, i686-w64-mingw32) while with the 64bit build (x86_64-w64-mingw32) the problem is not present. edit: clarification; the problem being popping sound. The "lag" is still present, though to my ear it sounds like imprecise timing so maybe the timer method needs to be different on Windows etc.

Try Duke Nukem 3D midis and you'll hear the pops even with the 64-bit build. However, I think the emulator is still incomplete, the project is very recent, so it seems obvious to me that there are problems... we could probably define it as an alpha.

I think your talking about the old post, in its latest update the synth works really well, even with duke nukem 3d midi's, the popping is gone as well.

Kappa971 commented 2 years ago

I think your talking about the old post, in its latest update the synth works really well, even with duke nukem 3d midi's, the popping is gone as well.

It is strange because it seems to me that no changes have been made since yesterday. Placebo effect? 😅 I tried this emulator today and, considering how young the project is, it is very promising but far from perfect, many instruments sound bad, as well as pops in some midi like those of Duke Nukem 3D, perhaps because they are among the most complex and that make perfect use of the real SC-55. I think some effects like reverb are still missing as well. It is currently not ready, let @skjelten work in peace (and who will join him) 🙂

There are these forums for any discussions: https://www.doomworld.com/forum/topic/118828-trevor0402s-sc-55-soundfont/?page=5

https://www.vogons.org/viewtopic.php?f=62&t=76613&start=340

ThatRetroGuy commented 2 years ago

it was my soft synth player which had changed to default midi player for some reason, lol.

skjelten commented 2 years ago

Hi, could you guys test the latest code update for whether you still have issues with crackle and pop in the audio?

I have not been able to figure out how to recover in windows when you have a buffer underrun situation, but I did find two memory bugs that gave wrong sample data. If you now can play MIDI files correctly also in windows, we'll just close this issue for now.

ThatRetroGuy commented 2 years ago

Hello, i''l get to the code testing when i can eventually, will post further when gotten it compiled.

ThatRetroGuy commented 2 years ago

Its definitely an improvement over the previous compile,, it doesn't struggle playing some midi's now it had trouble playing a while back, now the instruments just out of tune, it just needs the echo and chrous, then should be complete. but I get this note limit error on the prompt line, I'm guessing that's a issue going to be fixed eventually.

ts-korhonen commented 2 years ago

I think the 64bit build is now as functional as can be assumed in this stage.

The 32bit build no longer does the popping and crackling, but a complex song will make it stutter and lag.

Kappa971 commented 2 years ago

Thanks @skjelten, I haven't had the chance to test the new build on Windows yet, I will do it as soon as possible.

I tested it on Debian 11, no crackle or pop here (as before). I would recommend you test this emulator with Duke Nukem 3D midis, as they are quite complex and I have noticed that some songs push the polyphony of the original SC-55 to the limit: Duke3D_MIDI.zip.

For example 08 - Episode 1 - Ah, Geez! [Lee Jackson].mid, EmuSC displays: New note on ignored due to SC55 voice limit (24). 17 - Episode 2 - Alfred H. (My Family's Plot) [Lee Jackson].mid instead displays: Illegal program for drum set (1) I haven't tried them all.

it just needs the echo and chrous, then should be complete.

@ThatRetroGuy, I'm neither an expert nor a programmer or musician, but I don't think it's that simple. I noticed, thanks to this emulator, how much the SC-55 processes the samples of the instruments contained in the ROM. I have absolutely no idea what the SC-55 does to make those instruments sound right, but without any processing, you notice how bad they can sound, and this I think is not just the lack of the reverb or chorus effect.

ThatRetroGuy commented 2 years ago

@ThatRetroGuy, I'm neither an expert nor a programmer or musician, but I don't think it's that simple. I noticed, thanks to this emulator, how much the SC-55 processes the samples of the instruments contained in the ROM. I have absolutely no idea what the SC-55 does to make those instruments sound right, but without any processing, you notice how bad they can sound, and this I think is not just the lack of the reverb or chorus effect.

Im not saying its reverb or chorus that's gonna do the job, I noticed how strange it makes the fretless bass sound, but I'm sure there gets figured a progress out.

Kappa971 commented 2 years ago

The problem of crackles and pops seems solved on Windows, I happened to hear pops but only in some instruments that have a completely unbalanced volume and are probably "cropped" (in fact EmuSC displays Warning - audio clipped (too loud)). However, I notice that with some midi it seems that the emulator "stutters", it loses the rhythm of the music. There is this Duke Nukem 3D midi (28 - Episode 3 - Urban Jungle [Lee Jackson].mid) that literally puts him in crisis. Even in grabbag (intro music) it seems to miss "a few hits"

skjelten commented 1 year ago

Three weeks ago I finally managed to improve the WIN32 audio output (see 1bcbec9304a5b08444f6fea9a1d4dc74895b5037) so that if we get a buffer underrun situation, EmuSC will automatically recover as soon as it manages to feed enough audio data again.

The other issue of EmuSC limiting the number of simultaneous sounds (polyphony) is related to the TVA (volume) envelopes being too long. When sounds stay too long in sustain / release phase you quickly end up with too many simultaneous sounds for MIDI files that pushes the maximum polyphony of the SC55. The fix here is to correctly calculate to TVA envelope times for each phase, but that is harder than it sounds like :slightly_smiling_face: