VS1053b Duplex + AEC
====================

The duplex package implements two-way communication and has
another versio with acoustic echo cancellation (AEC).
AEC helps remove the speaker sound from the microphone in
speaker-phone / hands-free applications. You still should
not forget that acoustic design is still the key to get
good performance. If there are acoustical problems, AEC
can not work correctly.

AICTRL0, 1, 2, and 3 are used like in the normal IMA ADPCM
encoding mode. Samplerates 8000Hz, 12000Hz, 16000Hz, and 24000Hz
are possible. XTALI must be 12.288MHz for the exact rates.

CLOCKF should be set to for example 0x6000 (for 3.0x clock).
If 12000Hz rate is used with AEC, higher clock (4.0x) is required.

The loopback from ADC to DAC is removed, and DAC plays the IMA
ADPCM (or linear) data you send to SDI. You can send just the IMA ADPCM
(or linear) data, no WAV header is required (if it is sent, the 'player'
part skips that by synchronizing to the IMA ADPCM blocks).


Make the normal setup, then set AICTRL0..3:
- AICTRL0 for samplerate, must be exactly one of the supported rates,
- AICTRL1 = 0 for AGC,
- AICTRL2 to set AGC maximum amplification,
- AICTRL3 = 2 for left channel mono,
- clear the SM_LINE bit from the MODE register to select MIC,
- then write 0x50 to AIADDR to start the code.

The code sets the ADPCM bit in the mode register automatically to allow
using HDAT0/1 for data transfer.

The data to play is sent to SDI in the same format as the encoded data.
You can also route the data read from SCI directly to SDI.

DREQ should work normally for SDI, but of course it is an error case
if DREQ goes low during the normal duplex operation, because that would
mean you have sent data too fast. If you send the IMA ADPCM from file,
like I did, DREQ works as usual.

The first byte you get from HDAT0 is the high part of the word, and you
should send that first. Notice that HDAT1 gives the number of WORDS
available.

1) release reset, wait for DREQ
2) send the code from either duplex-plg.h or duplex-ctab.h
3) initialize AICTRL0 = 8000, AICTRL1 = 0, AICTRL2 = 16384, AICTRL3 = 2
4) clear SM_LINE from MODE register
5) start the code by writing 0x50 to AIADDR

6) read data like in normal ADPCM mode



20111006: changed the aec library. AEC variables and constants are now
	  collected into aecState structure for easier access and
	  adjustment.
