⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmaudiostream.c

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 C
📖 第 1 页 / 共 5 页
字号:

    if ( !pStreamCtx )
    {
        status = WMS_RESOURCE_FAIL;
        goto error;
    }

    /*
     * Mark our context as active and return.
     */    
    pStreamCtx->flags |= STREAM_ACTIVE;
    *ppStreamCtx = pStreamCtx;
    return WMS_SUCCESS;

    /*
     * Something went wrong.  Zap the context and return the error.
     */
error:
    *ppStreamCtx = NULL;
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    private_InitialiseStreamContext
 *
 * Initialises a stream context for the given stream.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice).
 *      stream      the stream to allocate for.
 *      pStreamCtx  the stream context to initialise.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_InitialiseStreamContext( WM_DEVICE_HANDLE   hDevice,
                                             WM_STREAM_ID       stream,
                                             StreamCtx          *pStreamCtx
                                           )
{
    WMAUDIO_CHANNEL     APIChannel;

    /*
     * Set the stream ID.
     */    
    pStreamCtx->stream = stream;

    /*
     * Look up the channel and make sure it's supported.  We should only
     * call this function once we've checked the stream is supported.
     */
    APIChannel = _WMAudioStreamToChannel( hDevice, stream );
    WM_ASSERT( hDevice, WMAUDIO_INVALID_CHANNEL != APIChannel );
    pStreamCtx->APIChannel = APIChannel;

    /*
     * We're done.
     */
    return;
}

/*-----------------------------------------------------------------------------
 * Function:    private_FreeStreamContext
 *
 * Frees the stream context for the given stream and returns it to use.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice).
 *      pStreamCtx  the stream to free.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_FreeStreamContext( WM_DEVICE_HANDLE hDevice,
                                       StreamCtx        *pStreamCtx
                                     )
{
    /* Just checking... */
    WM_ASSERT( hDevice, pStreamCtx->flags & STREAM_ACTIVE );
    
    /* And clear out the context */
    pStreamCtx->flags = 0;
    
    /*
     * Note: we'll be reusing the stream context next time someone wants
     * this stream, so don't clear it out, and don't return the DMA channel.
     */
     
    /* We're done */
    return;
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill8BitMonoTo16BitMono
 *
 * Copies 8-bit mono audio data to the DMA buffer.
 *
 * Parameters:
 *      pDest        the DMA buffer.
 *      Src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill8BitMonoTo16BitMono( void *dest, void *src, unsigned int nSamples )
{
    unsigned int    sample;
    short           *pDest = (short *) dest;
    unsigned char   *pSrc = (unsigned char *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        *pDest = CONVERT_8BIT_TO_16BIT( *pSrc );

        pDest++;
        pSrc++;
    }
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill8BitMonoTo32BitMono
 *
 * Copies 8-bit mono audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill8BitMonoTo32BitMono( void *dest, void *src, unsigned int nSamples )
{
    unsigned int    sample;
    int             *pDest = (int *) dest;
    unsigned char   *pSrc = (unsigned char *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        *pDest = (short) CONVERT_8BIT_TO_16BIT( *pSrc );

        pDest++;
        pSrc++;
    }
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill8BitMonoToStereo
 *
 * Copies 8-bit mono audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill8BitMonoToStereo( void *dest, void *src, unsigned int nSamples )
{
    unsigned int    sample;
    short           *pDest = (short *) dest;
    unsigned char   *pSrc = (unsigned char *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        pDest[0] = CONVERT_8BIT_TO_16BIT( *pSrc );
        pDest[1] = CONVERT_8BIT_TO_16BIT( *pSrc );

        pDest += 2;
        pSrc++;
    }
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill16BitMonoTo16BitMono
 *
 * Copies 16-bit mono audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill16BitMonoTo16BitMono( void *dest, void *src, unsigned int nSamples )
{
    memcpy( dest, src, nSamples * sizeof( unsigned short ) );
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill16BitMonoTo32BitMono
 *
 * Copies 16-bit mono audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill16BitMonoTo32BitMono( void *dest, void *src, unsigned int nSamples )
{
    unsigned int    sample;
    int             *pDest = (int *) dest;
    short           *pSrc = (short *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        *pDest = *pSrc;

        pDest++;
        pSrc++;
    }
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill16BitMonoToStereo
 *
 * Copies 16-bit mono audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill16BitMonoToStereo( void *dest, void *src, unsigned int nSamples )
{
    unsigned int    sample;
    short           *pDest = (short *) dest;
    short           *pSrc = (short *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        pDest[0] = *pSrc;
        pDest[1] = *pSrc;

        pDest += 2;
        pSrc++;
    }
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill8BitStereoTo16BitMono
 *
 * Copies 8-bit stereo audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill8BitStereoTo16BitMono( void *dest, void *src, unsigned int nSamples )
{
    unsigned int    sample;
    short           *pDest = (short *) dest;
    unsigned char   *pSrc = (unsigned char *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        *pDest = ( CONVERT_8BIT_TO_16BIT( pSrc[0] ) +
                   CONVERT_8BIT_TO_16BIT( pSrc[1] ) ) / 2;

        pDest++;
        pSrc += 2;
    }
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill8BitStereoTo32BitMono
 *
 * Copies 8-bit stereo audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill8BitStereoTo32BitMono( void *dest, void *src, unsigned int nSamples )
{
    unsigned int    sample;
    int             *pDest = (int *) dest;
    unsigned char   *pSrc = (unsigned char *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        *pDest = (short) ( CONVERT_8BIT_TO_16BIT( pSrc[0] ) +
                           CONVERT_8BIT_TO_16BIT( pSrc[1] ) ) / 2;

        pDest++;
        pSrc += 2;
    }
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill8BitStereoToStereo
 *
 * Copies 8-bit stereo audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill8BitStereoToStereo( void *dest, void *src, unsigned int nSamples )
{
    unsigned int    sample;
    short           *pDest = (short *) dest;
    unsigned char   *pSrc = (unsigned char *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        pDest[0] = CONVERT_8BIT_TO_16BIT( pSrc[0] );
        pDest[1] = CONVERT_8BIT_TO_16BIT( pSrc[1] );

        pDest += 2;
        pSrc += 2;
    }
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill16BitStereoTo16BitMono
 *
 * Copies 16-bit stereo audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill16BitStereoTo16BitMono( void *dest, void *src, unsigned int nSamples )
{
    unsigned int    sample;
    short           *pDest = (short *) dest;
    short           *pSrc = (short *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        *pDest = ( pSrc[0] + pSrc[1] ) / 2;

        pDest++;
        pSrc += 2;
    }
}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill16BitStereoTo32BitMono
 *
 * Copies 16-bit stereo audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
static void private_Fill16BitStereoTo32BitMono( void *dest, void *src, unsigned int nSamples )
{
    unsigned int sample;
    int          *pDest = (int *) dest;
    short        *pSrc = (short *) src;

    for ( sample = 0; sample < nSamples; sample++ )
    {
        *pDest = ( pSrc[0] + pSrc[1] ) / 2;

        pDest++;
        pSrc += 2;
    }

}

/*-----------------------------------------------------------------------------
 * Function:    private_Fill16BitStereoToStereo
 *
 * Copies 16-bit stereo audio data to the DMA buffer.
 *
 * Parameters:
 *      dest        the DMA buffer.
 *      src         the audio data.
 *      nSamples    the number of samples to copy.
 *
 * Returns:     void
 *------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -