How to set PWM duty cycle to control volume on Pico

Standard PWMAduio with PICO work fine.

I am using PWMAudio pwm(D28, false) for mono on io28
I load my 16bit 16khz audio sample in an array
i setup to call function: pwm.onTransmit(cb);
point my buffer pointers to my array and pwm.begin(16000)

Any idea how i can control volume? Is there some simple way to set the duty cycle for the PWM?

void cb() {
  while (pwm.availableForWrite()) {
    pwm.write(*pbb++, true);
    count += 2;
    if (count >= mybuffersize) {
      count = 0;
      pbb = starta;
      pwm.end();
    }
  }
}

found a solution:

changed this line:

pwm.write(*pbb++, true);

to:

// volumed is the static variable for volume divider.
pwm.write(*pbb/volumed, true);
pbb++;