1. Application Scenario 1.1 non-TWS session
A single speaker can connect up to two A2DP sources.
- When speaker a connects to two A2DP sources, another speaker B cannot create a TWS session
- At the same time a speaker can only select one of 2 A2DP sources to play
1.2 TWS Session 1.2.1 Prep work
A single speaker can connect up to 1 A2DP sources and 1 TWS sessions connect up to 2 A2DP feeds.
Before entering the TWS session, two A2DP sources must be paired with two speakers respectively, otherwise, once the TWS session is started, the A2DP source cannot search for two speakers and cannot be paired with one another.
1.2.2 Establishing a session
After pairing two speakers with two A2DP sources, start the TWS session:
-
Speaker A calls Eventusrpeersessioninquire, enters inquiry mode
-
Speaker B calls Eventusrpeersessionconndisc, enters Conndisc mode
-
Speaker a searches for Speaker B and establishes the TWS connection according to the following settings:
-
Automatically back up when links are lost. Recommended slave enable this option to prevent Master from having audio jitter
-
Use restricted call access codes
-
Connect device filter mode. If the UUID of Speaker B can pass the filter rule set by Speaker A, then speaker A and speaker B start to establish TWS connection. The filter rules here have the device ID and CSR peer service UUID, which is a customer-defined non-0 value.
-
Pairing mode
-
Whether it is supported as an audio repeater and audio is relayed by
-
Audio relay mode: Dual stereo, main left from right, main right from left, shrink blend
-
Volume reduction. The volume of TWS is controlled by the system volume and volume reduction. The system volume is set by the AVRCP instruction, and the default value for volume reduction is stored in the PSR configuration. Master will send the configuration to slave, and master will send it to slave when the mode is switched.
-
Single-device mode. After this mode is enabled, the AVRCP instruction of the A2DP source can be synchronized between the Master,slave and the A2DP source, otherwise slave commands that are received by the system cannot be relayed to master
1.2.3 Playing Audio
-
After the TWS session is successfully established, connect one of the two A2DP sources and play the audio file. Assuming A2DP source 1 is playing, the speaker paired with A2DP Source 1 is the master of the TWS session and the other speaker acts as the slave. The A2DP1 audio data is relayed from master to slave.
-
Assuming the A2DP source 2 is playing at this point, the speaker paired with Source 2 is the master of the TWS session and the other speaker automatically switches to slave
-
The A2DP source can be a different Bluetooth device, or it can be a local audio interface.
-
The Bluetooth device must support the A2DP,AVRCP protocol. The audio encoding of the supported Bluetooth devices is sbc,mp3,aac,aptx.
-
The local audio interface includes a USB interface and a analog interface (ADC/SPDIF/I2S). The local audio interface caches the audio data in internal RAM and is passed to slave via the connection established between master and slave after using the SBC encoding.
-
After receiving, the slave is decoded with the SBC to convert the decoded audio data to an audio signal via a DAC or to an external audio chip using the I2s interface.
1.2.4 Settings command
TWS mode supports the commands defined in AVRCP 1.4, including fast forward rewind, play pause, and so on.
The TWS mode also supports the following unique AVRCP commands:
The Gaia commands supported in TWS mode are as follows, and these instructions are synchronized between two devices in the TWS session (volume Control and device volume reduction control cannot be synchronized):
The volume control in TWS mode is divided into two parts:
-
System Volume: Can be set by AVRCP command, if need to sync to A2DP source, need to support AVRCP Absolute Volume control (absolute volume controls)
-
Volume reduction: Can be called by master through the following user events
1.2.5 Switching audio sources
The default audio source when TWS mode is established is determined by PSR. Options available are auto,a2dp,usb,analog.
When the Auto option is selected, the TWS connection is established by selecting the currently available audio source, with priority A2dp>usb>analog.
The runtime can invoke the following events to manually switch the audio source:
You can call Eventusrselectaudiosourcenone and switch back to auto-switch mode.
1.2.6 End TWS Session
Call Eventusrpeersessionend to end the TWS session.
Call Eventusrestablishpeerconnection to request a reconnect to the TWS session that has been paired.
2. Build VM Application 2.1 Modify VM Application Engineering properties
2.2 Enable peer device support
2.3 Enabling Debugging Information
- Modify Sink_debug.h
- Enable to Debug_print_enable
- Enable to Debug_peer
- Enable to Debug_peer_sm
- Add a library file
- Open the library file directory C:\ADK4.0.0\tools\lib\BlueLab-7.0.1-Release\assisted
- Find LIBCSR_A2DP_DECODER_COMMON_PLUGIN_STEREO_TWS_DEBUG.A
- Xide->project->properties->libraries, adding Csr_a2dp_decoder_common_plugin_stereo_tws_debug
3 Extending the I2s interface for application--analog mode
In the CSR's official demo, when the TWS mode audio source is analog, the hardware interface set up in the program is ADC. The I2S interface is required as an audio input in this project. The steps to modify are as follows:
-
The first step: Set the i2s of CSR8670 to master and the sampling rate to 48KHz.
-
Second step: When the pause key is pressed, the i2s clock disappears. The code to modify SINK_AUDIO_ROUTING.C is as follows:
-
Step three: Modify the CSR_A2DP_DECODER_COMMON_PLUGIN.C function Musicconnectaudio as follows:
-
Fourth step: Recompile the library file. Start Menu->ADK4.0.0->REBUILD->VM Libraries
-
Fifth Step: Modify SINK_WIRED.C
-
1: Modify the macro definition, use the program to control the ADC device Access detection results
-
2: New function Wiredaudiosetanalogconnect (uint8 status)
-
Sixth step: Only Inquriy devices will enable analog Connect, which allows the connection to be emulated when a request to send a inquiry event is received, and when a request to send a Conndisc event is received, the analog connection is closed.
-
Seventh step: If the A2DP source is switched, the rules for Master and slave will also be converted, so you need to modify the Sink_a2dp.c Sinka2dpsetlinkrole
4 Summary
The TWS mode is characterized by a synchronous timestamp between frames and frames, and the audio data delay between the two speakers is only ±5sample.
It is also necessary to continue to explore the reasons for the long periods of inability to enter the TWS session during the use process.
CSR8670 Application Note for TWS mode