Skip to content

Commit

Permalink
Merge pull request #51 from xhuw/feature/readme-note-on-clocks
Browse files Browse the repository at this point in the history
Update with some fixes for 3B mclk phase issue
  • Loading branch information
xhuw authored Nov 28, 2022
2 parents d972c09 + 1b23cc6 commit ea5b95a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# VocalFusion Raspberry Pi Setup Change Log

## 5.4.0

* Fix and document MCLK phase issue found on raspberry pi 3b

## 5.3.0

* Fix setup_dac.py script for XVF3615
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,20 @@ For XVF3510-UA and XVF361x-UA devices these actions will be done as well:
Wait for the script to complete the installation. This can take several minutes.

5. Reboot the Raspberry Pi.

## Important note on clocks

The I2S/PCM driver that is provided with rasbian does not support an MCLK output. However the
driver does have full ability to set the BCLK and LRCLK correctly for a given sample rate. As
the driver does not know about the MCLK it is likely to choose dividers for the clocks generators
which are not phase locked to the MCLK. The script in this repo gets around this problem by
configuring the i2s driver to a certain frequency and then overriding the clock registers to force
a phase locked frequency.

This will work until a different sample rate is chosen by an application, then the I2S driver will
write it's own value to the clocks and the MCLK will no longer be phase locked. To solve this problem
the following steps must be taken before connecting an XVF device with a different sample rate:

1. Take a short recording at the new sample rate: `arecord -c2 -fS32_LE -r{sample_rate} -s1 -Dhw:sndrpisimplecar`
2. For 48kHz `./resources/clk_dac_setup/setup_blk`, for 16kHz `./resources/clk_dac_setup/setup_blk`

9 changes: 9 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ if [[ -n "$I2S_MODE" ]]; then
echo "# Run Alsa at startup so that alsamixer configures" >> $i2s_driver_script
echo "arecord -d 1 > /dev/null 2>&1" >> $i2s_driver_script
echo "aplay dummy > /dev/null 2>&1" >> $i2s_driver_script

if [[ "$I2S_MODE" = "master" ]]; then
echo "# Preconfigure i2s clocks to 48kHz" >> $i2s_driver_script
# wait a bit as it doesn't work otherwise, this is probably caused
# by the same process that is deleting .asoundrc
echo "sleep 15" >> $i2s_driver_script
echo "arecord -Dhw:sndrpisimplecar,0 -c2 -fS32_LE -r48000 -s1 /dev/null" >> $i2s_driver_script
echo "sudo $RPI_SETUP_DIR/resources/clk_dac_setup/setup_bclk" >> $i2s_driver_script
fi
fi

if [[ -n "$DAC_SETUP" ]]; then
Expand Down

0 comments on commit ea5b95a

Please sign in to comment.