Sample Data Export/Import is “bit-perfect”/lossless?[SOLVED]

Help for Audacity 2.x.x on GNU/Linux.

ImageThis forum is for Audacity 2.x.x on GNU/Linux and Unix-like operating systems.
Please state which version of Linux you are using, the exact three-section version number of Audacity from Help > About Audacity... and whether you installed your distribution's release or daily version of Audacity or compiled Audacity from source code.

Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.

Sample Data Export/Import is “bit-perfect”/lossless?[SOLVED]

Permanent link to this post Posted by Kdmeizk » Thu Oct 19, 2017 4:09 pm

Hello,


I would just like to check if Sample Data Export/Import is “bit-perfect”/lossless?

I took into account this webpage:
http://manual.audacityteam.org/man/samp ... mport.html

Example:
– I export a sound in 32 bits 48000 Hz as RAW file;
– I export the same sound with Sample Data Export;
– I import with Sample Data Import the text file generated previously;
– I export the result in a new RAW file 32 bits 48000 Hz.

→ the first RAW file = the second RAW file? (I checked their SHA-512 and there are identical, but I would like your confirmation)





EDIT – [Answer] Yes, Sample Data Export/Import can be “bit-perfect”/lossless:


  • Check the prerequisites (read the whole page if necessary):
    http://manual.audacityteam.org/man/samp ... table_data
  • File to change (a simple text editor is sufficient):
    sample-data-export.ny

    → if desired, backup the file (= copy it for example) before manipulate it
  • In the file, you have to replace:
    Code: Select all
    (setq *float-format* "%1.5f")               ; 5 decimal places

    to →
    Code: Select all
    ;; (setq *float-format* "%1.5f")               ; 5 decimal places
    (setq *float-format* "%.100g")               ; 100 digits maximum. Non-significant zeroes are not kept


  • [Optionally] If you want to export more than 1 million samples (→ example of file size with 3 minutes / 44100 Hz / 2 channels ≈ 350 MB):
      In the same file, you have to replace:
    • Code: Select all
      ;maxlen 1000001

      to →
      Code: Select all
      ;; maxlen 1000001

    • Code: Select all
        (if (> number 1000000)
            (add-error "Cannot export more than 1 million samples."))

      to →
      Code: Select all
      ;;  (if (> number 1000000)
      ;;      (add-error "Cannot export more than 1 million samples."))

  • If you go into strange things, you should read the entire thread before any other research.
Last edited by steve on Mon Oct 30, 2017 6:36 pm, edited 5 times in total.
Reason: corrected meaning of (setq *float-format* "%.100g")
Kdmeizk
 
Posts: 30
Joined: Mon Mar 20, 2017 5:28 pm
Operating System: Windows 7

Re: Sample Data Export/Import is “bit-perfect”/lossless?

Permanent link to this post Posted by steve » Thu Oct 19, 2017 7:15 pm

Kdmeizk wrote:I would just like to check if Sample Data Export/Import is “bit-perfect”/lossless?

No,not bit perfect for 32-bit samples. Sample Data Export writes the sample values with 5 decimal places, whereas 32-bit float precision is around 15 decimal places. In other words, Sample Data Export rounds the sample values to 5 decimal places. 5 decimal places are almost enough for 16-bit precision.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45305
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Sample Data Export/Import is “bit-perfect”/lossless?

Permanent link to this post Posted by Kdmeizk » Thu Oct 19, 2017 7:47 pm

Oh… you are right…

– Is it possible to increase this value to be “bit-perfect”/lossless? If yes, you said “whereas 32-bit float precision is around 15 decimal places”. Do you have a more accurate value?
– Is it possible to increase the limit of 1 million samples?

I think I have found these two parameters in “sample-data-export.ny”, but maybe I will break something.
Kdmeizk
 
Posts: 30
Joined: Mon Mar 20, 2017 5:28 pm
Operating System: Windows 7

Re: Sample Data Export/Import is “bit-perfect”/lossless?

Permanent link to this post Posted by steve » Thu Oct 19, 2017 8:18 pm

Kdmeizk wrote:I think I have found these two parameters in “sample-data-export.ny”, but maybe I will break something.

The "ny" file is just a plain text file. Make a backup copy of it before you start modifying it, then there's no need to worry about breaking it.

Fortunately on Linux there is no shortage of good text editors, but for any Windows users reading this, I'd recommend Notepad++
(On Linux I use Scite, which has built-in syntax highlighting for LISP)

Kdmeizk wrote:– Is it possible to increase the limit of 1 million samples?

Yes, but be careful. Many applications will choke on huge text files.
Code: Select all
(defun checknumber ()
  (setq number (min number len))
  (if (< number 1)
      (add-error "No samples selected."))
  (if (> number 1000000)
      (add-error "Cannot export more than 1 million samples."))
  (setq number (truncate number)))



Kdmeizk wrote:– Is it possible to increase this value to be “bit-perfect”/lossless?

It could certainly be made bit-perfect for 16-bit or even 24-bit, but I'm not sure about 32-bit float, but I think it will probably be bit perfect with around 16 decimal places.
Kdmeizk wrote:you said “whereas 32-bit float precision is around 15 decimal places”. Do you have a more accurate value?

No, because we're talking about converting between binary floating point numbers and decimal floating point. For example, decimal 0.1 in binary is 0.00011001100110011...
Code: Select all
(setq *float-format* "%1.5f")               ; 5 decimal places

Try something like:
Code: Select all
(setq *float-format* "%.16f")               ; 16 decimal places
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45305
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Sample Data Export/Import is “bit-perfect”/lossless?

Permanent link to this post Posted by steve » Thu Oct 19, 2017 8:26 pm

Note that the more decimal digits, the bigger the file size. Each digit is 1 byte, so 16 decimal places, plus a leading "0." or "-0." and a new line character, is 19 or 20 bytes per sample, so 1million samples will create a file that is close to 20 MB.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45305
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Sample Data Export/Import is “bit-perfect”/lossless?

Permanent link to this post Posted by Kdmeizk » Thu Oct 19, 2017 9:06 pm

It is ok for the text editors, thank you for your suggestions!

So in the exported text file, I have values like this:
Code: Select all
0.62876382284369708500000000000000000000000000000000

When there is at least 2x 0 values at the end (here there are many more), it means I am “bit-perfect”/lossless, is not it? You gave me 16 as decimal places, I put 50 (yes, do not worry about the size of the text file, I have a lot of space), all seems fine!
Kdmeizk
 
Posts: 30
Joined: Mon Mar 20, 2017 5:28 pm
Operating System: Windows 7

Re: Sample Data Export/Import is “bit-perfect”/lossless?

Permanent link to this post Posted by steve » Thu Oct 19, 2017 9:25 pm

Here is a very small 32-bit float number as a decimal to 50 decimal places:
0.00000002683188249363865907071158289909362792968750

You might want to read a bit about IEEE 754 standard to get an appreciation of why this is complicated:
https://en.wikipedia.org/wiki/Single-pr ... int_format
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45305
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Sample Data Export/Import is “bit-perfect”/lossless?

Permanent link to this post Posted by Kdmeizk » Fri Oct 20, 2017 12:07 am

I am sure I did not quite understand your link. With your example and your link, it seems the “decimal places” are infinite, so I wonder if I can get “bit-perfect”/lossless with Sample Data Export.

But in my case, I always have the same number of 0 at the end.
Kdmeizk
 
Posts: 30
Joined: Mon Mar 20, 2017 5:28 pm
Operating System: Windows 7

Re: Sample Data Export/Import is “bit-perfect”/lossless?

Permanent link to this post Posted by steve » Fri Oct 20, 2017 12:34 am

Why do you need "bit perfect"?
Where do the original "bits" come from?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45305
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Sample Data Export/Import is “bit-perfect”/lossless?

Permanent link to this post Posted by Kdmeizk » Fri Oct 20, 2017 1:27 am

Why should I edit without “bit-perfect” in mind?
I do tests with the loopback recording. It depends for the files: 16 and 24 bits. But I do tests with the Tone plugin of Audacity too, and I assume it is in 32 bits (and I save it as 32 bits file). I play them with VLC and I disabled its resampling.
Kdmeizk
 
Posts: 30
Joined: Mon Mar 20, 2017 5:28 pm
Operating System: Windows 7

Next

Return to GNU/Linux and Unix-like



Who is online

Users browsing this forum: No registered users and 3 guests