Exemple #1
0
static void
kai_stream_destroy(cubeb_stream * stm)
{
  kaiClose(stm->hkai);
  _fmutex_close(&stm->mutex);
  free(stm);
}
Exemple #2
0
/*****************************************************************************
 * Close: close the audio device
 *****************************************************************************/
static void Stop ( audio_output_t *p_aout )
{
    aout_sys_t *p_sys = p_aout->sys;

    kaiClose( p_sys->hkai );
    kaiDone();

    aout_PacketDestroy( p_aout );
}
Exemple #3
0
/*****************************************************************************
 * Close: close the audio device
 *****************************************************************************/
static void Stop ( audio_output_t *p_aout )
{
    aout_sys_t *p_sys = p_aout->sys;

    kaiClose( p_sys->hkai );
    kaiDone();

    DestroyBuffer( p_aout );
}
Exemple #4
0
static int
kai_get_preferred_sample_rate(cubeb * ctx, uint32_t * rate)
{
  cubeb_stream_params params;
  KAISPEC wanted_spec;
  KAISPEC spec;
  HKAI hkai;

  params.format = CUBEB_SAMPLE_S16NE;
  params.rate = 48000;
  params.channels = 2;

  wanted_spec.usDeviceIndex   = 0;
  wanted_spec.ulType          = KAIT_PLAY;
  wanted_spec.ulBitsPerSample = BPS_16;
  wanted_spec.ulSamplingRate  = params.rate;
  wanted_spec.ulDataFormat    = MCI_WAVE_FORMAT_PCM;
  wanted_spec.ulChannels      = params.channels;
  wanted_spec.ulNumBuffers    = NBUFS;
  wanted_spec.ulBufferSize    = frames_to_bytes(FRAME_SIZE, params);
  wanted_spec.fShareable      = TRUE;
  wanted_spec.pfnCallBack     = kai_callback;
  wanted_spec.pCallBackData   = NULL;

  /* Test 48KHz */
  if (kaiOpen(&wanted_spec, &spec, &hkai)) {
    /* Not supported. Fall back to 44.1KHz */
    params.rate = 44100;
  } else {
    /* Supported. Use 48KHz */
    kaiClose(hkai);
  }

  *rate = params.rate;

  return CUBEB_OK;
}
Exemple #5
0
void playThread( void *arg )
{
    char           *name = arg;
    HMMIO           hmmio;
    MMIOINFO        mmioInfo;
    MMAUDIOHEADER   mmAudioHeader;
    LONG            lBytesRead;
    KAISPEC         ksWanted, ksObtained;
    HKAI            hkai;
    CBDATA          cd;

    /* Open the audio file.
     */
    memset( &mmioInfo, '\0', sizeof( MMIOINFO ));
    mmioInfo.fccIOProc = mmioFOURCC('W', 'A', 'V', 'E');
    hmmio = mmioOpen( name, &mmioInfo, MMIO_READ | MMIO_DENYNONE );
    if( !hmmio )
    {
        fprintf( stderr, "[%s] Failed to open a wave file!!!\n", name );

        goto exit_discount_threads;
    }

    /* Get the audio file header.
     */
    mmioGetHeader( hmmio,
                   &mmAudioHeader,
                   sizeof( MMAUDIOHEADER ),
                   &lBytesRead,
                   0,
                   0);

    memset( &cd, 0, sizeof( CBDATA ));
    cd.hmmio = hmmio;

    ksWanted.usDeviceIndex      = 0;
    ksWanted.ulType             = KAIT_PLAY;
    ksWanted.ulBitsPerSample    = mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample;
    ksWanted.ulSamplingRate     = mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec;
    ksWanted.ulDataFormat       = 0;
    ksWanted.ulChannels         = mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels;
    ksWanted.ulNumBuffers       = 2;
    ksWanted.ulBufferSize       = 0;
    ksWanted.fShareable         = TRUE;
    ksWanted.pfnCallBack        = kaiCallback;
    ksWanted.pCallBackData      = &cd;

    if( kaiOpen( &ksWanted, &ksObtained, &hkai ))
    {
        fprintf( stderr, "[%s] Failed to open audio device!!!\n", name );

        goto exit_mmio_close;
    }

    printf("[%s] hkai = %lx\n", name, hkai );

    kaiSetVolume( hkai, MCI_SET_AUDIO_ALL, 50 );

    kaiSetSoundState( hkai, MCI_SET_AUDIO_ALL, TRUE );

    printf("[%s] Trying to play...\n", name );

    //DosSetPriority( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0 );
    while( 1 )
    {
        switch( kaiPlay( hkai ))
        {
            case KAIE_NO_ERROR :
                break;

#if 0
            // Wait for instance to be active
            case KAIE_NOT_READY :
                DosSleep( 1 );
                continue;
#endif

            default :
                fprintf( stderr, "[%s] Failed to play!!!\n", name );
                goto exit_kai_close;
        }

        break;
    }
    //DosSetPriority( PRTYS_THREAD, PRTYC_REGULAR, 0, 0 );

    printf("[%s] Playing...\n", name );
    while( !m_fQuit && !( kaiStatus( hkai ) & KAIS_COMPLETED ))
        DosSleep( 1 );

    printf("[%s] Completed\n", name );

exit_kai_close :

    kaiClose( hkai );

exit_mmio_close :

    mmioClose( hmmio, 0 );

exit_discount_threads :

    m_nThreads--;
}