Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Missing code written for CS42884 object - Audio Library

  1. #1
    Senior Member
    Join Date
    Aug 2016
    Location
    Australia
    Posts
    204

    Missing code written for CS42884 object - Audio Library

    Hi Paul,

    I was testing some CS42448 functions and found that some of the function overloads for .output() and .input() led to empty servicing code!

    Here is the missing code for control_cs42448.cpp:

    Code:
    bool AudioControlCS42448::volumeInteger(uint32_t n)
    {
    	uint8_t data[9];
    	data[0] = 0;
    	for (int i=1; i < 9; i++) {
    		data[i] = n;
    	}
    	return write(CS42448_DAC_Channel_Mute, data, 9);
    }
    
    Cross post from https://forum.pjrc.com/threads/67298...ctions-written
    bool AudioControlCS42448::volumeInteger(int channel, uint32_t n)
    {
    	write(CS42448_DAC_Channel_Mute, 0); 			     // unmute all channels
    	return write(CS42448_AOUT1_Volume_Control + channel -1, n); // set this channel
    }
    
    bool AudioControlCS42448::inputLevelInteger(int32_t n)
    {
    	uint8_t data[6];
    	for (int i = 0; i < 6; i++) 
                  data[i] = n;
    	return	write(CS42448_AIN1_Volume_Control, data, 6); // set all channels (not 7 & 8)
    }
    
    bool AudioControlCS42448::inputLevelInteger(int channel, int32_t n)
    {
    	return write(CS42448_AIN1_Volume_Control + channel -1, n); // set this channel
    }
    Also, in control_cs42448.h, I believe the correct return value for the return value for a gain of -127.5dB is 255, rather than 128. (CS4428 data sheet P 50.)

    Code:
    	// convert level to volume byte, section 6.9.1, page 50
    	uint32_t volumebyte(float level) {
    		if (level >= 1.0) return 0;
    		if (level <= 0.0000003981) return 255;
    		return roundf(log10f(level) * -20.0);
    	}
    This is a cross post from 67298-Missing-CS42448-control-functions-written

    Richard

  2. #2
    Member
    Join Date
    Sep 2019
    Location
    Sevilla, Spain
    Posts
    63
    Hi @palmerr,
    in the post you have a difference in the code:
    Code:
    return roundf(log10f(level) * -40.0);
    Quote Originally Posted by palmerr View Post

    Code:
    	// convert level to volume byte, section 6.9.1, page 50
    	uint32_t volumebyte(float level) {
    		if (level >= 1.0) return 0;
    		if (level <= 0.0000003981) return 255;
    		return roundf(log10f(level) * -20.0);
    	}

    Richard
    is it the last the right one?

  3. #3
    Senior Member
    Join Date
    Aug 2016
    Location
    Australia
    Posts
    204
    Thanks for catching it. The other post is correct.

    The steps are 0.5dB therefore the multiplier should be -40.

    Code:
    	
    // convert level to volume byte, section 6.9.1, page 50
    uint32_t volumebyte(float level) {
      if (level >= 1.0) return 0;
      if (level <= 0.0000003981) return 255;
      return roundf(log10f(level) * -40.0);
    }
    I hope you have fun with the code. I've found it very useful to be able to use positive gains on the input PGAs. They do get a bit noisy towards maximum gain, so not recommended for microphone preamps, but quite usable to boost domestic-level (100mV) audio signals. With gain < 1 they have little real use, as they have the same input level restrictions as the ADCs.

    I've found the output level less useful, as it doesn't do anything that a mixer Audio object can't do.

    My guess is that these practical restrictions are why Paul didn't complete the code in the first place.

  4. #4
    Junior Member
    Join Date
    Nov 2019
    Location
    Piedmont, OK
    Posts
    12
    Those are very helpful - thanks for posting!

    I use the following to read the status register from the CS42448. Maybe you'll find them useful

    Code:
    bool AudioControlCS42448::read(uint32_t address)
    {
    	// reads registers values
    	uint8_t c = 0;
    	// pg38, control port read operation
    	//Send a start condition
    	Wire.beginTransmission(i2c_addr);
    	// send chip address and write operation
    
    	Wire.write(address);
    	Wire.endTransmission(true);
    	Wire.beginTransmission(i2c_addr);
    	//rx ack bit, send MAP byte
    	Wire.requestFrom( (int) i2c_addr, 1);
    	
    	while(Wire.available()) {
    		Serial.print("Register ");
    		Serial.print(address, HEX);
    		Serial.print(" = ");
    		c = Wire.read();
    		Serial.println(c, BIN);
    	}
    	Wire.endTransmission(true);
    	return true;
    }
    
    uint8_t AudioControlCS42448::get(uint32_t address) 
    {
    	// reads registers values
    	uint8_t c = 0;
    	// pg38, control port read operation
    	//Send a start condition
    	Wire.beginTransmission(i2c_addr);
    	// send chip address and write operation
    
    	Wire.write(address);
    	Wire.endTransmission(true);
    	Wire.beginTransmission(i2c_addr);
    	//rx ack bit, send MAP byte
    	Wire.requestFrom( (int) i2c_addr, 1);
    	
    	while(Wire.available()) {
    		c = Wire.read();
    		//Serial.println(c, BIN);
    	}
    	Wire.endTransmission(true);
    	return c;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •