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

📄 headset_codec.c

📁 bluelab 3.52 里面的立体声程序源代码
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.5.2-release

FILE NAME
    headset_codec.c

DESCRIPTION
    Deals with all codec configuration

*/


/****************************************************************************
    Header files
*/
#include <codec.h>
#include <panic.h>
#include <pcm.h>
#include <stream.h>

#include "headset_codec.h"
#include "headset_private.h"

#ifdef DEBUG_AVSTREAM
#define AVSTREAM_DEBUG(x) DEBUG(x)
#else
#define AVSTREAM_DEBUG(x) 
#endif

#ifdef WOLFSON_CODEC_WM8731
static void configure_wolfson_codec(headsetTaskData *app) 
{
    const codec_config_params wolfsonCodecConfigParams 
            = {mic_input,OUTPUT_DAC,sample48kHz,sample48kHz};
    CodecConfigure(app->codec_task,&wolfsonCodecConfigParams);
}
#endif

/****************************************************************************/
static void codec_disconnect_pcm(void)
{
    /* Disconnect anything already connected to PCM slots 0 and 1 */
    StreamDisconnect(StreamPcmSource(0), StreamPcmSink(0));
    StreamDisconnect(StreamPcmSource(1), StreamPcmSink(1));
    /* Set both ports to none to allow reassigning of internal DACs */
    (void) PanicFalse(PcmClearRouting(0));
    (void) PanicFalse(PcmClearRouting(1));
}        

/****************************************************************************/
void codec_configure_mono_8000(headsetTaskData *app) 
{
    codec_disconnect_pcm();
    
#ifdef WOLFSON_CODEC_WM8731
    (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, (uint32) 8000, (uint32) 8000, 
                                      VM_PCM_EXTERNAL_I2S));
    configure_wolfson_codec(app);
#else
    (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, (uint32) 8000, (uint32) 8000,
                                      VM_PCM_INTERNAL_A_AND_B));
#endif
}

/**************************************************************************/
void codec_configure_AvStream(headsetTaskData *app)
{
   uint32 sampleRate = app->rate;
   
   AVSTREAM_DEBUG(("AV: Configure Codec\n"));
   
#ifdef WOLFSON_CODEC_WM8731
   if (sampleRate == 44100)
       sampleRate = 44118;
#endif
   
   codec_disconnect_pcm();

   /* Is it mono playback? */
   if (app->channel_mode == a2dp_mono)
   {
       /* Mono - Set both DACs to play the output of port 0. */
#ifdef WOLFSON_CODEC_WM8731
      (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, sampleRate, VM_PCM_EXTERNAL_I2S));
      configure_wolfson_codec(app);
#else
      (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, (uint32) 8000, VM_PCM_INTERNAL_A_AND_B));
#endif
   }
   else
   {
      /*
         Stereo - Configure port 0 and 1 to be left and right channels
         and synchronise buffer offsets for stereo playback.
      */
#ifdef WOLFSON_CODEC_WM8731
      (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, sampleRate, VM_PCM_EXTERNAL_I2S));
      (void) PanicFalse(PcmRateAndRoute(1, 0, sampleRate, sampleRate, VM_PCM_EXTERNAL_I2S));
      configure_wolfson_codec(app);
#else
      (void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, (uint32) 8000, VM_PCM_INTERNAL_A));
      (void) PanicFalse(PcmRateAndRoute(1, 0, sampleRate, (uint32) 8000, VM_PCM_INTERNAL_B));
#endif
   }
}

⌨️ 快捷键说明

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