Author Topic: PC Speaker output to sound card?  (Read 1793 times)

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #15 on: April 16, 2020, 08:23:28 pm »
It's very simple. If have have an exe MyApp.Exe, then do this:
exehdr /V MyApp.exe | find "imp"

It will list all the imports. If you find something like this:
REL OFF(32)  0014       imp DOSCALLS.286

then you know that this exe uses DosBeep.

You then run:
dllrname /N /Q MyApp.exe DOSCALLS=NEWCALLS

You then rerun:
exehdr /V MyApp.exe | find "imp"

Now it will show this:
REL OFF(32)  0014       imp NEWCALLS.286

and you will know that from now on, the new DosBeep Implementation will be called. It works the very same way to patch a DLL.

I have written this simple app, file bla.c:

#define INCL_BASE
#include <os2.h>

int main(int argc,char *argv[])
{
    DosBeep(1000,1000);
    return 0;
}

and build it with:
icc -Gm+ -Gd+ -Ge+ bla.c
dllrname /N /Q bla.exe DOSCALLS=NEWCALLS /* this does the interesting part */

When I now run bla.exe, I can hear the Beep via my Speakers driven by Uniaud or via the Speakers connected via Audio USB, whatever device I choose as the default WAV device (the default WAV device will be used to play the sound).

By the way: use my USBAUDIO.ZIP package to have everything to work with USB audio. And it also comes with a DLL that extends the Multimedia Setup Object to allow you to simply switch the default WAV device with a mouse click. Of course that works across the board, not only for the USB audio device but also for the UNIAUD device.

Lars


Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #16 on: April 16, 2020, 08:43:10 pm »
Ok, I now tested rhythm.exe.

Yes, there is a problem. The app issues DosBeep with a duration of only 1 ms in length (that's the minimum duration) and this happens at a potentially very high repetition rate.
Looks like the MMPM sound system cannot handle this when a play list is used (as I do, because it is easy to use in this case). The "play" call never finishes but fortunately Ctrl-C works ...

I might need to switch to DART to keep up with this speed. I'll give that a try. In the meantime, try to run rhythm.exe with a slow beats per minute rate to test if it works in principle.

EDIT: it does not work even with a slow rate. What I can see is that this SW runs a high prio thread, potentially for sound output. That makes it likely that DART will have to be used in order to cope with the high generation rate that is necessary.

Lars
« Last Edit: April 16, 2020, 09:22:04 pm by Lars »

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #17 on: April 16, 2020, 09:17:37 pm »
I also looked at os2snd2. Yes, it does not use DosBeep. Instead it uses an incredibly bad hack and directly tries to program the PIT. That is what DosBeep would do anyway. Because DosBeep is not used, it cannot be replaced. It is not possible to patch this SW.

OS4User

  • Full Member
  • ***
  • Thank You
  • -Given: 42
  • -Receive: 7
  • Posts: 235
    • View Profile
Re: PC Speaker output to sound card?
« Reply #18 on: April 17, 2020, 10:12:07 am »
It will list all the imports. If you find something like this:
REL OFF(32)  0014       imp DOSCALLS.286

Hi Lars

do not forget  Dos16Beep   (DOSCALLS.50)

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #19 on: April 17, 2020, 12:03:41 pm »
It will list all the imports. If you find something like this:
REL OFF(32)  0014       imp DOSCALLS.286

Hi Lars

do not forget  Dos16Beep   (DOSCALLS.50)

I was too lazy to think about issues like thunking (and even more involved: changing the process type to PM and using 32-bit PM to show a message box) but I guess you are right. I'll just need to hack together a good old 16-bit app to test if it properly works.
« Last Edit: April 17, 2020, 12:09:36 pm by Lars »

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #20 on: April 17, 2020, 08:29:07 pm »
By now I have found out under what conditions my implementatiion of DosBeep will currently hang:

There is file SPI.INI in directory \MMOS2 that defines for each DATATYPE/SUBTYPE (this combination defines a triple of sampling rate,bit resolution, number of channels) how many buffers needs to be filled as a minimum and also the minimum size of each of those buffers.

I have now reworked NEWCALLS.DLL to play a sound with a minimum length that results out of those settings even if that is slightly longer than the requested duration (it is impossible for a human to notice a difference between 1 ms and 50 ms).
Find attached.

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #21 on: April 17, 2020, 09:11:15 pm »
 A new update, now DOS16BEEP (the 16-bit counterpart of DosBeep) is also supported.

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #22 on: April 17, 2020, 09:55:14 pm »
Here is some test code and the build batch file building a 32-bit and also a 16-bit version of the test exe:
bla.c
Code: [Select]
#define INCL_BASE
#include <os2.h>

#include <stdio.h>

int main(int argc,char *argv[])
{
    printf("Hallo!\n");
    DosBeep(800,1000);
    return 0;
}

the build batch file (adapt where necessary):
Code: [Select]
@echo off
setlocal

echo Building 32-bit executable...
icc.exe -Q -Gm+ -Gd+ -Ge+ -G5 -Ti -C bla.c
ilink.std -NOL -DE -DB -M -E:2 -NOPACKC -BAS:0x10000 -ST:0x8000 -PM:VIO -O:bla.exe bla.obj
dllrname.exe /Q /N bla.exe CPPOM30=OS2OM30 DOSCALLS=NEWCALLS

echo Building 16-bit executable...
SET PATH=d:\ddk\base\tools;%PATH%
SET INCLUDE=d:\ddk\base\h
SET LIB=d:\ddk\base\lib
cl.exe /nologo /AS /Od /G2 /Zi /Zl /c bla.c
link.exe /NOL /BATCH /CO /NOD /MAP /EXE /ST:0x8000 /PM:VIO bla.obj,bla16.exe,,os2286.lib+slibcep.lib;
dllrname.exe /Q /N bla16.exe DOSCALLS=NEWCALLS

endlocal

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 469
  • -Receive: 95
  • Posts: 2656
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: PC Speaker output to sound card?
« Reply #23 on: April 18, 2020, 01:32:44 am »
Hi Lars

I found this sample awesome. What do you think if we document your sample like the attached package?
I just consolidated the things on the thread on the readme.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #24 on: April 18, 2020, 02:49:41 am »
Need to brush up everything once more.
But sure, document as you like. I can also put this stuff on Hobbes if wanted.

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #25 on: April 18, 2020, 11:44:08 am »
Ok, I am now done. Find attached. I just updated your ZIP. Also uploaded to Hobbes.
« Last Edit: April 18, 2020, 12:05:18 pm by Lars »

Lars

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 51
  • Posts: 552
    • View Profile
Re: PC Speaker output to sound card?
« Reply #26 on: April 19, 2020, 04:39:26 pm »
Oops, required a fix for the 16-bit version. Also uploaded to Hobbes.