Thank you for your donation!


HifiBerry DAC2 HD support
#1
Hi guys,

Since last thread is closed and no solution was provided - I decided to spent couple of hours integrating brand new DAC from HiFiBerry into Moode. Later maybe someone will add it to source code or later I will try contribute this changes to project itself.

It is working with current latest version - 7.01, but i think it will be also working with older versions as well. Source code lines numbers are related to current version 7.01 - but even you're working with older version you wont have any problem with finding them in code Wink

So, in order to make it work you need to:

1. Add new driver to moode

Just like TookAFace suggested here but remove chip options (I'm not quite sure if there is a difference with or without these options. Since this is PCM1796 - I haven't seen any additional configuration needed like it was with PCM5122 (older boards like DAC+ PRO))

Code:
sudo sqlite3 /var/local/www/db/moode-sqlite3.db " INSERT INTO cfg_audiodev (id, name, dacchip, chipoptions, iface, list, driver, drvoptions) VALUES (75, 'HiFiBerry DAC2 HD', 'Burr Brown PCM1796', '', 'I2S', 'yes', 'hifiberry-dacplushd', '');"


2. Now we need to edit playerlib.php file and add custom name for volume control and modify driver count

Open editor with code:
Code:
sudo nano /var/www/inc/playerlib.php


Volume control:
Code:
Line:2071
elseif ($i2sdevice == 'HiFiBerry DAC+ DSP') {
    $mixername = 'DSPVolume';
}
elseif ($i2sdevice == 'HiFiBerry DAC2 HD') {
       $mixername = 'DAC';
}

Drivers count (originally 78 - now 79):
Code:
Line:270
// Verify the row count
$count = sysCmd('sqlite3 ' . SQLDB_PATH . " \"SELECT COUNT() FROM cfg_audiodev\"");
if ($count[0] != 79) {
   $_SESSION['ic_return_code'] = '4';
   return false;
}

3. Generate new checksums

After making changes we need to generate new checksum for both playerlib file and driver list. In moode there is table called cfg_hash with calculated values. After changes both checksums are no longer valid - so moode will break.

Well, we might bypass this integrity check and save some time, but let's play with moode nicely;-)

Generate new checksum for playerlib:

Code:
php -r 'echo md5(file_get_contents("/var/www/inc/playerlib.php"));'

Store output - will be needed in a minute ;-) Should be md5 sum - something like: d717dc9bc46782b962467a57de3fcedb


Generate new checksum for device list:

Create a file with devices in same way like moode does and store it in temporary folder:

Code:
sudo sqlite3 /var/local/www/db/moode-sqlite3.db "SELECT * FROM cfg_audiodev WHERE drvoptions NOT IN ('slave', 'glb_mclk') AND chipoptions = ''" > /tmp/moode-devices.txt
Now we can easily calculate checksum from file:
Code:
php -r 'echo md5(file_get_contents("/tmp/moode-devices.txt"));'

Store output

4. Modify checksums ind DB

There is a trigger in db which blocks any operation on cfg_hash table so we gonna remove it, modify table and recreate trigger (if you skip last part (recreation of trigger) then integrity check will fail in schema check).

4.1 Remove trigger:
Code:
sudo sqlite3 /var/local/www/db/moode-sqlite3.db "DROP TRIGGER ro_columns"

4.2 Modify checksums in db

Change PASTE_GENERATED_OUTPUT_HERE to your generated checksum for playerlib.php:
Code:
sudo sqlite3 /var/local/www/db/moode-sqlite3.db "UPDATE cfg_hash SET value='PASTE_GENERATED_OUTPUT_HERE' WHERE id=10"


Change PASTE_GENERATED_OUTPUT_HERE to your generated checksum for devices list:
Code:
sudo sqlite3 /var/local/www/db/moode-sqlite3.db "UPDATE cfg_hash SET value='PASTE_GENERATED_OUTPUT_HERE' WHERE id=8"

4.3 Recreate a trigger

Code:
sudo sqlite3 /var/local/www/db/moode-sqlite3.db "CREATE TRIGGER ro_columns BEFORE UPDATE OF param, value, [action] ON cfg_hash FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'read only'); END"


5. Reboot raspberry

Code:
sudo reboot


Now - just select new driver in Audio Options and enjoy music;-)
Reply
#2
That's great! It would be nice to have this integrated in 7.1.0 or even earlier Smile
Reply
#3
'I’m running the latest version of Moode.  When I copy and paste the first code paragraph, I get the following error:Error: UNIQUE constraint failed: cfg_audiodev.idSuggestions? thanks
Reply
#4
@Marrahm    please, don't re-post the whole how-to.
Just ask your question. :-)
"Mediocrity is achievable. This may explain it's popularity." 
Reply
#5
(01-21-2021, 12:47 AM)Marrahm Wrote: 'I’m running the latest version of Moode.  When I copy and paste the first code paragraph, I get the following error:Error: UNIQUE constraint failed: cfg_audiodev.idSuggestions? thanks

That's because id which is specified here (75) is already present in db. So I might made a typo here or you already have such entry in db. Check what you have under 75. To do that use select statement like:

Code:
sudo sqlite3 /var/local/www/db/moode-sqlite3.db "SELECT * FROM cfg_audiodev"
Reply
#6
Mystic,

Thanks - I’ll give that a shot.   In playing around, there might be an easier way.  I followed these instructions:  

https://www.hifiberry.com/docs/software/...ux-3-18-x/

If you’re using the latest Moode with a 5.4+ kernel, make sure to add the force eeprom read option off.  

I still do not see the HD in the I2S setup options in Moode, but it doesnt’ seem to matter.  Spotify works, airplay works, internet radio, etc.  Settign up NAS now to make sure that works as well.  

Mike
Reply
#7
Solution:


1: SSH into your moode box and sudo nano /boot/config.txt

2: comment out (add # to first character of line containing):
          dtparam=audio=on

3: Add following lines to the file:
         dtoverlay=hifiberry-dacplushd
         force_eeprom_read=0
4: Write out the file and reboot. 

5: In MPD settings, make sure you can see the “dacplushd” DAC identifier.  

That’s it.  You can reboot and do “aplay -l” to make sure it shows up correctly.  

For whatever reason, leaving the I2S setting to none in Moode still works fine for me.  The HD dac is playing everythign correctly from all sources.  Sounds great.  

Source:
https://www.hifiberry.com/docs/software/...ux-3-18-x/

Mike
Reply
#8
Hi,

first time posting here.

Will this be incorporated into 7.1.0 or even earlier?

Greg
Reply


Forum Jump: