Skip to main content
. 2021 Jul 5;21(13):4602. doi: 10.3390/s21134602
Algorithm 5 Variable bit-length ADPCM encoder.
Require:P // N bit Pixel element.
Require: M // bits of the current ADPCM value.
Require: InitW // if the predicted offset is initialized or not.
Require: Winit // a predicted offset to be initialized.
Require: InitP // if the Pprev is initialized or not.
Require: Pinit // an original data to be set to Pprev.
Ensure: p // ADPCM value.
 if M=N then
   p←P
  return
 end if
 if M≠Mprev then
  if M>Mprev then
    w←w≪(M−Mprev)
  else
    w←w≫(Mprev−M)
  end if
 end if
 if InitW=true then
   w←Winit
 end if
 if InitP=true then
   Pprev←Pinit
 end if
  d←P−Pprev
  step←(w×2)/2M−1
 if d>0 then
  if |d|/step>2M−1−1 then
    p←2M−1−1
  else
    p←ceil(d/step)
  end if
 else
  if |d|/step>2M−1 then
    p←2M−1
  else
    p←ceil(−d/step)+2M−1
  end if
 end if
  fprev←fprev×C[p&((1≪M)−1)]/64
  w←fprev