void CsrSubwooferPluginConnect(Sink audio_sink, Task codec_task, Task app_task, subwooferPluginConnectParams * params) { FILE_INDEX index; /* Update the current DSP status */ SetCurrentDspStatus(DSP_LOADING); /* Give Kalimba the plugin task so it knows where to send messages */ (void) MessageCancelAll( (TaskData*)&csr_subwoofer_plugin, MESSAGE_FROM_KALIMBA); MessageKalimbaTask( (TaskData*)&csr_subwoofer_plugin ); /* Load the Subwofoer DSP application - Panic if it could not be loaded */ index = PanicFalse( FileFind(FILE_ROOT, kal, sizeof(kal) - 1) ); PanicFalse( KalimbaLoad(index) ); /* update current DSP status */ SetCurrentDspStatus(DSP_LOADED_IDLE); /* Allocate memory to store the plugin data */ plugin_data = (subwooferPluginData*)PanicUnlessMalloc(sizeof(subwooferPluginData)); /* Initialise the plugin data based on parameters supplied by the application */ plugin_data->audio_source = StreamSourceFromSink(audio_sink); plugin_data->swat_system_volume_db = params->swat_system_volume_db; plugin_data->swat_trim_gain_db = params->swat_trim_gain_db; plugin_data->adc_volume_index = params->adc_volume; plugin_data->input = params->input; plugin_data->output = params->output; plugin_data->sample_rate = params->sample_rate; plugin_data->adc_sample_rate = params->adc_sample_rate; plugin_data->codec_task = codec_task; plugin_data->app_task = app_task; plugin_data->dsp_set_sample_rate = 0; /* set later in response to AUDIO_PLUGIN_SET_MODE_MSG */ /* Zero the codecs output gain */ CodecSetOutputGainNow(plugin_data->codec_task, 0, left_and_right_ch); CodecSetInputGainNow(plugin_data->codec_task, 0, left_and_right_ch); /* If using the ADC, set the ADC source */ if (plugin_data->input == SUBWOOFER_INPUT_ADC) { /* Get the ADC source */ plugin_data->audio_source = StreamAudioSource(AUDIO_HARDWARE_CODEC, AUDIO_INSTANCE_0, AUDIO_CHANNEL_A); } /* Disconnect the source in case it's currently being disposed */ StreamDisconnect(StreamSourceFromSink(audio_sink), 0); PRINT(("[SW_PLUGIN] : CsrSubwooferPluginConnect - complete\n")); }
/**************************************************************************** NAME connectAudio DESCRIPTION Connects the specified SCO/eSCO channel to the DSP. */ static void connectAudio(Sink audio_sink) { DEBUG_AGHFP((" connectAudio(0x%X)\n", (uint16)audio_sink)); if (audio_sink) { audio_codec_type codec = audio_codec_none; SendEvent(EVT_AUDIO_CONNECT_CFM,0); if(!the_app->bidirect_faststream) { /* Decide the plugin */ the_app->aghfp_audio_plugin = initScoPlugin(); ledSetProfile(LedTypeSCO,TRUE); /* Connect the audio plugin */ AudioConnect(the_app->aghfp_audio_plugin, audio_sink, the_app->sink_type, the_app->codecTask, 0x0a, 0, TRUE, AUDIO_MODE_CONNECTED, (void*)codec ); #ifdef KAL_MSG /* Switch the DSP to SCO mode */ PanicFalse(KalimbaSendMessage(KALIMBA_ENCODER_SELECT, EncoderSco, 0, 0, 0)); #endif AudioSetVolume(the_app->vgs,the_app->codecTask); CodecSetInputGainNow(the_app->codecTask,the_app->vgm,left_and_right_ch); the_app->active_encoder = EncoderSco; } } }
/**************************************************************************** DESCRIPTION This function connects a synchronous audio stream to the pcm subsystem */ void CsrSbcEncoderPluginConnect( Sink audio_sink , Task codec_task , uint16 volume , uint32 rate , bool stereo , AUDIO_MODE_T mode , const void * params ) { /* DSP Application loading and Transform starting is handled by a call to A2dpAudioCodecEnable in the application, so should not be done here. */ const char sbc_encoder[] = "sbc_encoder/sbc_encoder.kap"; FILE_INDEX index = FILE_NONE; typedef struct { uint8 content_protection; uint32 voice_rate; unsigned bitpool:8; unsigned format:8; uint16 packet_size; uint16 clock_mismatch; } sbc_codec_data_type; sbc_codec_data_type *sbc_codecData = (sbc_codec_data_type *) params; if (!sbc_codecData) Panic(); index = FileFind(FILE_ROOT, sbc_encoder, sizeof(sbc_encoder)-1); if (index == FILE_NONE) Panic(); if (!KalimbaLoad(index)) Panic(); if (!KalimbaSendMessage(KALIMBA_CODEC_TYPE_MESSAGE, 0,0,0,0)) Panic(); CodecSetInputGainNow(codec_task,volume,left_and_right_ch); SBC = (SBC_t*)PanicUnlessMalloc (sizeof (SBC_t) ) ; SBC->media_sink[0] = audio_sink ; SBC->codec_task = codec_task ; SBC->packet_size = sbc_codecData->packet_size; StreamDisconnect(StreamKalimbaSource(2), 0); /* Initialise the RTP SBC encoder */ SBC->t[0] = TransformRtpSbcEncode(StreamKalimbaSource(2), audio_sink); /* Configure the RTP transform to generate the selected packet size */ TransformConfigure(SBC->t[0], VM_TRANSFORM_RTP_SBC_ENCODE_PACKET_SIZE, sbc_codecData->packet_size); /* Transform should not manage timings. */ TransformConfigure(SBC->t[0], VM_TRANSFORM_RTP_SBC_ENCODE_MANAGE_TIMING, FALSE); /* Start the transform */ (void) TransformStart(SBC->t[0]); PRINT(("Audio Plugin: TransformStart sink:0x%x\n",(uint16)audio_sink)); if (SBC->media_sink[1]) { /* There is a 2nd audio stream so initialise this transform */ StreamDisconnect(StreamKalimbaSource(3), 0); /* Initialise the RTP SBC encoder */ SBC->t[1] = TransformRtpSbcEncode(StreamKalimbaSource(3), SBC->media_sink[1]); /* Configure the RTP transform to generate the selected packet size */ TransformConfigure(SBC->t[1], VM_TRANSFORM_RTP_SBC_ENCODE_PACKET_SIZE, sbc_codecData->packet_size); /* Transform should not manage timings. */ TransformConfigure(SBC->t[1], VM_TRANSFORM_RTP_SBC_ENCODE_MANAGE_TIMING, FALSE); /* Start the transform */ (void) TransformStart(SBC->t[1]); PRINT(("Audio Plugin: TransformStart sink:0x%x\n",(uint16)SBC->media_sink[1])); } /* Configure SBC encoding format */ if (!KalimbaSendMessage(KALIMBA_MSG_SBCENC_SET_PARAMS, sbc_codecData->format, 0, 0, 0)) /* If message fails to get through, abort */ Panic(); /* Pass bit pool value to DSP */ if (!KalimbaSendMessage(KALIMBA_MSG_SBCENC_SET_BITPOOL, sbc_codecData->bitpool, 0, 0, 0)) /* If message fails to get through, abort */ Panic(); /* disard any data sent by the SNK */ StreamConnectDispose(StreamSourceFromSink(audio_sink)); if (SBC->media_sink[1]) { /* disard any data sent by the 2nd SNK */ StreamConnectDispose(StreamSourceFromSink(SBC->media_sink[1])); } /* select the source type */ { PRINT(("Audio Plugin: SourceAnalog\n")); /* For analogue input source */ StreamDisconnect(StreamPcmSource(0), StreamPcmSink(0)); StreamDisconnect(StreamPcmSource(1), StreamPcmSink(1)); (void)PcmClearAllRouting(); { PRINT(("Audio Plugin: codec_internal\n")); /* configure slot 0 and 1 to be left and right channel and synchronise the offsets for stereo playback */ (void)PcmRateAndRoute(0, PCM_NO_SYNC, (uint32) rate, (uint32) rate, VM_PCM_INTERNAL_A); (void)PcmRateAndRoute(1, 0, (uint32) rate, (uint32) rate, VM_PCM_INTERNAL_B); } /* plug Left ADC into port 0 */ (void)StreamConnect(StreamPcmSource(0),StreamKalimbaSink(0)); /* plug Right ADC into port 1 */ (void)StreamConnect(StreamPcmSource(1),StreamKalimbaSink(1)); /* Select the source type */ PanicFalse(KalimbaSendMessage(KALIMBA_ENCODER_SELECT, 0x0002, 0, 0, 0)); if(!KalimbaSendMessage(KALIMBA_MSG_GO,0,0,0,0)) { PRINT(("SBC: Message KALIMBA_MSG_GO failed!\n")); Panic(); } } /* Select the source type */ /*PanicFalse(KalimbaSendMessage(KALIMBA_SOURCE_SELECT, SOURCE_USB, 0, 0, 0)); */ /*CsrSbcEncoderUsbPluginSetVolume(volume) ;*/ /*(void) StreamConnect(PanicNull(StreamUsbEndPointSource(end_point_iso_in)), StreamKalimbaSink(0)); */ /* Start decode */ /* if(!KalimbaSendMessage(KALIMBA_MSG_GO,0,0,0,0)) { PRINT(("SBC: Message KALIMBA_MSG_GO failed!\n")); Panic(); } */ }