modify your function like this
void sendVolume(bool forceSend = false) { // Convert dB volume level to hex array and send by I2C to the audio processor.
// Convery dB level to hex array.
linGain = pow(10, volume / 20); // Convert dB level to linear gain value.
vol32 = linGain * 16777216; // Convert linear gain value stored as a float variable to a 32 bit integer.
volArray[0] = (vol32 >> 24) & 0xFF; // Populate first byte of array with most significant 8 bits of the 32 bit volume word, by shifting word right by 24 bits. Adding 0xFF denotes it as a hex value.
volArray[1] = (vol32 >> 16) & 0xFF; // Populate second byte of array with next most significant 8 bits of the 32 bit volume word, by shifting word right by 16 bits. Adding 0xFF denotes it as a hex value.
volArray[2] = (vol32 >> 8) & 0xFF; // Populate third byte of array with next most significant 8 bits of the 32 bit volume word, by shifting word right by 8 bits. Adding 0xFF denotes it as a hex value.
volArray[3] = vol32 & 0xFF; // Populate fourth byte of array with least significant 8 bits of the 32 bit volume word, naturally the first 8 bits of the word. Adding 0xFF denotes it as a hex value.
// Send hex array by I2C safeload proceedure to audio processor.
if (forceSend || (millis () - lastSafeWrite >= 1)) { // Safeload should only occur once per audio frame (1ms is pleanty).
Serial.println("Sending Volume Now");
Wire.beginTransmission(dspAdd); // Begin I2C transmission to 7-bit address of audio processor.
Wire.write(safeDataAddr0, 2); // Prepare to write safe load data bank 1.
Wire.write(volArray, 4); // Write hex array holding linear volume level.
Wire.endTransmission(); // Send data queue and end transmission with stop bit.
Wire.beginTransmission(dspAdd); // Begin I2C transmission to 7-bit address (0x3B) adds R/W bit automatically.
Wire.write(safeTargetAddr, 2); // Prepare to write target address.
Wire.write(volAddress, 4); // Write aadress of volume control module.
Wire.endTransmission(); // Send data queue and end transmission with stop bit.
Wire.beginTransmission(dspAdd); // Begin I2C transmission to 7-bit address (0x3B) adds R/W bit automatically.
Wire.write(safeTrigAddr, 2); // Prepare to writing number of data banks used (1-5) and trigger safe load.
Wire.write(safeTrig1, 4); // Trigger safe load writing 1 data bank.
Wire.endTransmission(); // Send data queue and end transmission with stop bit.
lastSafeWrite = millis (); // Store time when the latest write occured.
}
}
and at the end of the setup() do
sendVolume(true); // Send volume to audio processor.
or quick hack, just give a value in the past to lastSafeWrite
unsigned long lastSafeWrite = -10;
so that the test will be true the first time you call