OSQ

From MultimediaWiki
Jump to navigation Jump to search
  • Company: Steinberg
  • Extension: osq

OSQ (short for Original Sound Quality) is a lossless audio format created reportedly by Philippe Goutier for storing audio output of WaveLab software. The format is based on Shorten.

Header

The file starts with 56-byte header (all values are little-endian):

 4 bytes - "OSQ "
 1 byte  - version? (should be 1)
 1 byte  - unknown (always zero?)
 1 byte  - bits per sample
 1 byte  - number of channels (mono or stereo)
 4 bytes - unknown
 4 bytes - sample rate?
 4 bytes - number of samples
 36 bytes - unknown

Block format

Blocks consist of samples with some redundancy removed by one of the fixed prediction schemes and residues coded with fixed-width bits or Rice codes. Block starts with block header(s) for each channel and then the data for each channel follows.

Block header format is the following:

 1 bit - should be zero
 1 bit - stereo decorrelation present
 1 bit - use 8-bit samples internally
 for each channel {
   rice(5) - prediction mode
   rice(3) - coefficient coding mode
   if coefficient coding mode < 3 {
     rice(4) - residue Rice parameter
   } else {
     rice(4) - number of bits per residue
   }
 }
 for each frame {
   for each channel {
     coefficient residue
   }
 }
 0-7 bits - byte boundary align

Coefficient residues are coded either as signed fixed-width bitfield or using Rice code plus sign bit (even for zeros). In case of coding mode 2 an adaptive Rice coding is used (in this case Rice parameter is calculated using the statistics of decoded residues).

Prediction modes are the following (for brevity predict2 = dst[-1] * 2 - dst[-2] and predict3 = dst[-1] * 3 - dst[-2] * 3 + dst[-3]):

  • 0 - no prediction
  • 1 - add previous sample
  • 2 - add previous sample and half of previous difference
  • 3 - predict2
  • 4 - predict2 + prev_diff / 2
  • 5 - predict3
  • 6 - predict3 + prev_diff / 2
  • 7 - (predict2 + predict3) / 2 + prev_diff / 2
  • 8 - (predict2 + predict3) / 2
  • 9 - (predict2 * 2 + predict3) / 3 + prev_diff / 2
  • 10 - (predict2 + predict3 * 2) / 3 + prev_diff / 2
  • 11 - (dst[-1] + dst[-2]) / 2
  • 12 - dst[-2]
  • 13 - (dst[-4] + dst[-2]) / 2
  • 14 - (dst[-1] + predict2) / 2 + prev_diff / 2

After the residue is read, prediction should be applied to it, then an optional clearing of low eight bits and finally, for the decoded pair of samples, stereo decorrelation in form L+R, L-R may be applied.