Sound fo the IDE

Description of your first forum.
Post Reply
bzuidgeest
Posts: 41
Joined: Wed May 01, 2019 6:51 pm

Sound fo the IDE

Post by bzuidgeest » Mon Sep 02, 2019 10:33 pm

Hello All,

Now A quick word on my other project for the IDE (beside ch376 support). I wanted to try to add sound. In my opinion sound, storage and video are the basic ingredients to build a "game" on.
Again a project that has me playing with something I now nothing about. Sound chips. It's always interesting to try something new. However I am somewhat adverse to reinventing the wheel so I started looking for code of an OPL emulator that could be converted to C# and fit the architecture of the IDE.
The dosbox OPL code seemed most promising. It's clearly functional and has not been touched significantly for years. After looking around, I choose to use the version contained in scummvm. One of the reason was that it is part of a larger set of emulations for several popular chips. Another was that scummvm actually has (in the authors own words) a quick and dirty c# conversion.
So I lifted the code and made a simple console app to try playing an imf file. This was unfortunately met with a recognizable but somewhat distorted sound. The sound seems to repeatedly drop off suddenly. At first I thought I did not fill the buffers properly but opening the result in a wave editor showed that the wave never really stops. It just gets very small and simple.
Having no experience with the chip to draw a proper diagnosis from I then decided that the conversion might be faulty and decided to redo it. Unfortunately that resulted in the same code, more or less, and the same sound.
The scummvn C version however has a somewhat recent addition of the Nuked OPL3 emulator. So I decided to port that one. It's surprisingly easy compared to the messy dosbox code. Dosbox took more than a day to do, but nuked took only a few hours. Dropped it in my console testapp with the same imf file and surprise! Complete and utter silence. All zeros on the samples.
Next was trying to make a C console app with the original nuked code to compare to. And strangely that also produces no samples (though it does show very small int values they might as wel be zero). Nuked its used widely in doom source ports. So again it clearly should work.
So at this point I have two conclusions. I'm not using the emulator code/cores correctly or there is something wrong with my ports.

I will be doing two things. One I will be ordering an opl3lpt so I have a real chip to talk to. Would also be nice to support that as a hardware option next to a softsynth in the IDE for the purists. Second I will be looking for someone that can supply me with the most basic and simple known working command set possible that makes an opl3 chip output a simple sine wave. I can than use that to test out the emulation code.

So any OPL experts on board?

p.s. Also tried porting the java opl code from cozendey. Same silence when running, though this was such a quick an dirty conversion it might just be my code in that case. It's also very old so I rather had one of the more new emulations ported over so I did not pay much attention to it.
p.s. I included a sample wav of the dosbox emulation as a zipped wav file. The first part is almost all shorter sounds but almost to the end there are some longer sound parts.
Attachments
test.7z
sample
(410.25 KiB) Not downloaded yet
bzuidgeest
Posts: 41
Joined: Wed May 01, 2019 6:51 pm

Re: Sound fo the IDE

Post by bzuidgeest » Sun Sep 08, 2019 4:04 pm

Did some further tests today. I found some information on doing a simple frequency sweep on the opl. Turns out that actually works. Got a nice stable beep in my speakers. Now I have to figure out what part of the emulation fails when actually trying to play opl music files. So more tests to do.
My opl3lpt has not arrived yet. I really hoped to have it this weekend...
bzuidgeest
Posts: 41
Joined: Wed May 01, 2019 6:51 pm

Re: Sound fo the IDE

Post by bzuidgeest » Sun Sep 08, 2019 8:13 pm

Did some more fiddling. tested playing two DRO file. phemopop.dro sound almost fine. Maybe quite acceptable when working on a simulator. However strickeforce.dro sounds quite bad. As a non musician comparing it to other players out there it seems that strikeforce is a much faster song. It almost feels to me like I'm dropping samples or something like that. Might have something to do with the thread I'm using to control the opl on one side and pull audio samples out on the other. Faster elements like percussion seems to suffer most...

I included two samples I anybody is interested in actually hearing what I am talking about :)
Attachments
samples.7z
(377.27 KiB) Downloaded 6 times
User avatar
drone84
Posts: 9
Joined: Sat Apr 13, 2019 2:05 pm
Location: On Earth

Re: Sound fo the IDE

Post by drone84 » Sun Sep 08, 2019 9:14 pm

Nice I like the first sound. I cant tell you about the speed for strikeforce but it sound weird
Give me anything with electronic and I will make it crash/bug
bzuidgeest
Posts: 41
Joined: Wed May 01, 2019 6:51 pm

Re: Sound fo the IDE

Post by bzuidgeest » Tue Sep 10, 2019 2:49 pm

Yeah, I have an idea about that but I have not been able to test it out yet.
At the moment I am feeding the "chip" in one thread and yanking out samples to an audio stream on another thread. I thought I could do this because the opl2 is a continuous generator (it does not stop/change the sound without a new command after one is given).
However I think I failed to account for the speed at which and the size of the audio buffers that get requested by the audio device. I think its requesting buffers that are larger than what should fit between song commands. The more rapid the changes in a song (percussion) the worse the effect would get I think. It should explain my current results with the percussion heavy "strikeforce" sounding worse than the more sine heavy pemp..somthing.

For adlib songs number of samples between commands can be calculated, so I should be able to get perfect output. However in the IDE I do not know how many "ticks" between commands. I do not know how dosbox does it, but I suspect it uses many small sample buffers based on computer ticks instead of fewer larger ones. .Net is far from real-time, but neither is cpp on windows. I should be able to get it to more or less sound right if I time the sample generation properly (and did not make wrong conclusions in this reasoning ;).

We will see, but might be next weekend before I get some time again.
bzuidgeest
Posts: 41
Joined: Wed May 01, 2019 6:51 pm

Re: Sound fo the IDE

Post by bzuidgeest » Wed Sep 11, 2019 7:51 pm

Had some time and adjusted the rate and time for buffer request to the virtual adlib. Rendering the samples to disk so mistakes with the audio pipeline where excluded.
Both songs now sound perfectly
Attachments
timingtest.zip
(289.73 KiB) Downloaded 8 times
User avatar
drone84
Posts: 9
Joined: Sat Apr 13, 2019 2:05 pm
Location: On Earth

Re: Sound fo the IDE

Post by drone84 » Thu Sep 12, 2019 5:51 pm

I love that sound :mrgreen: ... the 80/90s smell
Give me anything with electronic and I will make it crash/bug
User avatar
techristian
Posts: 14
Joined: Mon Apr 15, 2019 1:39 am
Location: Windsor, Ontario
Contact:

Re: Sound fo the IDE

Post by techristian » Wed Sep 18, 2019 4:17 pm

Ever try and add all of the channels and sound devices together to produce ONE FAT synth sound ?

Dan
Post Reply