Thread: Need help with audio library on DOS...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    4

    Need help with audio library on DOS...

    Hi all,

    I am facing what is for me a really complicated situation. I program C but not this advanced (I mean direct hardware access etc).
    Here is the background:
    I am using DJGPP.
    I am programming a DOS program that will play wave files on certain functions (moving through the menus, running functions, etc)
    Today's motherboards come with AC97 sound boards that do not have drivers compatible with DOS.
    MAME (a videogame emulator) does have a library that uses the AC97 boards with no problems. It is named WSS and is made by Shigeaki Sakamaki (the email address of the author is unknown)
    I managed to make a standalone DOS wav player using the library. It works perfectly.
    I like to add the WSS library to the SEAL Audio library, which is another neat audio library that also has a mixer, filters and etc, and has functions for everything I need on my program. SEAL is here: http://www.sonicspot.com/sealsdk/sealsdk.html
    Here comes my problem:
    I added WSS to the SEAL library and it sounds, but SLOWLY, it looks as it is taking 100% of the CPU, and returns control to my program when it wants. The main functions are easy: openaudio for detecting and initializing the board (this one works great) and updateaudio which is called every clock_per_second from my program.
    Updateaudio is the issue here. I made a neat package with everything I'm using, and some examples, like the standalone player, my partially-working driver for SEAL and the driver I derived my work from, and the MAME code that makes use of WSS and has a working updateaudio function through it. Everything is commented and has a description. I've been stuck and fighting with this for more than a week and I'm on the point of needing help desperatedly. I can pay for the time needed to look at it and to point me in the right direction. Any help will be more than appreciated.

    Package is here: http://24.232.64.200/sources.zip (85kb)

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    DOS sound? Time to get with the times don't ya think? Instead of banging your head against a wall trying to do something that was done 10 to 12 years ago on a modern platform that doesn't support what was done 10 to 12 years ago....why not focus your efforts on something that CAN be done on a modern platform with little or no trouble?

    DX sound is so nice. No more DMA, no more PIC, no more interrupt handlers, no more mess.
    Try it.

    In a nutshell: DOS is the anti-thesis of XP. Do yourself a favor and work with the OS instead of against it.
    Last edited by VirtualAce; 08-23-2006 at 11:55 PM.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    4
    The system I'm building doesn't need (and doesn't want to need) Windows, so why loading it unnecesarily? Quick booting time and being able to shut it down at any moment are the main advantages I need. Anyway it is almost done, I just need a little push. Thanks for your reply!

    Marton

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Um...Start->Turn off computer->Turn off.

    How much faster do you need it?

    Your advantages and reasons for using DOS are not really advantages nor valid reasons. But if you want to stick with ancient technology then go ahead. I suggest you read some ancient books too.

  5. #5
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Ever try DOSBOX?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > Package is here: http://24.232.64.200/sources.zip (85kb)
    Shudder - 85K of someone elses compressed source code.

    I mean, you could try prototyping a standalone example in I dunno, a hundred or so lines tops and posting that. It would be a darn sight easier to look at, and it might help you focus on some of the real issues of the specific problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    The specific problem is XP is not designed to do this. Anything you come up with is a hack or only pertains to very specific cards.

    Hardware is hands off now unless you get to it through a driver.

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    4
    Salem, the 85K include a ~100kb exe file (which packed goes down to ~50kb). That is not someone elses compressed source code. There is my source as well as the explanations and examples.
    I see gurus like you complain when someone asks "please make my program" or "how do I do this" expecting someone else to solve it entirely... but I'm seeing complaints even with my case in which I have it almost working and need a push from someone who knows more than me...

    Anyway I will definitely try your suggestion. Here it goes:

    This is the problematic function:

    Code:
    static UINT AIAPI UpdateAudio(UINT nFrames)
    
    // nFrames is 0 when this function is called
    nFrames = 500;
    // I am just "guessing" that value.
    
        /* send PCM samples to the DSP audio device */
        if (AC97.lpfnAudioWave != NULL) {
            AC97.lpfnAudioWave(AC97.lpBuffer, nFrames);
        }
    
    //I think is while is one of my problems (too much delay to break for some reason)
        while(1){
          int d0 = w_get_watermark_status();
           if(d0 == -1 || d0 == 0) break;
           if(d0 == -2){
           w_reset_watermark_ex(nFrames);
          break;
           }
         }
    
    //nFrames is the size of the buffer, it should be actual_sample_rate / clocks_per_second
    //I don't know where to get the clocks_per_second from.
        w_lock_mixing_buffer(nFrames);
    //AC97.lpBuffer is the pointer to the wave data.
    //It is 8 bits so that's why I call w_mixing8 instead of w_mixing
        w_mixing8(AC97.lpBuffer, nFrames, 256, 256); // 256 is the volume on L/R channels
        w_unlock_mixing_buffer();
    
        return AUDIO_ERROR_NONE;
    So:

    a) My program calls this function every clock_per_second. I get clocks_per_second with this function:

    Code:
    		a=clock();
    		gettime(&t);
    		while(secs!=2)
    		{
    			gettime(&t2);
    			if(t.ti_sec!=t2.ti_sec)
    			{
    				memcpy(&t,&t2,sizeof(struct time));
    				secs++;
    			}
    
    		}
    		b=clock()-a;
    		clocks_per_second=(clock_t)((double)b/2.0F);
    b) Updateaudio locks the buffer, plays the wave, unlocks the buffer and via the while loop checks if the samples have been played, and if they did it breaks. If D0 is 0 it is OK with no latency, if it's -1 it is fine, if it's -2 there's been a buffer underrun.
    c) I can't figure if I need to advance the AC97.lpBuffer pointer or SEAL does it automatically.

    Hope this helps... thanks for the replies.

    Marton
    Last edited by Marton79; 08-24-2006 at 07:50 PM.

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    4
    Quote Originally Posted by Bubba
    Um...Start->Turn off computer->Turn off.

    How much faster do you need it?
    Speed is not the issue.

    1) The machine will not have a mouse, only a small numeric keyboard for navigation through the menus.
    2) The user will not be able to touch the PC, it will be a closed box.
    3) The machine will be shut down by the main power switch (obviously when it is idle). If this is made in Windows, it would not last long without crashing the registry at some point.
    4) If I didn't really need to make it this way, I would not be asking, believe me.

    Cheers,
    Marton

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    1) The machine will not have a mouse, only a small numeric keyboard for navigation through the menus.
    You can navigate Windows just fine with no mouse. This is irrelevant to the topic at hand.

    3) The machine will be shut down by the main power switch (obviously when it is idle). If this is made in Windows, it would not last long without crashing the registry at some point.
    How so? Windows usually crashes hard b/c of a failure to defrag the drives and the fact that the default defrag proggy that comes with XP sucks. Since I've purchased a 3rd party defrag program I've had no issues. Windows frags the drive far more than DOS did b/c of the swap file mechanism. If you defrag a lot you will notice that certain portions of the drive always get fragged. This portion is normally the sectors/indexes that the swap file uses.

    2) The user will not be able to touch the PC, it will be a closed box.
    As are all our shop-floor systems at my current factory as well as the previous one. They all use XP and before that NT. Again I don't see the relevance here for choice of platform.

    4) If I didn't really need to make it this way, I would not be asking, believe me.
    So far you have no reasons to do it this way. Now if some of your reasons were relevant and specific then I would agree. I'm just trying to make things easier on you and tell you to choose the path of least resistance - which would be working with the system instead of against it.

    Also why do you need sound on a system like this? If it's for training employees they have several programs out there just for that or you could code one easily yourself.
    Last edited by VirtualAce; 08-24-2006 at 11:04 PM.

  11. #11
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by Bubba
    This portion is normally the sectors/indexes that the swap file uses.
    Man oh man. . . I know this is WAY WAT OT, but. . .

    It is a good idea to create a static swap file for a Windows 2***/XP/-Anything with a NTFS on it. The way to do it is to make the MIN/MAX for the swap file the default MAX -- This assumes that the default max is about 3X your memeory. If you do this several things can happen 1) your computer will boot more quickly **Having a good defrag tool like Diskeeper to defrag this file AFTER you reboot the first time after making this change will increase the speed**, 2) speeds up your access time if you do a lot of program swapping, 3) really hoses you if you are using the "Delete the swap file on windows shutdown."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Library Wrapper
    By cusavior in forum C Programming
    Replies: 3
    Last Post: 03-25-2008, 10:27 AM
  2. Difficulty choosing graphics library
    By jdiperla in forum Game Programming
    Replies: 11
    Last Post: 02-27-2008, 06:35 PM
  3. Linker errors in VC++ 2005
    By C+/- in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2007, 07:42 AM
  4. how many old school DOS programmers are left?
    By Waldo2k2 in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 02-01-2003, 05:14 PM
  5. File systems?? (Winxp -> DOS)
    By Shadow in forum Tech Board
    Replies: 4
    Last Post: 01-06-2003, 09:08 PM