octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #56889] Incorrect encoding results from uint8


From: Rik
Subject: [Octave-bug-tracker] [bug #56889] Incorrect encoding results from uint8 vector to wav file
Date: Sun, 15 Sep 2019 11:12:31 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Follow-up Comment #10, bug #56889 (project octave):

In audiowrite, the translation from [0, 255] to the range [-1.0, +1.0] for
passing to libsndfile *is* compressing the range.

First this code,


  if (args(1).is_uint8_type ())
    bias = scale = std::pow (2.0, 7);


which sets bias and scale at 128.  And then


for (int i = 0; i < audio.rows (); i++)
  {
    for (int j = 0; j < audio.columns (); j++)
      {
        double elem = (audio.xelem (i, j) - bias) / scale;
        data[idx++] = std::min (std::max (elem, -1.0), 1.0);
      }
  }


The value 255 is translated to (255 - 128) / 128 = 127/128 which is not 1.0.



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?56889>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]