home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / runnable / mmos2 / mmtoolkt / samples / audiodd / audintr.c next >
Encoding:
C/C++ Source or Header  |  1992-05-06  |  4.3 KB  |  111 lines

  1. /**************************START OF SPECIFICATIONS **************************/
  2. /*                                                                          */
  3. /* SOURCE FILE NAME:  AUDINTR.C    (TEMPLATE SAMPLE)                        */
  4. /*                                                                          */
  5. /* DISCRIPTIVE NAME: Audio device driver interrupt handler                  */
  6. /*                                                                          */
  7. /* LINKAGE: near calls                                                      */
  8. /*                                                                          */
  9. /* DESCRIPTION:                                                             */
  10. /*    Processes data stream and calls stream handler via                    */
  11. /*    IDC (Inter Device Communication) to get/give data buffers.            */
  12. /*                                                                          */
  13. /************************** END OF SPECIFICATIONS ***************************/
  14.  
  15. #define  INCL_DOS
  16. #define  INCL_DOSINFOSEG
  17. #include <os2.h>
  18.  
  19. #include <os2medef.h>
  20. #include <ssm.h>         // Sync Stream Manager
  21. #include <shdd.h>
  22. #include <audio.h>
  23. #include "audiodd.h"
  24.  
  25. extern ULONG operation;
  26.  
  27. //****************************************************
  28. // This procedure is called at device interrupt time
  29. //****************************************************
  30. VOID InterruptHandler()
  31. {
  32.         SHD_REPORTINT   ShdInt ;
  33.         PSTREAM         pStream;
  34.  
  35.         // Set up the pStream pointer
  36.         // Code omitted - there are no streams
  37.  
  38.         /*
  39.         ** Do not call stream handler OR get any new buffers
  40.         ** if stream was/is stopped by handler
  41.         **
  42.         ** Definitions:
  43.         **    Overrun  - Happens during "record" if the DSP (card)
  44.         **               does not have an empty buffer to place data.
  45.         **               This is a data loss condition.
  46.         **    Underrun - Happsn during "playback" if the DSP (card)
  47.         **               has no more buffers available to read.
  48.         **               (ie No data available to write to hardware).
  49.         **               No data loss, but will experience audio interuption.
  50.         **
  51.         ** So, it is the hardware that detects the error condition.
  52.         ** The method of relaying this information to the PDD is device
  53.         ** specific.  A common method is for the hardware to address flags
  54.         ** in the PDD (writeable addresses set up at initialization time).
  55.         ** Those flags would be interrogated here to determine if all is well.
  56.         ** If things are not well, that information would be passed on to
  57.         ** the stream handler.
  58.         */
  59.  
  60.         // Code omitted - test overrun/underrun and report to stream handler
  61.  
  62.  
  63.         if (pStream->ulFlags & STREAM_STOPPED)
  64.           {
  65.           EOI(); // Reset interrupt controller
  66.           return;
  67.           }
  68.  
  69.         //*************************************
  70.         // If operation is PLAY, write data out
  71.         // to the card.  If operation is RECORD
  72.         // get data from the card's input jack
  73.         //*************************************
  74.         if (operation == OPERATION_PLAY)
  75.            {
  76.            WriteDataToCard();
  77.            }
  78.         else
  79.            {
  80.            ReadDataFromCard(); // Operation is record
  81.            }
  82.  
  83.         //*****************************************
  84.         // Report interrupt to audio stream handler
  85.         //*****************************************
  86.  
  87.         ShdInt.ulFunction = SHD_REPORT_INT ;
  88.         ShdInt.hStream    = pStream->hStream;
  89.         ShdInt.ulFlag     = SHD_WRITE_COMPLETE ;
  90.  
  91.         //*****************************************
  92.         // If overrun or underrun flags are set,
  93.         // return error code to stream handler, set ERROR flag
  94.         //*****************************************
  95.  
  96.         //************************************
  97.         // If pBuffer is NULL, report UNDERRUN
  98.         // to ADSH, so he can shut me down
  99.         //************************************
  100.  
  101.         // IDC call to Stream Handler
  102.         ((PSHDFN)pStream->ADSHEntry)(&ShdInt);
  103.  
  104.         //***************************
  105.         // Reset interrupt controller
  106.         //***************************
  107.         EOI();
  108.  
  109.         return;
  110. }
  111.