📄 av_headset_kalimba.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004
FILE NAME
av_headset_kalimiba.c
DESCRIPTION
NOTES
*/
/****************************************************************************
Header files
*/
#include "headset_private.h"
#include "av_headset_kalimba.h"
#include "av_headset_controls.h"
#include "cvc_headset.h"
#include <codec.h>
#include <file.h>
#include <kalimba.h>
#include <kalimba_standard_messages.h>
#include <pcm.h>
#include <stdlib.h>
#include <string.h>
#include <transform.h>
#include <panic.h>
static uint32 GetSampleRateValue(vm_pcm_rate rate)
{
switch (rate)
{
case VM_PCM_RATE_8K: return 8000;
case VM_PCM_RATE_11K025: return 11025;
case VM_PCM_RATE_16K: return 16000;
case VM_PCM_RATE_22K05: return 22050;
case VM_PCM_RATE_24K: return 24000;
case VM_PCM_RATE_32K: return 32000;
#ifdef WOLFSON_CODEC
case VM_PCM_RATE_44K1: return 44118;
#else
case VM_PCM_RATE_44K1: return 44100;
#endif
case VM_PCM_RATE_48K: return 48000;
}
return 48000;
}
/* Configure the physical codec depending on the AV codec params negotiated */
static void configureCodec(headsetTaskData *app)
{
uint32 sampleRate = GetSampleRateValue(app->rate);
app->pcm_audio_state = pcm_av;
/* 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 below.
(A DAC can only be routed to one port at a time!)
*/
(void) PanicFalse(PcmRoute(0, VM_PCM_NONE, PCM_NO_SYNC));
(void) PanicFalse(PcmRoute(1, VM_PCM_NONE, PCM_NO_SYNC));
/* Is it mono playback? */
if (app->channel_mode == a2dp_mono)
{
/* Mono - Set both DACs to play the output of port 0. */
#ifdef WOLFSON_CODEC
(void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, sampleRate, VM_PCM_EXTERNAL_I2S));
#else
(void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, 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
(void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, sampleRate, VM_PCM_EXTERNAL_I2S));
(void) PanicFalse(PcmRateAndRoute(1, 0, sampleRate, sampleRate, VM_PCM_EXTERNAL_I2S));
CodecConfigure(app->codec_task,0);
#else
(void) PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, sampleRate, 8000, VM_PCM_INTERNAL_A));
(void) PanicFalse(PcmRateAndRoute(1, 0, sampleRate, 8000, VM_PCM_INTERNAL_B));
#endif
}
}
/*************************************************************************
NAME
avHeadsetStartKalimba
DESCRIPTION
Initialise Kalimba and routing for SBC encoding
RETURNS
*/
static void avHeadsetStartKalimba(headsetTaskData* app)
{
/* Start decode */
A2dpAudioCodecEnable(app->a2dp, app->media_sink);
/* is it mono playback? */
if (app->channel_mode == a2dp_mono)
{
DEBUG(("Mono\n"));
/* plug port 0 into both DACs */
(void) PanicFalse(StreamConnect(StreamKalimbaSource(0),StreamPcmSink(0)));
}
else
{
DEBUG(("Stereo\n"));
/* plug port 0 into Left DAC */
(void) PanicFalse(StreamConnect(StreamKalimbaSource(0),StreamPcmSink(0)));
/* plug port 1 into Right DAC */
(void) PanicFalse(StreamConnect(StreamKalimbaSource(1),StreamPcmSink(1)));
}
/* Start decode */
(void) PanicFalse(KalimbaSendMessage(KALIMBA_MSG_GO,0,0,0,0));
app->led_state |= LED_STREAMING;
app->active_profile = av_active;
app->av_stream_stopped = FALSE;
}
/*************************************************************************
NAME
avHeadsetAvStreamStop
DESCRIPTION
Stop Kalimba streaming audio and discard anything streamed.
Use when activating the hfp profile.
RETURNS
*/
void avHeadsetAvStreamStop(headsetTaskData* app, bool send_suspend)
{
if (app->av_stream_stopped)
return;
DEBUG(("Stream Stop...\n"));
#ifdef INCLUDE_CVC
StreamDisconnect(StreamKalimbaSource(0),StreamPcmSink(0));
StreamDisconnect(StreamKalimbaSource(1),StreamPcmSink(1));
#endif
/* Stop decode */
A2dpAudioCodecDisable(app->a2dp, app->media_sink);
if (send_suspend)
A2dpSuspend(app->a2dp, app->media_sink);
app->led_state &= ~LED_STREAMING;
app->av_stream_stopped = TRUE;
}
/*************************************************************************
NAME
avHeadsetAvStreamStart
DESCRIPTION
Re-Start streaming of audio.
RETURNS
*/
void avHeadsetAvStreamStart(headsetTaskData* app)
{
if (!app->av_stream_stopped)
return;
DEBUG(("Stream Start...\n"));
/* Configure the DACs for the codec configuration */
configureCodec(app);
if (app->sent_suspend)
{
A2dpStart(app->a2dp, app->media_sink);
app->sent_suspend = FALSE;
}
else
avHeadsetStartKalimba(app);
/* Set the local volume back to what it was */
avHeadsetUpdateAvVolume(app->codec_task, app->speaker_volume);
app->led_state |= LED_STREAMING;
/* Let hfpHeadsetHandleScoConnectInd() know that CHF DSP is stopped */
#ifdef INCLUDE_CVC
CvcHeadsetUnloaded();
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -