My First Kalimba DSP Application

My First Kalimba DSP Application
BlueCore-Multimedia™
My First Kalimba DSP Application
Application Note
Issue 7
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 1 of 43
CS-101420-ANP7
www.csr.com
Document History
Date
History
a
30 JUN 06
Original publication of this document.(CSR reference bcore-an-084Pa)
2
22 JUL 07
Removed reference to obsolete document.
3
19 NOV 09
Minor correction to VM and DSP source code files. Updated to latest style
guidelines.
4
16 DEC 09
Update the gains on the output codec in the VM_app.
5
21 JUL 10
Changes to VM code to support the new SDK. Project names now in lower
case only.
6
09 FEB 12









7
04 DEC 13
Major changes have been made on VM code to accommodate the
changes in xIDE ADK 2.5 and hardware (CNS10001 Development
board)
Minor changes have been made on DSP code Removed sections 2.1
and 2.2
Added step-by-step steps to build and run Kalimba DSP on CSR8670
and BlueCore5-Multimedia boards
Added code explanation about mic bias and speaker amplifier shutdown control on CSR8670 board
Updated Document references
Updated Appendix A VM Application Code
Updated Appendix B Kalimba DSP Code
Updated Terms and Definitions
Updated document to latest style
Updated for ADK 2.5, minor style corrections.
Contacts
General information
Information on this product
Customer support for this product
More detail on compliance and standards
Help with this document
www.csr.com
[email protected]
www.csrsupport.com
[email protected]
[email protected]
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 2 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Revision
Trademarks, Patents and Licences
Unless otherwise stated, words and logos marked with ™ or ® are trademarks registered or owned by CSR plc
and/or its affiliates.
Other products, services and names used in this document may have been trademarked by their respective
owners.
The publication of this information does not imply that any licence is granted under any patent or other rights
owned by CSR plc or its affiliates.
CSR reserves the right to make technical changes to its products as part of its development programme.
While every care has been taken to ensure the accuracy of the contents of this document, CSR cannot accept
responsibility for any errors.
Life Support Policy and Use in Safety-critical Compliance
CSR’s products are not authorised for use in life-support or safety-critical applications. Use in such applications is
done at the sole discretion of the customer. CSR will not warrant the use of its devices in such applications.
Performance and Conformance
Refer to www.csrsupport.com for compliance and conformance to standards information.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 3 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Bluetooth® and the Bluetooth logos are trademarks owned by Bluetooth SIG, Inc. and licensed to CSR.
Contents
Tables, Figures and Equations
Table 3.1: Stream Library Functions Reference Documents ................................................................................. 17
Table 3.2: Index to Gain Values Mappings ........................................................................................................... 19
Table 3.3: Input Indices to Current and Voltage Settings Mappings...................................................................... 20
Table 3.4: Index to Gain Values Mappings ........................................................................................................... 21
Table 3.5: Using the StreamConnect Function ..................................................................................................... 21
Table 4.1: Example Application DSP Code ........................................................................................................... 24
Figure 2.1: Connecting DEV-PC-1309 Interface Daughterboard to the CNS10001 (CSR8670) Board ................... 7
Figure 2.2: USB-SPI Converter (DEV-SYS-1808-1A) ............................................................................................. 7
Figure 2.3: Setting J3 Jumper ................................................................................................................................. 8
Figure 2.4: Open Workspace .................................................................................................................................. 9
Figure 2.5: my_first_dsp_app Project Properties .................................................................................................. 10
Figure 2.6: Blue Flash ........................................................................................................................................... 11
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 4 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Document History.................................................................................................................................................... 2
Contacts .................................................................................................................................................................. 2
Trademarks, Patents and Licences ......................................................................................................................... 3
Life Support Policy and Use in Safety-critical Compliance ...................................................................................... 3
Performance and Conformance .............................................................................................................................. 3
Contents .................................................................................................................................................................. 4
Tables, Figures and Equations................................................................................................................................ 4
1.
Introduction................................................................................................................................................... 6
2.
Getting Started ............................................................................................................................................. 7
2.1. Building and Running Kalimba DSP Application on CSR8670 Board ....................................................... 7
2.2. Building and Running Kalimba DSP Application on BlueCore5-Multimedia Board ................................. 11
3.
VM Application ........................................................................................................................................... 16
3.1. Loading the DSP Application .................................................................................................................. 16
3.2. Connecting the Audio Stream Path ......................................................................................................... 17
3.3. Starting the Main DSP Application Loop ................................................................................................. 22
3.4. Adding a Pre-processor Conditional Include ........................................................................................... 22
4.
Kalimba Application .................................................................................................................................... 24
4.1. Operators ................................................................................................................................................ 24
4.2. Libraries .................................................................................................................................................. 26
4.3. Routing Audio ......................................................................................................................................... 27
4.4. Application Details .................................................................................................................................. 28
5.
Summary .................................................................................................................................................... 30
Appendix A VM Application Code ....................................................................................................................... 31
Appendix B Kalimba DSP Application Code ....................................................................................................... 35
Document References .......................................................................................................................................... 43
Terms and Definitions ........................................................................................................................................... 43
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 5 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Figure 2.7: USB-SPI Converter (DEV-SYS-1808-1A) ........................................................................................... 11
Figure 2.8: Setting Left and Right Channel Switches ............................................................................................ 12
Figure 2.9: Open Workspace ................................................................................................................................ 13
Figure 2.10: vm-my_first_dsp_app Project Properties .......................................................................................... 14
Figure 2.11: Blue Flash ......................................................................................................................................... 15
Figure 3.1: Initialising Kalimba from the VM .......................................................................................................... 16
Figure 3.2: Project Properties Window: Define Symbols ....................................................................................... 23
Figure 4.1: Stream Object Definition ..................................................................................................................... 25
Figure 4.2: $audio_in_copy_struc Declaration ...................................................................................................... 25
Figure 4.3: $audio_in_left_cbuffer_struc Declaration ............................................................................................ 25
Figure 4.4: Operator Object Definition................................................................................................................... 26
Figure 4.5: $audio_in_left_shift_op Declaration .................................................................................................... 26
Figure 4.6: Using Kalimba Libraries ...................................................................................................................... 27
Figure 4.7: Audio Buffering ................................................................................................................................... 28
Figure 4.8: my_first_dsp_app Outline ................................................................................................................... 29
1.
Introduction
my_first_dsp_app is an example audio application. It uses the Kalimba DSP and the xIDE development
environment. The application routes stereo audio through the DSP and describes how to use the Kalimba
libraries.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 6 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
This document accompanies the example application my_first_dsp_app and describes how to build and run a
basic Kalimba DSP application. It is relevant for DSP-equipped CSR ICs such as the
CSR8670 BlueCore7-Multimedia or BlueCore5-Multimedia and their derivatives.
2.
Getting Started
The instructions for building and running the Kalimba DSP application for CNS10001 development board
(referred to as CSR8670 board in this document) and DEV-PC-1645 board (referred to as BlueCore5-Multimedia
board in this document) are slightly different.
2.1.
1.
Building and Running Kalimba DSP Application on CSR8670 Board
Connect the DEV-PC-1309 interface daughter board to the CSR8670 board, as shown in
Figure 2.1.
Figure 2.1: Connecting DEV-PC-1309 Interface Daughterboard to the CNS10001 (CSR8670) Board
2.
Connect the USB-SPI converter (DEV-SYS-1808-1A) to the DEV-PC-1309 interface daughter board
using RJ45 patch cable. Connect the other end of USB-SPI converter to the PC USB port using the
A-B USB cable, as shown in Figure 2.2.
Figure 2.2: USB-SPI Converter (DEV-SYS-1808-1A)
Alternatively, use a CSR XSPI dongle to connect the DEV-PC-1309 interface daughter board and
the PC parallel port. XSPI dongle converts PC-parallel to RJ45: XSPI dongle connects to the PC
parallel port and RJ45 connects to the DEV-PC-1309 interface daughter board.
3.
Connect the STEREO OUT jack to the speaker or headphone.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 7 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Kalimba DSP applications are developed within the xIDE development environment ADK. Applications are
structured as a workspace which can be made up of a number of projects. When developing a DSP application
the workspace should contain both a VM application and a DSP application. For instructions on how to create
projects in xIDE, see the BlueCore xIDE User Guide.
4.
For the single-ended stereo LINE input, connect the R-MIC and L-MIC jacks to the audio Line-out
jack of the PC or any portable media player through the Y-type audio cable. Set the J3 jumper to
LINE.
For the 2-mic application, connect the R-MIC and L-MIC jacks to the stereo microphones
through the Y-type audio cable.
4.2.
For the 1-mic application, connect either R-MIC or L-MIC jack to the mono microphone.
Set the J3 jumper to MIC.
Set J3 jumper to LINE for
Line-in application or set
J3 jumper to MIC for
microphone input
application
Figure 2.3: Setting J3 Jumper
5.
Connect a USB cable to the CSR8670 board to provide 5 V power supply.
6.
Turn the Power switch ON.
7.
Launch ADK 2.5.
8.
Locate the project workspace my_first_dsp_app.xiw by selecting Project | Open Workspace ... within
xIDE.
The project file my_first_dsp_app.xiw is in
C:\ADK2.5_INSTALL\apps\examples\my_first_dsp_app. ADK2.5 is installed in the C:\ADK2.5_INSTALL
directory by default. You can copy and save it anywhere or create your own Kalimba DSP project.
For instructions, see the BlueCore xIDE User Guide.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 8 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
4.1.
9.
To set the Execution mode to Assisted Native, right-click vm – ‘my_first_dsp_app and select
Properties... | Build System.
For more information about execution modes (VM, Assisted Native and Native), see the
BlueCore Classic vs Native VM vs Assisted Native VM Application Note.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 9 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Figure 2.4: Open Workspace
10.
The default setting for the VM code in file main.c is for BlueCore5-Multimedia board and line-in
input. To change it to use in the CSR8670 board and line-in input, comment out #define GORDON
in line 20 or add the symbol GORDON in Define symbols. To do this, right-click vm –
„my_first_dsp_app and select Properties... | Build System, as shown in Figure 2.5.
11.
Build the application by hitting key F7, which compiles and links the code for both VM and DSP.
Alternatively, right-click kalimba – „my_first_dsp_app_kalimba and select Build and rightclick vm – „my_first_dsp_app and select Build.
12.
Run the Kalimba DSP application by hitting the key F5. This step flashes the executable binary
image to the hardware and runs the application in debugging mode.
Alternatively, use the xIDE to generate the executable binary image. To do this, hit the key F7and
use the flash tool BlueFlash to flash and run the application.
You must set the Build merge to Yes in the VM Project Properties window or the executable image
merge.xpv (.xdv) will not generate. See Figure 2.5. CSR recommends this approach because it is
more efficient and productive.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 10 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Figure 2.5: my_first_dsp_app Project Properties
After completing Step 12, a speaker or headphone will play music. This example code routes the audio from ADC
to DSP and then from DSP to DAC. As an exercise, you can bypass the DSP and route audio from ADC to DAC
directly without passing the DSP. To do this, comment out Line 28: #define BYPASS_KALIMBA. You can also
add the symbol BYPASS_KALIMBA in Define symbols, described Step 10 and repeat
Steps 11 and 12. If there is more than one symbol (pre-processors), separate all symbols with a comma.
To use microphone input, follow steps 1-13 but comment out Line 30: #define MIC_INPUT. You can also add
the symbol MIC_INPUT in Define symbols described in Step 10. You must set Jumper J3 to MIC, as described in
Step 4.
2.2.
Building and Running Kalimba DSP Application on BlueCore5Multimedia Board
1.
Connect the DEV-PC-1309 interface daughter board to the BlueCore5-Multimedia board.
2.
Connect the USB-SPI converter (DEV-SYS-1808-1A) to the DEV-PC-1309 interface daughter board
using the RJ45 patch cable. Connect the other end of USB-SPI converter to the PC USB port using
the A-B USB cable.
Alternatively, use a CSR XSPI dongle to connect the DEV-PC-1309 interface daughter board and
the PC parallel port. XSPI dongle converts PC-parallel to RJ45: XSPI dongle connects to the PC
parallel port and RJ45 connects to the DEV-PC-1309 interface daughter board.
Figure 2.7: USB-SPI Converter (DEV-SYS-1808-1A)
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 11 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Figure 2.6: Blue Flash
3.
Connect the AUDIO OUT jack to the speaker or headphone.
4.
For the single-ended stereo LINE input, connect the LINE IN jack to the audio Line-out jack of a PC
or any portable media player. Set both Left and Rich channel MIC/DIFF/LINE switches to LINE.
Because BlueCore5-Multimedia board only supports mono microphone, setting the Left channel
switch to MIC is sufficient However, if LINE IN jack is connected to the Line-out jack of PC, low
frequency noise will be populated to the microphone front-end circuitry through the Line-in jack. In
this case, Right channel switch should also be switched to MIC or DIFF.
Set Left and Right channel switches to LINE for Line-in application
or set to MIC for microphone input application
Figure 2.8: Setting Left and Right Channel Switches
5.
Connect USB cable to the BlueCore5-Multimedia board to provide 5V power supply.
6.
Turn the Power switch ON.
7.
Launch ADK 2.5.
8.
Locate the project workspace my_first_dsp_app.xiw by selecting Project | Open Workspace ...
within xIDE, see Figure 2.9.
The project file my_first_dsp_app.xiw is in
C:\ADK2.5_INSTALL\apps\examples\my_first_dsp_app. By default the ADK2.5 is installed
in the C:\ADK2.5_INSTALL directory. You can copy and save it to anywhere or create your own
Kalimba DSP project. For instructions see the BlueCore xIDE User Guide.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 12 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
For the microphone input application, connect MIC IN jack to the microphone. The BlueCore5Multimedia board only supports mono microphone. Set the Left channel MIC/DIFF/LINE switches to
MIC, as shown in Figure 2.8.
9.
Set the Execution mode to Native. Right-click vm – 'my_first_dsp_app' and select
Properties... | Build System.
For more information about execution modes (VM, Assisted Native and Native), see the
BlueCore Classic vs. Native VM vs. Assisted Native VM Application Note.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 13 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Figure 2.9: Open Workspace
10.
The default setting for the VM code in file main.c is for BlueCore5-Multimedia board and line-in
input. To run in other modes (such as microphone input or bypass DSP), comment out related lines
or add the related symbols in Define symbols. To do this, right-click vm – „my_first_dsp_app‟
and select Properties... | Build System, see Figure 2.10.
11.
Build the application by pressing the F7 key, which compiles and links the code for both VM and
DSP.
Alternatively, right-click kalimba – „my_first_dsp_app_kalimba‟ and select Build..
Right-click vm – „my_first_dsp_app‟ and select Build.
12.
Run the Kalimba DSP application by pressing the F5 key. This step flashes the executable binary
image to the hardware and runs the application in debugging mode.
Alternatively, use the xIDE to generate the executable binary image. To do this, press the F7 key
and use the flash tool BlueFlash to flash and run the application.
You must set the Build merge to Yes in the VM Project Properties window or the executable image
merge.xpv (.xdv) does not generate. See Figure 2.5. CSR recommends this approach because
it is more efficient and productive.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 14 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Figure 2.10: vm-my_first_dsp_app Project Properties
After completing Step 12, a speaker or headphone will play the music. This example code routes the audio from
ADC to DSP and then from DSP to DAC. As an exercise, you can bypass the DSP and route audio from ADC to
DAC directly without passing the DSP. To do this, comment out Line 28: #define BYPASS_KALIMBA. You can
also add the symbol BYPASS_KALIMBA in Define symbols, as described Step 10 and repeat
Steps 11 and 12. If there is more than one symbol (pre-processors), separate all symbols with a comma.
To use microphone input, follow steps 1-13 but comment out Line 30: #define MIC_INPUT. You can also add
the symbol MIC_INPUT in Define symbols described in Step 10. You must set the Left channel MIC/DIFF/LINE
switch to MIC as described in Step 4.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 15 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Figure 2.11: Blue Flash
3.
VM Application
In the example application my_first_dsp_app, the VM application is responsible for:
1.
Setting up the Kalimba DSP
2.
Connecting the audio stream path
3.
Starting the main DSP application loop
DSP
VM
KalimbaLoad
1)
Zero RAM
Populate RAM with kap file
Set running
Initialises
Time
StreamConnect
(n)
2)
3)
KALIMBA_MSG_GO
Application loop
Figure 3.1: Initialising Kalimba from the VM
The VM also initialises the input and output gain of the codecs.
3.1.
Loading the DSP Application
To load the DSP application, the VM application code must do the following.
1.
Find the appropriate file in the file system:
Note:
The root is the \image directory.
static const char kal[] =
"my_first_dsp_app_kalimba/my_first_dsp_app_kalimba.kap";
FILE_INDEX index = FileFind( FILE_ROOT,(const char *)kal, strlen(kal) );
2.
Load the specified DSP code into Kalimba.
KalimbaLoad( index );
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 16 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
The VM code runs in the main processor. It loads the DSP executable image to the DSP processor, connects the
ADC and DAC to the Kalimba DSP ports, starts the DSP code and runs an infinitive loop. VM code runs in master
processor and DSP code runs in slave Kalimba DSP processor.
3.2.
Connecting the Audio Stream Path
This section describes how to configure the functions that relate to the audio stream path, specifically as it relates
to the sample code.
Streams, as implemented in the firmware, include two halves, a source and a sink. A source produces a byte
stream while a sink consumes it.
Streams can represent a variety of data sources from PCM audio to UART data. Section 3.2.5 describes how to
use the StreamConnect() function to route PCM audio between the PCM subsystem and the DSP. For more
information about the stream library functions, see the VM and Native Reference Guide files listed in Table 3.1.
Document Name
Directory Location
stream.8h.html
<SDK Installation
Path>\doc\reference\html\
stream.h
<SDK Installation
Path>\tools\include\firmware\
Table 3.1: Stream Library Functions Reference Documents
3.2.1.
Defining the Source and Sinks
The following function calls define the audio sources. The left and right channels are assigned to channel A
and B, respectively:
Source audio_source_a = StreamAudioSource( AUDIO_HARDWARE_CODEC,
AUDIO_INSTANCE_0, AUDIO_CHANNEL_A );
Source audio_source_b = StreamAudioSource( AUDIO_HARDWARE_CODEC,
AUDIO_INSTANCE_0, AUDIO_CHANNEL_B );
The following function calls define the audio sinks. The left and right channels are assigned to channel A
and B, respectively:
Sink audio_sink_a = StreamAudioSink( AUDIO_HARDWARE_CODEC, AUDIO_INSTANCE_0,
AUDIO_CHANNEL_A );
Sink audio_sink_b = StreamAudioSink( AUDIO_HARDWARE_CODEC, AUDIO_INSTANCE_0,
AUDIO_CHANNEL_B );
3.2.2.
Configuring the Sampling Rate and Synchronisation
The following function calls configure the sampling rates of the left and right input channels to 44.1 kHz:
SourceConfigure(audio_source_a, STREAM_CODEC_INPUT_RATE, 44100);
SourceConfigure(audio_source_b, STREAM_CODEC_INPUT_RATE, 44100);
The following function call synchronises the left and right input channels:
SourceSynchronise(audio_source_a, audio_source_b);
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 17 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
The my_first_dsp_app application utilises the stream library to quickly route data from the PCM input ports
through the DSP and to the PCM output ports via streams.
The following function calls configure the sampling rates of the left and right output channels to 44.1kHz:
SinkConfigure(audio_sink_a, STREAM_CODEC_OUTPUT_RATE, 44100);
SinkConfigure(audio_sink_b, STREAM_CODEC_OUTPUT_RATE, 44100);
SinkSynchronise(audio_sink_a, audio_sink_b);
3.2.3.
Configuring the ADC Gain Setting
The following function calls configure the input channel gains to -3.0 dB.
To configure the input gain for the left channel use:
SourceConfigure(audio_source_a, STREAM_CODEC_INPUT_GAIN, 8);
To configure the input gain for the right channel use:
SourceConfigure(audio_source_b, STREAM_CODEC_INPUT_GAIN, 8);
Note:
Table 3.2 shows the input_gain given in the form of an index (0-22) that is mapped to an actual
gain/attenuation value.
Index
Gain (db)
0
-27.0
1
-23.5
2
-21.0
3
-17.5
4
-15.0
5
-11.5
6
-9.0
7
-5.5
8
-3.0
9
0.0
10
3.0
11
6.0
12
9.0
13
12.5
14
15.0
15
18.0
16
21.5
17
24.0
18
27.5
19
30.0
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 18 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
The following function call synchronises the left and right output channels:
Gain (db)
20
33.5
21
36.0
22
39.5
Table 3.2: Index to Gain Values Mappings
The following function calls control the preamps for the left and right input channels (disabled in the example).
When enabled this adds an extra 24.5 dB in addition to the selected input gain from Table 3.2.
SourceConfigure(audio_source_a, STREAM_CODEC_MIC_INPUT_GAIN_ENABLE, 0);
SourceConfigure(audio_source_b, STREAM_CODEC_MIC_INPUT_GAIN_ENABLE, 0);
For microphone pre-amp circuitry to work, the BlueCore chips’ BIAS_MIC pins must be properly DC biased. To
do this, use the following code:
MicbiasConfigure(MIC_BIAS_0, MIC_BIAS_ENABLE, MIC_BIAS_FORCE_ON);
MicbiasConfigure(MIC_BIAS_1, MIC_BIAS_ENABLE, MIC_BIAS_FORCE_ON);
You only need the first line of code for the BlueCore5-Multimedia board because only one microphone is used.
Note:
In the provided source code, the MicbiasConfigure()function call is conditionally compiled according to
the definition of the MIC_INPUT macro. To use this function include the micbias.h header file in the
VM application.
In addition to enabling the current, you can configure both the current and voltage of the microphone bias using
the function calls:
MicbiasConfigure( MIC_BIAS_0, MIC_BIAS_CURRENT, current );
MicbiasConfigure( MIC_BIAS_0, MIC_BIAS_VOLTAGE, voltage );
Note:
The bias current and voltage are given in the form of indices (0-15) that are mapped to actual values.
See Table 3.3.
Index
Voltage (V)
Current (mA)
0
1.72
0.32
1
1.77
0.40
2
1.83
0.48
3
1.89
0.56
4
1.97
0.64
5
2.53
0.72
6
2.12
0.80
7
2.20
0.88
8
2.34
0.97
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 19 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Index
Voltage (V)
Current (mA)
9
2.44
1.05
10
2.58
1.13
11
2.71
1.21
12
2.92
1.29
13
3.10
1.37
14
3.34
1.45
15
3.69
1.53
Table 3.3: Input Indices to Current and Voltage Settings Mappings
CSR8670 board speaker/headphone output is powered by stereo headphone amplifier with shutdown function.
When the speaker amplifier shutdown pin is driven down by active-low voltage, the amplifier is disabled and the
audio is muted. In the CSR8670 board, control this shutdown pin by setting the PIO pin PIO_4.
PioSetPio(GORDON_POWER_AMP_PIO, TRUE);
where GORDON_POWER_AMP_PIO is defined as 4.
3.2.4.
Configuring DAC Gain Setting
The following function calls configure the output channel gains to 0.0dB.
To configure the output gain for the left channel use:
SinkConfigure(audio_sink_a, STREAM_CODEC_OUTPUT_GAIN, 15);
To configure the output gain for the right channel use:
SinkConfigure(audio_sink_b, STREAM_CODEC_OUTPUT_GAIN, 15);
Note:
Table 3.4 provides the output_gain, given in the form of an index (0-22) that is mapped to an actual
gain/attenuation value.
Index
Gain (dbFS)
0
-45.0
1
-41.5
2
-39.0
3
-35.5
4
-33.0
5
-29.5
6
-27.0
7
-23.5
8
-21.0
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 20 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Index
Gain (dbFS)
9
-18.0
10
-15.0
11
-12.5
12
-9.0
13
-6.0
14
-3.0
15
0.0
16
3.5
17
6
18
9.5
19
12
20
15.5
21
18
22
21.5
Table 3.4: Index to Gain Values Mappings
Note:
Index values greater than 15 can cause saturation in the digital gain stage of the DAC output.
3.2.5.
Using the StreamConnect Function
This section provides guidelines on using the StreamConnect() function to route PCM audio between the PCM
subsystem and the DSP:
Function
Description
StreamConnect(audio_source_a, StreamKalimbaSink(0));
Connects the left channel audio
source to the DSP read port 0
StreamConnect(audio_source_b, StreamKalimbaSink(1));
Connects the right channel audio
source to the DSP read port 1
StreamConnect(StreamKalimbaSource(0), audio_sink_a);
Connects the DSP write port 0 to the
left channel audio sink
StreamConnect(StreamKalimbaSource(1), audio_sink_b);
Connects the DSP write port 1 to the
right channel audio sink
Table 3.5: Using the StreamConnect Function
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 21 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Index
3.3.
Starting the Main DSP Application Loop
To start the main DSP application loop, use the following two functions:
1.
DSP:
2.
VM:
KalimbaSendMessage(KALIMBA_MSG_GO,0,0,0,0);
The function starts the DSP application. After sending this message, the VM application enters the
MessageLoop() routine to service any received messages.
3.4.
Adding a Pre-processor Conditional Include
The pre-processor allows conditional compilation of source code by using the #ifdef, #else, and #endif
directives. This is useful for quickly switching between different versions of code at compile time. For example,
the VM application uses the pre-processor directives to compile code that enables the microphone input by
defining MIC_INPUT, or to route the audio around the DSP by defining BYPASS_KALIMBA.
These pre-processor statements can be defined in the source code as:
#define MIC_INPUT
#define BYPASS_KALIMBA
These statements can also be included in the Define Symbols field on the Project Properties window. Figure 3.2
uses the #define MIC_INPUT statement.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 22 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
$message.send_ready_wait_for_go
This function sends a message to the VM firmware indicating that it has finished its initialisation and
is ready to begin processing. The DSP remains in a wait loop until it receives the
KALIMBA_MSG_GO from the VM application.
The MIC_INPUT statement is defined in the Define
symbols field on the Project Properties window
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Figure 3.2: Project Properties Window: Define Symbols
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 23 of 43
CS-101420-ANP7
www.csr.com
4.
Kalimba Application
This section describes the Kalimba application code. All the DSP code for the example application is in the
module my_first_dsp_app.asm. Each function is contained within the following instructions:
.CODESEGMENT PM;
.DATASEGMENT DM;
// … Function implementation here
.ENDMODULE;
These instructions specify the name of the function in the module, and which memory banks the code and data
segments should reside in.
Table 4.1 describes the modules that contain all DSP code for the example application.
Module
Description
$M.main (my_first_dsp_app.asm):
Contains the main DSP application that
initialises the DSP, defines the linked list of
operators, starts the audio timers and
enters copy_loop
$M.audio_in_copy_handler (my_first_dsp_app.asm)
Calls $cbops.copy for the
$audio_in_copy_struc and schedules
the next input audio timer
$M.audio_out_copy_handler (my_first_dsp_app.asm)
Calls $cbops.copy for the
$audio_out_copy_struc and
schedules the next output audio timer
$M.loopback_copy (my_first_dsp_app.asm)
Calls $cbops.copy for the
$audio_loopback_copy_struc
Table 4.1: Example Application DSP Code
4.1.
Operators
The my_first_dsp_app code uses the current cbops operator structure to route data in and out of the DSP
ports through cbuffers. This section describes the operator structure.
Operators can be separated into two levels:
1.
Stream Object
2.
Operator Object
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 24 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
.MODULE $module_name.function_name;
4.1.1.
Stream Object Level
The Stream Object level is the highest level. It defines the number of inputs and outputs and identifies these
possible PORTS or cbuffers. It also contains the pointer to the first operator in the linked list. Figure 4.6 shows
the generic Stream Object definition and FIR filter specific Stream Object declaration.
$cbops.OPERATOR_STRUC_ADDR_FIELD
Number of Inputs
**** CBUFFER/PORT Identifiers ****
Number of Outputs
**** CBUFFER/PORT Identifiers ****
Figure 4.1: Stream Object Definition
.VAR $audio_in_copy_struc[] =
&$audio_in_left_shift_op,
2,
$AUDIO_LEFT_IN_PORT,
$AUDIO_RIGHT_IN_PORT,
2,
&$audio_in_left_cbuffer_struc,
&$audio_in_right_cbuffer_struc;
//
//
//
//
//
//
//
First operator block
Number of inputs
Input
Input
Number of outputs
Output
Output
Figure 4.2: $audio_in_copy_struc Declaration
Figure 4.2 shows the first operator in the linked list is $ audio_in_left_shift_op.
This Stream Object uses two inputs (input ports)

$AUDIO_LEFT_IN_PORT

$AUDIO_RIGHT_IN_PORT,
and two outputs (cbuffers)

$audio_in_left_cbuffer_struc

$audio_in_right_cbuffer_struc.
Note:
The cbuffer outputs are not the actual cbuffers, but the cbuffer structures. The cbuffer structure contains the
read and write pointer locations as well as the size of the cbuffer. Figure 4.3 shows the
$audio_in_left_cbuffer_struc cbuffer structure declaration.
// ** allocate memory for cbuffer structures **
.VAR $audio_in_left_cbuffer_struc[$cbuffer.STRUC_SIZE] =
LENGTH($audio_in_left),
// size
&$audio_in_left,
// read pointer
&$audio_in_left;
// write pointer
Figure 4.3: $audio_in_left_cbuffer_struc Declaration
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 25 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Stream Object
4.1.2.
Operator Object Level
Operator Object
$cbops.NEXT_OPERATOR_ADDR_FIELD
$cbops.FUNCTION_VECTOR_FIELD
$cbops.PARAMETER_AREA_START_FIELD
< operator specific parameters >
Figure 4.4: Operator Object Definition
.BLOCK $audio_in_left_shift_op;
.VAR $audio_in_left_shift_op.next =
&$audio_in_left_dc_remove_op;
.VAR $audio_in_left_shift_op.func = &$cbops.shift;
.VAR $audio_in_left_shift_op.param[$cbops.shift.STRUC_SIZE]
=
0,
// Input index
2,
// Output index
8;
// Shift amount
.ENDBLOCK;
Figure 4.5: $audio_in_left_shift_op Declaration
The first element in Figure 4.5 points to the next operator in the linked list, which is
$audio_in_left_dc_remove_op.
The second element points to the function vector (&$cbops.shift) of the current operator
($audio_in_left_shift_op).
The third element defines the shift -specific parameters.

The input index 0, refers to $AUDIO_LEFT_IN_PORT (the input to the cbops.shift operator is
$AUDIO_LEFT_IN_PORT).

The output index, 2, refers to $audio_in_left_cbuffer_struc (the output of the cbops.shift
operator is $audio_in_left_cbuffer_struc).

The shift amount number 8 left shift input data by 8 bits which converts the 16-bit data into 24-bit data.
4.2.
Libraries
The application uses two Kalimba libraries:

The core library provides an API for buffers in Kalimba memory (which are called cbuffers) and the
Memory Management Unit (MMU) ports, which streams data between the BlueCore subsystem and the
Kalimba.
Core libraries have functions that do the following:

Set-up the interrupt controller

Send and receive messages from the VM application

Manage a simple stack
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 26 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
The Operator Object level is below the Stream Object level. It contains the address to the next operator in the
linked list, the current operator function vector, and the list of operator specific parameters. To terminate the
linked list set the next operator field to $cbops.NO_MORE_OPERATORS. Figure 4.4 and Figure 4.5 show the
generic Operator Object and FIR filter specific Operator Object declaration.

The cbops library provides routines to copy data between buffers/ports while doing some form of
processing. Operator functions, which are held in a linked list, carry out processing. The library contains a
number of operators to perform frequently required functionality. You can also write custom functions, as
needed.
Using Kalimba Libraries
To use the Kalimba libraries the application must include the relevant library header files such as:
#include “core_library.h”
This define is included in the source file. In addition, the libraries must be listed in the project’s properties. These
can be added in xIDE by selecting Properties… in the xIDE Project menu.
Add libraries in the Build System section of the Project Properties window. See Figure 4.6. Multiple libraries must
be comma separated.
Figure 4.6: Using Kalimba Libraries
4.3.
Routing Audio
The example application, my_first_dsp_app, routes stereo audio from the ADC to the DAC. The ADC and
DAC are free-running and controlled by hardware. Their buffers are managed by the Memory Management Unit
(MMU). The DSP has its own input and output circular connection buffers known as cbuffers.
The example Kalimba application has three parts. See Figure 4.7
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 27 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
4.2.1.
2)
3)
cbuffer
DSP
XAP RAM
Foreground task
Background task
Figure 4.7: Audio Buffering
The three parts of the application are:
1.
Copying audio from the MMU to input cbuffers
2.
Copying audio from the input cbuffers to the output cbuffers
3.
Copying audio from the output cbuffer to the MMU
4.4.
Application Details
The input and output processes (steps 1 and 3 in Figure 4.7) are handled in interrupt routines. These input and
output processes are effectively handled in the background.
Each of the three parts of the application involves copying audio between buffers. Each step is a separate linked
list of operations that copy and process the audio. This linked list of operations (or cbops) specifies audio
processing. The operators in the list are configurable; you can add custom processes by writing new operations.
In my_first_dsp_app, the operator list for the input copy in Step 1 of Figure 4.7 includes a shift of the audio
and removal of any DC. The shift is carried out because the data memory is 24 bits wide and the PCM audio
supplied by the codec is 16 bits wide.
Note:
Further operations could be carried out during this input copy, such as amplifying or attenuating the signal by
a further shift or checks for overflow.
In the foreground, the main application loop calls a function to copy audio from the input cbuffer to the output
cbuffer, step 2 in Figure 4.7. It then sleeps for 1 ms (time permitting) to save power.
For the duration of the copy routine call interrupts must be blocked to prevent memory corruption. As with the
input and output steps, this copying is carried out as part of a linked list of operators. It is possible to insert
processing tasks as required into the list.
Figure 4.8 shows the structure of the Kalimba application. This code is in my_first_dsp_app.asm.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 28 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
1)
Allocate memory for cbuffers: audio in left, audio in right, audio out left, right out left
Allocate memory for cbuffers structures
Appendix A
Audio in left, audio in right, audio out left, right out left
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Appendixmemory
B
Allocate
for timer structures
Appendix C
Audio in left, audio in right, audio out left, right out left
Appendix D
Allocate
memory
copy
routines:
Appendix
E for cbops stereo input
Audio
in left,
audio in right, audio out left, right out left

Audio
Appendix
F in copy structure

cbops

Audio in left shift operation

Audio in left dc remove operation

Audio in right shift operation

Audio in right dc remove operation
Allocate memory for cbops stereo output copy routines:

Audio out copy structure

cbops

Audio out left dc remove operation

Audio out left shift operation

Audio out right dc remove operation

Audio out right shift operation
Allocate memory for cbops loopback copy routines:

Audio copy structure

cbops

Audio left copy

Audio right copy
Initialise various library functionality (e.g. stack, interrupt, message, cbuffer)
Wait for ADC buffers to wrap – Start timer that copies input samples
Wait for DAC buffers to wrap – start timer that copies output samples
Loop
If audio to
copy
Blocks interrupts and performs loopback copy routines
If no audio
to copy
Sleeps 1 ms to save power
Figure 4.8: my_first_dsp_app Outline
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 29 of 43
CS-101420-ANP7
www.csr.com
5.
Summary
This application works BlueCore ICs which include a DSP e.g. BlueCore5-Multimedi, BlueCore7-Multimedia and
derivatives.
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 30 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
This application note introduces the xIDE development environment and describes how to build and run a basic
DSP application. The application uses the supplied Kalimba libraries: it uses connection buffers to read and write
from the ports and the cbops linked list of operators to copy and process audio. This cbops framework provides
the means to configure operators to achieve the desired processing of the audio. In addition, new custom
operators can be inserted as required.
Appendix A
VM Application Code
The following C source code is provided in:
<SDK Installation folder>\Examples\my_first_dsp_app folder
/*
Copyright (C) Cambridge Silicon Radio Ltd. 2006 ~ 2012
An example app for routing audio through the Kalimba DSP from ADC to DAC
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
<kalimba.h>
<kalimba_standard_messages.h>
<file.h>
<string.h>
<panic.h>
<source.h>
<sink.h>
<stream.h>
<connection.h>
<micbias.h>
/* Define preprocessor GORDON to use the Gordon board, otherwsie the Elvis board is
assumed. */
/* #define GORDON */
#ifdef GORDON
#include <pio.h>
void PioSetPio (uint16 pPIO , bool pOnOrOff);
#define GORDON_POWER_AMP_PIO 4
#endif
/* Define the macro "BYPASS_KALIMBA" to bypasss Kalimba DSP otherwise direct ADC>DAC */
/* #define BYPASS_KALIMBA */
/* Define the macro "MIC_INPUT" for microphon input otherwise line-in input */
/* #define MIC_INPUT */
/* Location of DSP kap file in the file system */
static const char kal[] = "my_first_dsp_app_kalimba/my_first_dsp_app_kalimba.kap";
uint16 sampleRate = 44100;
void start_kalimba(void);
void connect_streams(void);
/* Main VM routine */
int main(void)
{
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 31 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Do not cut and paste the following sample code for use.
/* Load the Kalimba */
start_kalimba();
/* Connect up the ADCs and DACS */
connect_streams();
/* Remain in MessageLoop (handles messages) */
MessageLoop();
return 0;
}
void start_kalimba(void)
{
/* Find the codec file in the file system */
FILE_INDEX index = FileFind( FILE_ROOT, (const char *)kal, strlen(kal) );
/* Did we find the desired file? */
PanicFalse( index != FILE_NONE );
/* Load the codec into Kalimba */
PanicFalse( KalimbaLoad( index ) );
}
}
void connect_streams(void)
{
/* Access left and right ADC and DAC */
Source audio_source_a = StreamAudioSource( AUDIO_HARDWARE_CODEC,
AUDIO_INSTANCE_0, AUDIO_CHANNEL_A );
Source audio_source_b = StreamAudioSource( AUDIO_HARDWARE_CODEC,
AUDIO_INSTANCE_0, AUDIO_CHANNEL_B );
Sink audio_sink_a = StreamAudioSink( AUDIO_HARDWARE_CODEC, AUDIO_INSTANCE_0,
AUDIO_CHANNEL_A );
Sink audio_sink_b = StreamAudioSink( AUDIO_HARDWARE_CODEC, AUDIO_INSTANCE_0,
AUDIO_CHANNEL_B );
/* Configure sampling rate for both channels and synchronise left and right
channels */
PanicFalse( SourceConfigure(audio_source_a, STREAM_CODEC_INPUT_RATE,
sampleRate) );
PanicFalse( SourceConfigure(audio_source_b, STREAM_CODEC_INPUT_RATE,
sampleRate) );
PanicFalse(
PanicFalse(
);
PanicFalse(
);
PanicFalse(
SourceSynchronise(audio_source_a, audio_source_b) );
SinkConfigure(audio_sink_a, STREAM_CODEC_OUTPUT_RATE, sampleRate)
SinkConfigure(audio_sink_b, STREAM_CODEC_OUTPUT_RATE, sampleRate)
SinkSynchronise(audio_sink_a, audio_sink_b) );
/* Set up codec gains */
#ifdef MIC_INPUT
PanicFalse( SourceConfigure(audio_source_a, STREAM_CODEC_MIC_INPUT_GAIN_ENABLE,
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 32 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
/* Start the Kalimba */
PanicFalse( KalimbaSendMessage(KALIMBA_MSG_GO,0,0,0,0) );
#else
PanicFalse( SourceConfigure(audio_source_a, STREAM_CODEC_MIC_INPUT_GAIN_ENABLE,
0) );
PanicFalse( SourceConfigure(audio_source_b, STREAM_CODEC_MIC_INPUT_GAIN_ENABLE,
0) );
#endif
PanicFalse( SourceConfigure(audio_source_a, STREAM_CODEC_INPUT_GAIN, 10) );
PanicFalse( SourceConfigure(audio_source_b, STREAM_CODEC_INPUT_GAIN, 10) );
#ifdef GORDON
PioSetPio(GORDON_POWER_AMP_PIO, TRUE);
#endif
PanicFalse( SinkConfigure(audio_sink_a, STREAM_CODEC_OUTPUT_GAIN, 15) );
PanicFalse( SinkConfigure(audio_sink_b, STREAM_CODEC_OUTPUT_GAIN, 15) );
#ifdef BYPASS_KALIMBA
/* Plug Left ADC directly into left DAC */
PanicFalse( StreamConnect(audio_source_a, audio_sink_a) );
/* Plug Right ADC directly into right DAC */
PanicFalse( StreamConnect(audio_source_b, audio_sink_b) );
#else
/* Plug Left ADC into port 0 */
PanicFalse( StreamConnect(audio_source_a, StreamKalimbaSink(0))
/* Plug Right ADC into port 1 */
PanicFalse( StreamConnect(audio_source_b, StreamKalimbaSink(1))
/* Plug port 0 into Left DAC */
PanicFalse( StreamConnect(StreamKalimbaSource(0), audio_sink_a)
/* Plug port 1 into Right DAC */
PanicFalse( StreamConnect(StreamKalimbaSource(1), audio_sink_b)
);
);
);
);
#endif
}
#ifdef GORDON
void PioSetPio (uint16 pPIO , bool pOnOrOff)
{
uint16 lPinVals = 0 ;
uint16 lWhichPin = (1<< pPIO) ;
if ( pOnOrOff )
{
lPinVals = lWhichPin
;
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 33 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
1) );
PanicFalse( SourceConfigure(audio_source_b, STREAM_CODEC_MIC_INPUT_GAIN_ENABLE,
1) );
PanicFalse(MicbiasConfigure(MIC_BIAS_0, MIC_BIAS_ENABLE, MIC_BIAS_FORCE_ON));
#ifdef GORDON
PanicFalse(MicbiasConfigure(MIC_BIAS_1, MIC_BIAS_ENABLE,
MIC_BIAS_FORCE_ON));
#endif
}
else
{
lPinVals = 0x0000;/*clr the corresponding bit*/
}
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 34 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
/*(mask,bits) setting bit to a '1' sets the corresponding port as an output*/
PioSetDir32( lWhichPin , lWhichPin );
/*set the value of the pin*/
PioSet32 ( lWhichPin , lPinVals ) ;
#endif
Appendix B
Kalimba DSP Application Code
The following Kalimba code is provided in:
<SDK Installation folder>\Examples\my_first_dsp_app folder
//******************************************************************************
// Copyright (C) Cambridge Silicon Radio plc 2006 ~ 2012 http://www.csr.com
// *****************************************************************************
// *****************************************************************************
// DESCRIPTION
// An example app for routing audio through the Kalimba DSP from ADC to DAC
//
// NOTES
//
// What the code does:
//
Sets up cbuffers (circular connection buffers) for reading audio from
//
the ADC and routing to the DAC. Cbuffers are serviced by timer
//
interrupts.
// *****************************************************************************
//
//
//
//
//
//
1.5ms is chosen as the interrupt rate for the audio input/output
because: ADC/DAC MMU buffer is 256byte = 128samples
- up to 8 sample FIFO in voice interface
= 120samples = 2.5ms @ 48kHz
Assume absolute worst case jitter on interrupts = 1ms
Hence choose 1.5ms between audio input/output interrupts
#define
#define
#define
#define
#define
$TMR_PERIOD_AUDIO_COPY
$AUDIO_CBUFFER_SIZE
$DATA_COPIED
$DATA_NOT_COPIED
$TONES_BLOCK_SIZE
1500
512
0
1
$AUDIO_CBUFFER_SIZE/2
// Standard includes
#include "core_library.h"
#include "cbops_library.h"
.MODULE $M.main;
.CODESEGMENT PM;
.DATASEGMENT DM;
$main:
// ** Setup ports that are to be used **
.CONST $AUDIO_LEFT_IN_PORT
($cbuffer.READ_PORT_MASK + 0);
.CONST $AUDIO_RIGHT_IN_PORT
($cbuffer.READ_PORT_MASK + 1);
.CONST $AUDIO_LEFT_OUT_PORT
($cbuffer.WRITE_PORT_MASK + 0);
.CONST $AUDIO_RIGHT_OUT_PORT
($cbuffer.WRITE_PORT_MASK + 1);
// ** Allocate memory for cbuffers **
// cbuffers are 'circular connection buffers'
.VAR/DMCIRC $audio_in_left[$AUDIO_CBUFFER_SIZE];
.VAR/DMCIRC $audio_in_right[$AUDIO_CBUFFER_SIZE];
.VAR/DMCIRC $audio_out_left[$AUDIO_CBUFFER_SIZE];
.VAR/DMCIRC $audio_out_right[$AUDIO_CBUFFER_SIZE];
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 35 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Do not cut and paste the following sample code for use.
.VAR $audio_in_right_cbuffer_struc[$cbuffer.STRUC_SIZE] =
LENGTH($audio_in_right),
// Size
&$audio_in_right,
// Read pointer
&$audio_in_right;
// Write pointer
.VAR $audio_out_left_cbuffer_struc[$cbuffer.STRUC_SIZE] =
LENGTH($audio_out_left),
// Size
&$audio_out_left,
// Read pointer
&$audio_out_left;
// Write pointer
.VAR $audio_out_right_cbuffer_struc[$cbuffer.STRUC_SIZE] =
LENGTH($audio_out_right),
// Size
&$audio_out_right,
// Read pointer
&$audio_out_right;
// Write pointer
// ** Allocate memory for timer structures **
.VAR $audio_in_timer_struc[$timer.STRUC_SIZE];
.VAR $audio_out_timer_struc[$timer.STRUC_SIZE];
// Input:
// -----// ** Allocate memory for cbops stereo
.VAR $audio_in_copy_struc[] =
&$audio_in_left_shift_op,
//
2,
//
$AUDIO_LEFT_IN_PORT,
//
$AUDIO_RIGHT_IN_PORT,
//
2,
//
&$audio_in_left_cbuffer_struc,
//
&$audio_in_right_cbuffer_struc; //
input copy routines **
First operator block
Number of inputs
Input
Input
Number of outputs
Output
Output
.BLOCK $audio_in_left_shift_op;
.VAR $audio_in_left_shift_op.next = &$audio_in_left_dc_remove_op;
.VAR $audio_in_left_shift_op.func = &$cbops.shift;
.VAR $audio_in_left_shift_op.param[$cbops.shift.STRUC_SIZE] =
0,
// Input index
2,
// Output index
8;
// Shift amount
.ENDBLOCK;
.BLOCK $audio_in_left_dc_remove_op;
.VAR $audio_in_left_dc_remove_op.next = &$audio_in_right_shift_op;
.VAR $audio_in_left_dc_remove_op.func = &$cbops.dc_remove;
.VAR $audio_in_left_dc_remove_op.param[$cbops.dc_remove.STRUC_SIZE] =
2,
// Input index
2,
// Output index
0;
// DC estimate
.ENDBLOCK;
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 36 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
// ** Allocate memory for cbuffer structures **
.VAR $audio_in_left_cbuffer_struc[$cbuffer.STRUC_SIZE] =
LENGTH($audio_in_left),
// Size
&$audio_in_left,
// Read pointer
&$audio_in_left;
// Write pointer
.BLOCK $audio_in_right_dc_remove_op;
.VAR $audio_in_right_dc_remove_op.next = $cbops.NO_MORE_OPERATORS;
.VAR $audio_in_right_dc_remove_op.func = &$cbops.dc_remove;
.VAR $audio_in_right_dc_remove_op.param[$cbops.dc_remove.STRUC_SIZE] =
3,
// Input index
3,
// Output index
0;
// DC estimate
.ENDBLOCK;
// Output:
// -----// ** Allocate memory for cbops stereo output copy routines **
.VAR $audio_out_copy_struc[] =
&$audio_out_left_dc_remove_op,
2,
&$audio_out_left_cbuffer_struc,
&$audio_out_right_cbuffer_struc,
2,
$AUDIO_LEFT_OUT_PORT,
$AUDIO_RIGHT_OUT_PORT;
//
//
//
//
//
//
//
First operator block
Number of inputs
Input
Input
Number of outputs
Output
Output
.BLOCK $audio_out_left_dc_remove_op;
.VAR $audio_out_left_dc_remove_op.next = &$audio_out_left_shift_op;
.VAR $audio_out_left_dc_remove_op.func = &$cbops.dc_remove;
.VAR $audio_out_left_dc_remove_op.param[$cbops.dc_remove.STRUC_SIZE] =
0,
// Input index
0,
// Output index
0;
// DC estimate
.ENDBLOCK;
.BLOCK $audio_out_left_shift_op;
.VAR $audio_out_left_shift_op.next = &$audio_out_right_dc_remove_op;
.VAR $audio_out_left_shift_op.func = &$cbops.shift;
.VAR $audio_out_left_shift_op.param[$cbops.shift.STRUC_SIZE] =
0,
// Input index.
2,
// Output index
-8;
// Shift amount
.ENDBLOCK;
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 37 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
.BLOCK $audio_in_right_shift_op;
.VAR $audio_in_right_shift_op.next = &$audio_in_right_dc_remove_op;
.VAR $audio_in_right_shift_op.func = &$cbops.shift;
.VAR $audio_in_right_shift_op.param[$cbops.shift.STRUC_SIZE] =
1,
// Input index
3,
// Output index
8;
// Shift amount
.ENDBLOCK;
.ENDBLOCK;
.BLOCK $audio_out_right_shift_op;
.VAR $audio_out_right_shift_op.next = $cbops.NO_MORE_OPERATORS;
.VAR $audio_out_right_shift_op.func = &$cbops.shift;
.VAR $audio_out_right_shift_op.param[$cbops.shift.STRUC_SIZE] =
1,
// Input index
3,
// Output index
-8;
// Shift amount
.ENDBLOCK;
// Input to Output:
// ---------------// ** Allocate memory for cbops stereo loopback copy routines **
.VAR $audio_loopback_copy_struc[] =
&$audio_loopback_left_copy_op,
2,
&$audio_in_left_cbuffer_struc,
&$audio_in_right_cbuffer_struc,
2,
&$audio_out_left_cbuffer_struc,
&$audio_out_right_cbuffer_struc;
//
//
//
//
//
//
//
First operator block
Number of inputs
Input
Input
Number of outputs
Output
Output
.BLOCK $audio_loopback_left_copy_op;
.VAR $audio_loopback_left_copy_op.next = &$audio_loopback_right_copy_op;
.VAR $audio_loopback_left_copy_op.func = &$cbops.copy_op;
.VAR $audio_loopback_left_copy_op.param[$cbops.copy_op.STRUC_SIZE] =
0,
// Input index
2;
// Output index
.ENDBLOCK;
.BLOCK $audio_loopback_right_copy_op;
.VAR $audio_loopback_right_copy_op.next = $cbops.NO_MORE_OPERATORS;
.VAR $audio_loopback_right_copy_op.func = &$cbops.copy_op;
.VAR $audio_loopback_right_copy_op.param[$cbops.copy_op.STRUC_SIZE] =
1,
// Input index
3;
// Output index
.ENDBLOCK:
// Initialise the stack library
call $stack.initialise;
// Initialise the interrupt library
call $interrupt.initialise;
// Initialise the message library
call $message.initialise;
// Initialise the cbuffer library
call $cbuffer.initialise;
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 38 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
.BLOCK $audio_out_right_dc_remove_op;
.VAR $audio_out_right_dc_remove_op.next = &$audio_out_right_shift_op;
.VAR $audio_out_right_dc_remove_op.func = &$cbops.dc_remove;
.VAR $audio_out_right_dc_remove_op.param[$cbops.dc_remove.STRUC_SIZE] =
1,
// Input index
1,
// Output index
0;
// DC estimate
// Tell VM we're ready and wait for the go message
call $message.send_ready_wait_for_go;
// Start timer that copies input samples
r1 = &$audio_in_timer_struc;
r2 = $TMR_PERIOD_AUDIO_COPY;
r3 = &$audio_in_copy_handler;
call $timer.schedule_event_in;
// Wait for DAC buffers to have just wrapped around
wait_for_dac_buffer_wraparound:
r0 = $AUDIO_LEFT_OUT_PORT;
call $cbuffer.calc_amount_space;
// If the amount of space in the buffer is less than 32 bytes then a
// buffer wrap around must have just occurred.
Null = r0 - 32;
if POS jump wait_for_dac_buffer_wraparound;
// Start timer that copies output samples
r1 = &$audio_out_timer_struc;
r2 = $TMR_PERIOD_AUDIO_COPY;
r3 = &$audio_out_copy_handler;
call $timer.schedule_event_in;
// Start a loop to copy the data from the input through to the output
// buffers
copy_loop:
call $loopback_copy;
Null = r0 - $DATA_NOT_COPIED;
if Z call $timer.1ms_delay;
jump copy_loop;
.ENDMODULE;
// *****************************************************************************
// MODULE:
//
$audio_in_copy_handler
//
// DESCRIPTION:
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 39 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
// Left and right audio channels from the MMU have been synced to each
// other by the VM app but are free running in that the DSP doesn't tell
// them to start. We need to make sure that our copying between the
// cbuffers and the MMU buffers starts off in sync with respect to left
// and right channels. To do this we make sure that when we start the
// copying timers that there is no chance of a buffer wrap around
// occurring within the timer period. The easiest way to do this is to
// start the timers just after a buffer wrap around occurs.
// Wait for ADC buffers to have just wrapped around
wait_for_adc_buffer_wraparound:
r0 = $AUDIO_LEFT_IN_PORT;
call $cbuffer.calc_amount_data:
// If the amount of data in the buffer is less than 32 bytes then a
// buffer wrap around must have just occurred.
Null = r0 - 32;
if POS jump wait_for_adc_buffer_wraparound;
//
Function called on an interrupt timer to copy samples from MMU
//
input ports to internal cbuffers.
//
// *****************************************************************************
$audio_in_copy_handler:
// Push rLink onto stack
$push_rLink_macro;
// Copy data whatever mode we are in to keep in sync
// transfer data from mmu port to internal cbuffer
r8 = &$audio_in_copy_struc;
call $cbops.copy;
// Post another timer event
r1 = &$audio_in_timer_struc;
r2 = $TMR_PERIOD_AUDIO_COPY;
r3 = &$audio_in_copy_handler;
call $timer.schedule_event_in;
// Pop rLink from stack
jump $pop_rLink_and_rts;
.ENDMODULE;
//
//
//
//
//
//
//
//
//
*****************************************************************************
MODULE:
$audio_out_copy_handler
DESCRIPTION:
Function called on an interrupt timer to copy samples from internal
cbuffers to output MMU ports.
*****************************************************************************
.MODULE $M.audio_out_copy_handler;
.CODESEGMENT PM;
.DATASEGMENT DM;
$audio_out_copy_handler:
// Push rLink onto stack
$push_rLink_macro;
// Transfer data from internal cbuffer to MMU port
r8 = &$audio_out_copy_struc;
call $cbops.copy;
// Post another timer event
r1 = &$audio_out_timer_struc;
r2 = $TMR_PERIOD_AUDIO_COPY;
r3 = &$audio_out_copy_handler;
call $timer.schedule_event_in;
// Pop rLink from stack
jump $pop_rLink_and_rts;
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 40 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
.MODULE $M.audio_in_copy_handler;
.CODESEGMENT PM;
.DATASEGMENT DM;
.ENDMODULE;
*****************************************************************************
MODULE:
$loopback_copy
DESCRIPTION:
Routine to copy data from both input channels into the corresponding
output buffer. Routine is on a long delay between calls so need to
ensure we copy enough data.
INPUTS:
none
OUTPUTS:
r0 = DATA_COPIED / DATA_NOT_COPIED
TRASHED REGISTERS:
r8
Called buffer routines called also trash:
r1, r2, r3, r4, I0, L0, I1, L1, r10, DO LOOP
// *****************************************************************************
.MODULE $M.loopback_copy;
.CODESEGMENT PM;
.DATASEGMENT DM;
$loopback_copy:
// push rLink onto stack
$push_rLink_macro;
// Check if there is enough data in the input buffer
r0 = &$audio_in_left_cbuffer_struc;
call $cbuffer.calc_amount_data;
Null = r0 - $TONES_BLOCK_SIZE;
if NEG jump dont_copy;
r0 = &$audio_in_right_cbuffer_struc;
call $cbuffer.calc_amount_data;
Null = r0 - $TONES_BLOCK_SIZE;
if NEG jump dont_copy;
// Check if there is enough data in the output buffer
r0 = &$audio_out_left_cbuffer_struc;
call $cbuffer.calc_amount_space;
Null = r0 - $TONES_BLOCK_SIZE;
if NEG jump dont_copy;
r0 = &$audio_out_right_cbuffer_struc;
call $cbuffer.calc_amount_space;
Null = r0 - $TONES_BLOCK_SIZE;
if NEG jump dont_copy;
// Block interrupts when copying sample data
call $interrupt.block;
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 41 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// Copy the data between the buffers
r8 = &$audio_loopback_copy_struc;
call $cbops.copy;
BlueCore-Multimedia My First Kalimba DSP Application Application Note
// Now unblock interrupts
call $interrupt.unblock;
// Indicate DATA_COPIED and return
r0 = $DATA_COPIED;
// pop rLink from stack
jump $pop_rLink_and_rts;
// Indicate DATA_NOT_COPIED and return
dont_copy:
r0 = $DATA_NOT_COPIED;
// pop rLink from stack
jump $pop_rLink_and_rts;
.ENDMODULE;
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 42 of 43
CS-101420-ANP7
www.csr.com
Document References
Reference
BlueCore xIDE User Guide
CS-101500-UG
BlueCore Classic vs Native VM vs Assisted Native VM Application Note
CS-122636-AN
Terms and Definitions
ADC
Analogue to Digital Converter
ADK
Audio Development Kit
BC
Blue Core
BlueCore®
Group term for CSR’s range of Bluetooth wireless technology chips
Bluetooth®
Set of technologies providing audio and data transfer over short-range radio connections
CODEC
COder DECoder
CSR
Cambridge Silicon Radio
DAC
Digital to Analogue Converter
DSP
Digital Signal Processor
e.g.
exempli gratia, for example
i.e.
Id est, that is
IC
Integrated Circuit
MMU
Memory Management Unit
VM
Virtual Machine
xIDE
CSR’s BlueCore Integrated Development Environment
© Cambridge Silicon Radio Limited 2006-2013
Confidential Information - This material is subject to CSR’s non-disclosure agreement
Page 43 of 43
CS-101420-ANP7
www.csr.com
BlueCore-Multimedia My First Kalimba DSP Application Application Note
Document
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement