How to play sound on two different DOSBoxes simultaneously?
Asked Answered
C

1

6

I have created the game "Angry Birds" in assembly 8086. My main problem now is that I want to play the song of the game while the main loop is running. I've already written the code for the music. I thought about using multi-threading but found out the assembly interrupt for creating threads only works on cmd and not on DOSBox.

However, I found another way of doing multi-threading, which was to call a command from the C++ Windows.h file, that creates a thread. That was too complicated.

Now, I have managed to communicate between two different DOSBox windows, using interrupt 14h for sending messages over LAN ports. Basically, I've written a separate code for the music. Both codes run and only when the music code gets the sign, it starts playing the music.

However, I found out that when two DOSBox windows are open, only the sound of the main one works. You have to switch windows in order to hear the music, which means you can't hear it.

Does anyone have any idea of how I can solve this problem, or generally play music while the main loop is running?

Thank you

Carnatic answered 8/5, 2019 at 14:1 Comment(6)
no idea on the answer, but +1 from me for the determination and perseverance :)Clos
You don't have to create another thread (which is an OS concept) to play the music. SoundBlaster and similar support DMA. Also, games are usually interrupt driven, so you can eventually play the music in the "main thread".Journeywork
Out of curiosity what mechanism are you using to play sound? Through the PC speaker (simulated in DOSBox) or some sound card like Soundblaster (simulated in DosBOX) or something else?Antlia
The code could hook into timer 0 interrupt (INT 08), and change the frequency to a higher rate. To keep system time correct, the code pointed to by the INT 08, should be called once every 65536 cycles = 54.925 ms. The code could also create a mini multi-threaded kernel and use that.Stork
DOSBOX might have an option to enable sound even when it's in the background. It's probably muting itself intentionally. If there's no config option, DOSBOX is open-source so you could add one. (If you really want to make this remote-sound-server idea work instead of using a timer interrupt + audio mixing inside one program so it can run on a single (virtual) uniprocessor PC!)Scone
I'd like to play this game.Baldwin
I
1

As mentioned, you could use a multi-channel sound device (not specified in question, see the soundchip(s) docs for that) but the PWM based DOS speaker output is a single waveform output with no concept of second frequency unless you want to digitally merge PWM waveforms and output the merged data (going to be nasty work, possibly tens of microseconds between edges that you will have to bit stuff manually. DMA should work, but buffers are probably going to be large, which means the sound lag will be many milliseconds.

Iain answered 31/12, 2019 at 3:48 Comment(1)
Windows is probably simulating the sound device through API to HW translation. Not sure how hard that will be to reach in there.Iain

© 2022 - 2024 — McMap. All rights reserved.