Hydrogenaudio Forums

Lossless Audio Compression => FLAC => Topic started by: alexhd on 2018-05-02 19:20:14

Title: SACD to FLAC
Post by: alexhd on 2018-05-02 19:20:14
I would like to know how to convert SACD to FLAC, with the best quality. (How to config foobar options and which steps to follow)

I have two different SACD:

SACD1.iso
Sample rate : 2822400 Hz
Channels : 2
Bits per sample : 1
Bitrate : 5645 kbps
Codec : DSD64
Encoding : lossless

SACD2.iso (multi-channel)
Sample rate : 2822400 Hz
Channels : 6
Bits per sample : 1
Bitrate : 16934 kbps
Codec : DST64
Encoding : lossless


Thank you all.  ::)
Title: Re: SACD to FLAC
Post by: magicgoose on 2018-05-03 13:40:10
"best quality" goal is ill-defined. When resampling is involved, one can always trade even more CPU resources for even more precision, but it will become pointless at some point, and where does this point stand is subjective. 
If the goal is to keep it audibly indistinguishable from the source, then you don't even need to use FLAC, a lossy format would suffice as well.

Perhaps it's worth adding a specific goal, for example, S/N ratio of resampling of ≥140 dB in <20kHz range.

That said, for all practical purposes, converting DSD to FLAC in foobar2000 while resampling with SoX resampler to 44100Hz should produce completely fine results, as long as there's no clipping. All other settings can be left as defaults.
Make sure to check "don't reset DSP between tracks…" if converting from a tracks view, otherwise resampling could be not gapless.
Title: Re: SACD to FLAC
Post by: alexhd on 2018-05-03 14:53:48
Ok, I have no idea. I just want to covert them to flac format, with correct parameters to maintain their quality.


Steps:

1. Open SACD.iso into Foobar2000
2. Select all tracks.
3. Right clic and select 'Convert'.
4. 'Converter Setup':
'Output format': FLAC
                          'edit': 'Compression Level' = 5
                          'Output bit depth' = Auto
                           'Dither' = Never
'Processing': 'Replay Gain' = None
                    'DSP' = None
                    Select "don't reset DSP between tracks…"


Are these options correct?
Title: Re: SACD to FLAC
Post by: alexhd on 2018-05-03 15:21:46
I have obtained these files 'files.flac':

Sample rate : 44100 Hz
Channels : 6: FL FR FC LFE BL BR
Bits per sample : 24
Avg. bitrate : 3493 kbps
Codec : FLAC
Encoding : lossless
Title: Re: SACD to FLAC
Post by: Porcus on 2018-05-03 15:42:44
I would like to know how to convert SACD to FLAC, with the best quality.

For the first: if you are a bit more agnostic about formats, you could use WavPack, which actually supports DSD. But you can consider just converting to [something] and leaving the iso's for backup. (Because you need backup anyway, right ... ?)
Title: Re: SACD to FLAC
Post by: alexhd on 2018-05-03 16:23:44
I only use fresoftware formats like 'flac'.  ;)  https://www.fsf.org/resources/



Title: Re: SACD to FLAC
Post by: bennetng on 2018-05-03 16:48:30
From what I read in the "About" part of WavPack's website it should be a "free" and "open" format.
http://www.wavpack.com/

Maybe you can ask in the WavPack subforum to get a confirmation.
https://hydrogenaud.io/index.php/board,68.0.html
Title: Re: SACD to FLAC
Post by: alexhd on 2018-05-03 17:15:24
http://www.gnu.org/licenses/bsd.html
Title: Re: SACD to FLAC
Post by: alexhd on 2018-05-03 17:18:46
Can anyone confirm if these SACD to FLAC convertion options are good?  ::)
Title: Re: SACD to FLAC
Post by: bennetng on 2018-05-03 17:43:01
Then foobar's license may not meet your requirement as well.
Title: Re: SACD to FLAC
Post by: bryant on 2018-05-03 18:34:51
http://www.gnu.org/licenses/bsd.html
WavPack uses the "modified" BSD license with no advertising clause, so it qualifies as fully free.

It is not as universally supported as FLAC, but is supported by foobar and would work nicely is you wanted to retain the DSD audio.

If you don't mind converting to PCM then your conversions are fine (and save more space).
Title: Re: SACD to FLAC
Post by: alexhd on 2018-05-03 19:37:54
Thank you for the modified BSD info.

I don't understand audio things, like DSD and PCM. I want good sound quality in flac format. I have SACD and I want it into flac format with no loss of quality.


 :)
Title: Re: SACD to FLAC
Post by: Apesbrain on 2018-05-03 21:23:49
I have obtained these files 'files.flac':

Sample rate : 44100 Hz
Channels : 6: FL FR FC LFE BL BR
Bits per sample : 24
Avg. bitrate : 3493 kbps
Codec : FLAC
Encoding : lossless

That looks good for 5.1 surround. Have you tried playing them?
Title: Re: SACD to FLAC
Post by: lvqcl on 2018-05-03 21:39:18
I have SACD and I want it into flac format with no loss of quality.
Quality is subjective, so there's no unambiguous, "100% mathematically correct" answer.
Title: Re: SACD to FLAC
Post by: Porcus on 2018-05-04 01:18:18
By the way: according to the Wikipedia SACD entry (https://en.wikipedia.org/wiki/Super_Audio_CD#DST), the SACD DST format is an MPEG-4 stream; but it does not fit in the MP4 container? Or ... ?
Title: Re: SACD to FLAC
Post by: alexhd on 2018-05-04 02:19:59
I have obtained these files 'files.flac':

Sample rate : 44100 Hz
Channels : 6: FL FR FC LFE BL BR
Bits per sample : 24
Avg. bitrate : 3493 kbps
Codec : FLAC
Encoding : lossless

That looks good for 5.1 surround. Have you tried playing them?


Thank you. They can be played good. :)
Title: Re: SACD to FLAC
Post by: Pusherman on 2018-05-04 11:19:51
'Output format': FLAC
                          'edit': 'Compression Level' = 5

Test compression level at full ( 8 ), there should not be much difference in encoding speed.
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-16 16:14:12
...That said, for all practical purposes, converting DSD to FLAC in foobar2000 while resampling with SoX resampler to 44100Hz should produce completely fine results, as long as there's no clipping. All other settings can be left as defaults.
Make sure to check "don't reset DSP between tracks…" if converting from a tracks view, otherwise resampling could be not gapless.
I have a quick question about this. Using foobar2000 and the SACD input component which is the more accurate conversion (or better math) in your opinion:
SACD input settings PCM & 44.1 and then use the foobar2000 convert function using wav (auto) and no dither
or
SACD input settings PCM & 88.2 (or 176 for that matter) and then foobar2000 convert-->wav (auto), no dither and SoX resample to 44.1.

I ask because I've done option #1 with both no SoX and with SoX and they both yield 44.1 files so it seems like SoX is redundant in this case...or probably not even being used?

Basically is SoX better than the SACD input conversion...I've read that as long as the sample rate for DSD64 is a multiple of 44.1 then it should be good to go so I was planning on using option number one.

Thanks
Title: Re: SACD to FLAC
Post by: magicgoose on 2018-08-20 09:36:50
Maybe SoX resampler is not necessary if the SACD component does that with the similar precision. I can't confirm for sure if SoX is necessary here because I don't know about the resampling algorithms used in the SACD component.

And yes if your SACD component is set to already produce 44.1k data then of course no further resampling is needed because it's already 44.1. Resampling from 44.1 to 44.1 will _at best_ do nothing at all.

> as long as the sample rate for DSD64 is a multiple of 44.1 then it should be good

Actually good resamplers like SoX can resample to any rate without any sound quality problems.
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-20 13:59:06
Thanks for your response. So when using the SACD component, you have to select something...either 44.1, 88.2 or 176. There is no "auto" setting however from what I understand because SACD isn't PCM based there is no "normal" - it'll be re-sampled no matter what setting is chosen because you're converting a non PCM audio track to PCM. With that said I was thinking re-sampling the audio twice (SACD at a high sample rate and then SoX) would be less precise than just resampling once (SACD) since there is no way to avoid the initial SACD resample even if SoX is great.

Does that make sense?

Or do you think it possible that using a high sample rate like 176 for the "first pass" will essentially minimize the loss of fidelity, it'll be more like a "copy" than a re-sample? ...And therefore letting SoX do the "hard" math part (re-sampling to 44.1 could be a better option.
Title: Re: SACD to FLAC
Post by: Wombat on 2018-08-20 15:10:32
A while back Mans Rullgard added support to SoX for DSD resampling. It applies the SoX resampling to 1bit DSD directly. https://github.com/mansr/sox
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-20 16:31:36
A while back Mans Rullgard added support to SoX for DSD resampling. It applies the SoX resampling to 1bit DSD directly. https://github.com/mansr/sox
Fantastic, thank you

Ben
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-20 21:31:50
I just ran the command
sox 1.dsf 1.wav
and got the error: FAIL formats: no handler for file extension 'dsf'.
Do I need to add a windows component or something?

on a different file
sox 1.flac 1.wav
worked fine.
Title: Re: SACD to FLAC
Post by: saratoga on 2018-08-20 21:54:16
I just ran the command
sox 1.dsf 1.wav
and got the error: FAIL formats: no handler for file extension 'dsf'.
Do I need to add a windows component or something?

What version are you running?
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-21 13:34:34
What version are you running?
https://sourceforge.net/projects/sox/files/sox/14.4.2/sox-14.4.2-win32.zip

okay so from reading another thread:
https://www.computeraudiophile.com/forums/topic/38313-converting-dsd-to-pcm/

Do I have to install the DSD patches? I'm running windows and trying to figure out what files from the following site to download and where to install/place them:
A while back Mans Rullgard added support to SoX for DSD resampling. It applies the SoX resampling to 1bit DSD directly. https://github.com/mansr/sox

Title: Re: SACD to FLAC
Post by: blurry_light on 2018-08-21 15:09:34
What version are you running?
https://sourceforge.net/projects/sox/files/sox/14.4.2/sox-14.4.2-win32.zip

okay so from reading another thread:
https://www.computeraudiophile.com/forums/topic/38313-converting-dsd-to-pcm/

Do I have to install the DSD patches? I'm running windows and trying to figure out what files from the following site to download and where to install/place them:
A while back Mans Rullgard added support to SoX for DSD resampling. It applies the SoX resampling to 1bit DSD directly. https://github.com/mansr/sox



A cursory glance at that computeraudiophile thread shows that someone found this link (https://audiodigitale.eu/repo/sox/) from which the file sox-dsd-win32-MSVC.zip can be downloaded. I downloaded a DSD64 (which I believe is the kind of encoding SACD's use; correct me if I am mistaken) file from here (http://www.2l.no/hires/) and managed to convert it to FLAC with the included SoX.exe executable included in the ZIP file (extract all of the compressed file first).

I used the following batch file in Windows 10 with the executable in question:

Code: [Select]
for %%a in ("YourInputFolderHere\*.dsf") do sox -V3 -S -D "%%a" -b 16 "YourOutputFolderHere\%%~na.flac" rate -v 44100
pause

I had to include the "-D" parameter to stop SoX from dithering; I'm not sure why it was automatically doing this. Maybe it's better? I'm not too sure.

Anyway, this is if you want to encode it in standard CDDA quality (16-bit stereo, 44.1kHz). You can change the bit depth and sampling frequency to whatever you want the FLAC output to be.
Title: Re: SACD to FLAC
Post by: Wombat on 2018-08-21 15:11:31
You need the SoX version of the Mans R. code as compiled exe only. The sox-dsd-win32-MSVC.zip from over there should do it https://audiodigitale.eu/repo/sox/

LOL! Just when i typed that blurry_light answered.
Title: Re: SACD to FLAC
Post by: Wombat on 2018-08-21 15:17:28
I had to include the "-D" parameter to stop SoX from dithering; I'm not sure why it was automatically doing this. Maybe it's better? I'm not too sure.
SoX does dither when going to 16bit because it is common practise and not because it is bad. If you ask mathematical skilled people they even recommend 24bit to be dithered when coming from the 32bit integer SoX routines.
Title: Re: SACD to FLAC
Post by: blurry_light on 2018-08-21 15:25:19
I had to include the "-D" parameter to stop SoX from dithering; I'm not sure why it was automatically doing this. Maybe it's better? I'm not too sure.
SoX does dither when going to 16bit because it is common practise and not because it is bad. If you ask mathematical skilled people they even recommend 24bit to be dithered when coming from the 32bit integer SoX routines.

Yes -- that's when going from 32-bit PCM to 24-bit PCM. But this is PDM to PCM; is dither still justified here? I'm admittedly not familiar with the ins and outs of PDM so maybe SoX's default behavior is acceptable.

EDIT: I think I see what you mean; so because SoX uses a 32-bit internal routine (regardless of the *actual* source being PDM, it uses 32-bit PCM internally), and you request 16-bit, this is why it dithers?
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-21 16:32:42
Thank you both...I have been playing around with that "other" file but wasn't sure if it was "official" or trusted. Was literally just about to write how I got it working.

Thanks for the responses.

After playing a bit, a couple more questions of advice. When doing what I'll call a standard convert:
sox 01.dsf -b 16 01.wav rate -v -s 44100

I get output files that when looked at in Audacity the peaks never go above or below 0.5 (see attached "normal").
I've read that PDM to PCM converting always loses volume and therefore it could be added back in.
Do you think it's worth trying to boost them a little bit - in theory could anything be gained other than having to turn the volume knob a little less?

I tried using both gain and volume adjustments but any positive number yields clipping. When looking at the output files in audacity...the gained and clipped files look identical to the not gained ones and doesn't show any clipping. When looking at the command prompt side of (attached "gain6") it looks like the input file was gained...not the output. I guess I'm wondering how to gain the output file.
sox 01.dsf -b 16 01.wav gain 6 rate -v -s 44100
or
sox 01.dsf -b 16 01.wav vol 6dB -v -s 44100

The only thing I could do that wouldn't clip was use --norm
sox --norm=-1 01.dsf -b 16 01.wav vol 1dB -v -s 44100

Am I getting the gain coding wrong?
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-21 17:01:21
Wow, I'm dumb. Simply changing it from
sox 01.dsf -b 16 01.wav gain 6 rate -v -s 44100
to
sox 01.dsf -b 16 01.wav rate -v -s 44100 gain 6
I believe did it.

Thanks again for the help
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-21 17:14:27
Last question: Is there a way to get sox to create a log file so I can check for errors later in case I accidentally hit a key and close the batch script...for example when waking the computer from a screen saver if I walk away after a big batch.

I tried adding > log.txt but that yielded and empty text file and I couldn't find any options in the Sox command line help section.
Title: Re: SACD to FLAC
Post by: blurry_light on 2018-08-21 19:09:39
Last question: Is there a way to get sox to create a log file so I can check for errors later in case I accidentally hit a key and close the batch script...for example when waking the computer from a screen saver if I walk away after a big batch.

I tried adding > log.txt but that yielded and empty text file and I couldn't find any options in the Sox command line help section.

Try adding ">> output.txt", with two > symbols, at the end of the main loop of the script.

So, for example (here we let SoX dither, as explained before)

Code: [Select]
for %%a in ("YourInputFolderHere\*.dsf") do sox -V3 -S "%%a" -b 16 "YourOutputFolderHere\%%~na.flac" rate -v 44100 >> output.txt
pause
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-21 20:40:33
No dice but thanks for idea. I can't remember if command prompt has a mode to write everything to a text file. I know for Lame, FLAC and robocopy for example, the .exe file itself has a "logging" option.

I noticed that if you just run it silent, then errors are quite obvious - so I'll do that I guess.
Title: Re: SACD to FLAC
Post by: blurry_light on 2018-08-21 21:54:34
No dice but thanks for idea. I can't remember if command prompt has a mode to write everything to a text file. I know for Lame, FLAC and robocopy for example, the .exe file itself has a "logging" option.

I noticed that if you just run it silent, then errors are quite obvious - so I'll do that I guess.

Hm, I just tried it and it doesn't seem to work. However, if you remove the "pause" at the end and have it write both standard output and standard error from the command prompt or PowerShell, you can have a log file.

The batch file would be

Code: [Select]
for %%a in ("YourInputFolderHere\*.dsf") do sox -V3 -S "%%a" -b 16 "YourOutputFolderHere\%%~na.flac" rate -v 44100

And in the command prompt or PowerShell, you'd invoke it as

Code: [Select]
PS DirectoryHere> BatchFile.bat > log.txt 2>&1

Now log.txt will have all the output that was generated (but there's no console output in real time; this is why the "pause" part was removed, so when you get back the command prompt, you know it's finished).
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-22 01:32:06
Thanks... I'll try that Saturday when I get back from my mini vacation to the White Mountains. Cheers!
Title: Re: SACD to FLAC
Post by: bmcelvan on 2018-08-27 19:26:53
And in the command prompt or PowerShell, you'd invoke it as

Code: [Select]
PS DirectoryHere> BatchFile.bat > log.txt 2>&1
This works great, thanks!
Title: Re: SACD to FLAC
Post by: magicgoose on 2018-08-29 11:14:37
DSD support in SoX is great. I think this means that we can finally abandon all worries about possibly doing something "not right" with DSD -> PCM conversion.
Title: Re: SACD to FLAC
Post by: kode54 on 2018-08-29 11:25:49
You can also convert to WavPack and maintain the DSD format, and the WavPack libraries also support DSD -> PCM conversion by default in apps that don't request the DSD format on decode. Probably not what you were concerned about, though.
Title: Re: SACD to FLAC
Post by: mycroft on 2018-08-29 14:01:28
You can also use ffmpeg.
Title: Re: SACD to FLAC
Post by: blurry_light on 2018-09-01 15:22:48
And in the command prompt or PowerShell, you'd invoke it as

Code: [Select]
PS DirectoryHere> BatchFile.bat > log.txt 2>&1
This works great, thanks!


You're welcome!
SimplePortal 1.0.0 RC1 © 2008-2019