                          VIA AC'97 codec
                     sound problem solver pack
                            for OS/2

                     (c) 2001 by Vit Timchsihin
                           tivv@ukr.net

                           version 0.9b


1. Preface

    Not long ago I've decided to upgrade my PC. The motherboard I've selected
contained VIA 686B with integrated AC'97 audio. I even heard that there are
drivers for this audio card.
    But after I came home and tried to use the sound I've faced some problems...
Now I can listen any WAV/MP3 file I wish (now I have CD player plying using
digital transfer).
    Some time later I've realized that I am not alone and so this package
was created to help many others that faced same problems.

Discaimer:
    I created this package in my effort to help OS/2 community, but I don't
support it - this mean that I may answer or may not answer to your questions.
I am trying to solve my own problems and will be happy if this methods will
help someone else, but I unfortunatelly don't have time to resolve someone
other's problems.

2. Introduction

    Any AC'97 sound solution has two parts:
    a)Driver-dependant interface chip (VIA 686 in our case) that creates
      interface between user program (or driver) and codec
    b)Driver-independant codec chip. It is also important because this
      codec defines what features you will have, what sound quality you
      will hear and so on.

    VIA 686 provides two (almost, see below) independant interfaces to the
    sound codec:
    a)AC'97 version (this is what VIA drivers working with)
    b)Sound Blaster Pro emulation (that is second way, standard
      Sound Blaster pro (OPL3) drivers can work with this.

    Both cases have it's own problems, that are described in the two sections
below. But if you will overcome problem in both ways, you will have ability
to get TWO independant virtual sound card.

Note: This sound solution does NOT include MIDI, so you will need software
      midi (like TIMIDITY). Fortunatelly this is not a problem.

3. History

0.9c
    I am sorry, I've put older version of viadt.exe without new enhancements
    into 0.9b.
    Also this version has lxlited executables.

0.9b
    Since this is already second version of the page, new section is introduced.
    My current goal is to get normal DivX playback at my computer, so you can
    look forward to something more in the future. No promises.
    First of all, textual incorrectness is corrected. I was thinking too good
    of Sound Blaster Pro. Also, VIA provided new version of their package that
    treats some problems I've found before and provided a solution <g>. May be
    they will also incorporate changes from this package.
    Also viadt utility can be used now to ENABLE sound blaster emulation if you
    don't have such a setting in the BIOS or try to use VIA legacy driver (that
    disables this emulation). Actually second goal was my purpose and I am not
    sure if the utility will help in first.
    New dumppci utility will dump PCI space registers for VIA sound. I give no
    explanation to it, it is rather debugging thing that shows different modes
    and settings of VIA sound in unreadable way <g>. If you have VIA docs you
    can use this utility to check if you have SB Pro emulation enabled, what
    settings (IRQ/DMA/PORT) does it use, etc.
    Now I have much more devices on my PCI bus and I've found out that VIA
    driver DO NOT SUPPORT IRQ SHARING. For PCI device driver it is ridiculous.
    I hope I've corrected this problem - fortunatelly VIA do not have a man
    that knows how to write drivers and person who wrote VIA driver basing
    on DDK PAS16 driver source did not even remove calls to actual PAS16 ports
    in IRQ handler - so I have enough unneeded code to place 3 bytes that made
    the whole IRQ handler to perform good on sharing IRQs (yes, this would
    be a LOT of work for VIA to do this - read DDK docs and add few lines of
    code<g>).
    Also viaudd patched are now based on newer VIA drivers (see url.txt).

0.9
    Initial version

4. Tools

    This package has next tools available:
    a)viadt.exe (TRAP remover, see below)
    b)dumppci - dumps part of VIA Audio device PCI registers.
    c)dumpreg - dumps AC'97 codec registers
    d)setreg - sets AC'97 codec register, can be used
      to set mixer settings (volume).

    Last two need IOPL32.DLL (URL #3 in url.txt).

5. VIA (AC'97) driver problems:

    a)Driver simply does not work. When one issue "TYPE VIAUD1$"
      he get "write protected" error message ("The device does not
      recognize the command is OK")

    Technical cause:
        When creating VIA drivers from DDK PAS16 samples
        they did not make there IRQ handler to work with
        shared interrupts.

    Patch:
        viaudd.sys
        00003B0E: 68 F9
        00003B0F: 88 C9
        00003B10: 1B CB
        00004086: 00 01

        This will make SetIRQ call to request shared interrupt
        and patch IRQ handler to work with shared interrupts correctly.
        Note that this patch is alpha code and tested not too good.
        If you have traps with patch applied, please send me TRAP information.


    b)All sound files are played faster then needed

    This is codec functionality problems: not all codecs has
    variable sound rate feature, and if codec lacks the feature
    it will play all files if they are 48000 Khz

    Nothing can be done with this, the only thing is that you can
    check this to be sure:
    1)Run dumpreg.
    2)Look for 0x28 register
    3)Check bit 0. It will indicate if your codec support
    variable rate for playing.
    3)Check bit 3. It will indicate if your codec support
    variable rate for recording.

    If you are not lucky (like me <g>), you must use second (Sound Blaster Pro)
solution. But you can still leave VIA drivers to play(or record!) 48000Khz
audio. In case of recording, you will get full duplex solution.

6. Sound Blaster emulation problems

    a)TRAP 2

    Technical cause:
        This is feature <g>.
        The trap is created by hardware when SB driver tries to access
        midi. This enables creation of solution that will react to the trap
        and emulate SB FM MIDI. Fortunatelly this is disableable.

    Solution:
        Add CALL=D:\PATH\viadt.exe to your config.sys. This program will
        disable TRAP 2 generation for all VIA sound solutions found.

    b)Problems playing 44100Khz/16Bit audio.

    Technical cause:
        SB Pro do not support this mode. Nothing can be done.
        Use 8bit when available.

    c)Nothing can be heard from Solution.

    Technical cause:
        Yet two solutions are independant, something still must init
        AC'97 codec.

    Solution:
        a) This can be done by viaudd driver (simply leave it
        in the config.sys, even without referencing in MMOS2).
        b) viaudd setup gives to high rate for PC speaker as for me,
        That's why I can recommend using setreg.exe to set needed volumes
        (See below).

     d)VIA and SB Pro do not work in pair. (Nothing can be heard from SB Pro).

     Technical cause:
        VIA driver disables SB Pro emulation

     Solution:
        Add CALL=D:\PATH\viadt.exe to your config.sys. This program will
        reenable SB Pro emulation on you VIA chipset.

7. Using setreg as mixer control program to set volumes.

    a)Use regs2.txt to select needed register.
    b)Call setreg <register> <value>.
    In most volume cases value must be 4 bytes hex value (i.e. ABCD),
    first two digits for one channel (left/right), last two for other.
    Setting highest bit (8000) will mute.
    Please note that lower settings gives HIGHER volume.

    My favorite settings (that are lines form startup.cmd):
    D:\path\setreg.exe 2 505
    D:\path\setreg.exe a a0a
    D:\path\setreg.exe 1c 0
    D:\path\setreg.exe 12 808
    D:\path\setreg.exe 18 a0a

    Note 1: To get other register values see first two urls from url.txt
    Note 2: setreg traps for me if called from config.sys (it seems that
            IOPL32 does not work), that's why I call it from startup.cmd

8. Disclaimer

    This pack is freeware

    YOU ARE USING THIS IT AT YOUR OWN RISK!!! In no event I take any
responsibillity   for  damages,  problems,  custodies,  etc. resulting
from  use, inability  to  use, misuse,  possession  or non-possession of
this library directly or indirectly.

	THE SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

    Permission is granted to redistribute this package free of charge,
provided it is distributed in the full archive with unmodified
contents and no profit beyond the price of the media on which it
is distributed is made. Exception to the last rule: the library
may be included on freeware/shareware collections on CD-ROM, as
well as on magazine cover CD-ROMs.

9. Trademarks

    IBM and OS/2 are registered trademarks of International Business
Machines, Inc.

    All other trademarks, registered trade marks, service marks and other
registered marks are the property of their respective owners.

