Exemple #1
0
void Engine::EnableAudio() {
  SDL_AudioSpec audio_spec = {0};
  audio_spec.freq = kSamplesPerSecond;
  audio_spec.format = AUDIO_S16LSB;
  audio_spec.channels = 1;
  audio_spec.samples = 2048;

  audio_enabled_ = OpenAudioDevice(audio_spec);

  if (audio_enabled_)
    PauseAudioDevice(0);
}
void MythRAOPConnection::audioRetry(void)
{
    if (!m_audio)
    {
        MythRAOPDevice* p = (MythRAOPDevice*)parent();
        if (p && p->NextInAudioQueue(this) && OpenAudioDevice())
        {
            CreateDecoder();
        }
    }

    if (m_audio && m_codec && m_codeccontext)
    {
        StopAudioTimer();
    }
}
/*******************************************************************************
 * Name        : MainDialogProc
 *
 * Description : This function controls the main dialog box.  It will handle
 *               received messages such as pushbutton notifications, playlist
 *               messages, etc
 *
 *               The following messages are handled specifically by this
 *               routine.
 *
 *                  WM_INITDLG
 *                  WM_CLOSE
 *                  WM_COMMAND
 *                  MM_MCIPASSDEVICE
 *                  WM_ACTIVATE
 *
 *
 * MMPM/2 API's : mciSendCommand
 *                   MCI_ACQUIREDEVICE
 *                mmioClose
 *                mmioRead
 *                mmioSeek
 *
 * Parameters   : hwnd - Handle for the Main dialog box.
 *                msg  - Message received by the dialog box.
 *                mp1  - Parameter 1 for the just recieved message.
 *                mp2  - Parameter 2 for the just recieved message.
 *
 * Return       :
 *
 *
 ******************************************************************************/
MRESULT EXPENTRY MainDialogProc(
                HWND hwnd,
                 ULONG msg,
                 MPARAM mp1,
                 MPARAM mp2)
{
static MCI_GENERIC_PARMS  lpWaveGeneric; /* Used for MCI_ACQUIREDEVICE      */
ULONG                     ulReturn;      /* Ret Code for Dos and MCI calls  */


switch (msg)
   {

    case WM_CLOSE:

       if ( usWaveDeviceId > 0 )
            mciSendCommand(
               usWaveDeviceId,               /* Device to play the chimes.    */
               MCI_CLOSE,                    /* MCI message.                  */
               MCI_WAIT,                     /* Flags for the MCI message.    */
               (ULONG) NULL,                 /* Parameters for the message.   */
               (ULONG) NULL );               /* Parameter for notify message. */

       WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
       return ((MRESULT) NULL);

    case WM_INITDLG:

       /*
        * Put the Playlist Instructions into the Playlist structure.
        */
       ulReturn = InitializePlayList();

       if( ulReturn )
         {
         ShowAMessage(
             IDS_ERROR_TITLE,
             IDS_CANT_CREATE_SEMAPHORE,
             MB_OK | MB_INFORMATION | MB_MOVEABLE | MB_HELP |
             MB_APPLMODAL,
             FALSE );

         WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
         }

       /* Opens the Audio device for playlist */
       OpenAudioDevice(hwnd);

       /*
        * Since the play button is an animated button, we need to initialize it
        */
       WinSendMsg (
           WinWindowFromID(
                hwnd,             /* Dialog window handle             */
                ID_PLAY),         /* Id - Play graphic button         */
           GBM_SETANIMATIONRATE,  /* Animation rate control           */
           MPFROMLONG(100L),      /* Update play bitmap every .1 sec  */
           NULL);                 /* Ignore return data               */

       break;


    /*  Service all of the button pushes */
    case WM_COMMAND:
       switch (SHORT1FROMMP(mp1))
         {
         case ID_END:

            /*
             * Send command to MCI to stop the playlist
             */
            mciSendCommand( usWaveDeviceId,  /* Device to play the chimes.    */
                            MCI_STOP,        /* MCI message.                  */
                            MCI_WAIT,        /* Flags for the MCI message.    */
                            (ULONG) NULL,    /* Parameters for the message.   */
                            (ULONG) NULL );  /* Parameter for notify message. */

            fEndPlay = TRUE;

            /*
             * Disable the animation of the Play button
             */
            WinSendMsg (   WinWindowFromID(
                             hwnd,            /* Dialog window handle        */
                             ID_PLAY),        /* Id - Play graphic button    */
                           GBM_ANIMATE,       /* Animation control           */
                           MPFROMSHORT(FALSE),/* Animation flag              */
                           NULL);             /* Ignore return data          */

            lState = STATE_IS_STOP;

            break;


         case ID_PLAY:

            /*
             * If we are not playing the playlist only then Play it
             */
            if (lState == STATE_IS_STOP)
               {
               if (fPassedDevice)
                  {
                  /*
                   * If we don't have the device then display a message.
                   * FALSE is passed because this is not a MCI error.
                   */

                  ShowAMessage(
                       IDS_ERROR_TITLE,
                       IDS_CANT_PROCESS_MESSAGE,
                       MB_OK | MB_INFORMATION | MB_MOVEABLE | MB_HELP |
                       MB_APPLMODAL ,
                       FALSE);
                  }
               else
                  /*
                   * We have the device so no problem.
                   * Call the subroutine that starts the audio playlist.
                   */
                  ulReturn = PlayTheWave();

               if ( ulReturn )
                  {
                  /*
                   * Play failed so display an error message
                   */
                  ShowAMessage(
                      IDS_ERROR_TITLE,
                      IDS_CANT_PROCESS_MESSAGE,
                      MB_OK | MB_INFORMATION | MB_MOVEABLE | MB_HELP |
                      MB_APPLMODAL,
                      FALSE );
                  }
               else
                  {
                  /*
                   * Play was successful so update the flag and animate
                   * the play button.
                   */
                  lState = STATE_IS_PLAYING;

                  WinSendMsg (
                     WinWindowFromID(
                       hwndDiag,         /* Dialog window handle      */
                       ID_PLAY),         /* Id - Play graphic button  */
                     GBM_ANIMATE,        /* Animation control         */
                     MPFROMSHORT(TRUE),  /* Animation flag            */
                     NULL);              /* Ignore return data        */

                  }


               }

            break;

         } /* end switch */
       return((MRESULT)NULL);

   /*
    * This message is used to set a flag that indicates wether this
    * application has position of the audio device. This information
    * is used to implement device sharing.
    */

    case MM_MCIPASSDEVICE:
       if( SHORT1FROMMP( mp2 ) == MCI_GAINING_USE )
          fPassedDevice = FALSE;
       else
       {
          fPassedDevice = TRUE;
          if( lState == STATE_IS_PLAYING )

            mciSendCommand( usWaveDeviceId,  /* Device to play the chimes.    */
                            MCI_PAUSE,       /* MCI message.                  */
                            MCI_WAIT,        /* Flags for the MCI message.    */
                            (ULONG) NULL,    /* Parameters for the message.   */
                            (ULONG) NULL );  /* Parameter for notify message. */

       } /* end else */
       break;


    /*
     * We use the WM_ACTIVATE message to participate in device sharing.
     * We first check to see if this is an activate or a deactivate
     * message (indicated by mp1). Then, we check to see if we've passed
     * control of the device that we use.  If these conditions are true,
     * then we issue an acquire device command to regain control of the
     * device, since we're now the active window on the screen.
     *
     * This is one possible method that can be used to implement
     * device sharing. For applications that are more complex
     * than this sample program, developers may wish to take
     * advantage of a more robust method of device sharing.
     * This can be done by using the MCI_ACQUIRE_QUEUE flag on
     * the MCI_ACQUIREDEVICE command.  Please refer to the MMPM/2
     * documentation for more information on this flag.
     */
    case WM_ACTIVATE:
       /* First we check to see if we've passed control of the device */
       if ((BOOL)mp1 && fPassedDevice == TRUE)
       {
          lpWaveGeneric.hwndCallback =   hwnd;
          ulReturn = mciSendCommand( usWaveDeviceId,
                                     MCI_ACQUIREDEVICE,
                                     (ULONG)MCI_WAIT,
                                     (PVOID)&lpWaveGeneric,
                                     (USHORT)NULL );
          if (ulReturn != 0)
             /*
              * This is an MCI Error so show the message by passing TRUE
              */
             ShowAMessage(
                     IDS_ERROR_TITLE,
                     ulReturn,
                     MB_OK | MB_INFORMATION | MB_MOVEABLE | MB_HELP |
                     MB_APPLMODAL,
                     TRUE);

          if( lState == STATE_IS_PLAYING )

            mciSendCommand( usWaveDeviceId,  /* Device to play the chimes.    */
                            MCI_RESUME,      /* MCI message.                  */
                            MCI_WAIT,        /* Flags for the MCI message.    */
                            (ULONG) NULL,    /* Parameters for the message.   */
                            (ULONG) NULL );  /* Parameter for notify message. */

       } /* end if */

       break;
    } /* end switch */

    return ( WinDefDlgProc( hwnd, msg, mp1, mp2 ) );
}