lossyWAV 1.3.0 Delphi to C++ Translation Thread, Added noise linear PCM bitdepth reduction method. |
![]() ![]() |
lossyWAV 1.3.0 Delphi to C++ Translation Thread, Added noise linear PCM bitdepth reduction method. |
Aug 22 2012, 19:27
Post
#1
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
And he's off!
Tycho has kindly started the translation of lossyWAV from Delphi to C++. I'll need to learn it to be able to contribute meaningfully.... Changelog: lossyWAV beta 1.3.0m 25/03/2013
This post has been edited by Nick.C: Mar 30 2013, 15:37
Attached File(s)
-------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Aug 22 2012, 19:55
Post
#2
|
|
|
Group: Members Posts: 1559 Joined: 24-June 02 From: Catalunya(Spain) Member No.: 2383 |
Hi Tycho. That sounds nice.
Remember that there are the java and C# ports (although they are from older versions) that could be of help during the conversion: jLossywav: (based on lossywav 1.1.4) http://www.hydrogenaudio.org/forums/index....st&p=645228 C# (based on 1.0?) : http://www.hydrogenaudio.org/forums/index....showtopic=67418 |
|
|
|
Aug 22 2012, 20:48
Post
#3
|
|
![]() Group: Members (Donating) Posts: 765 Joined: 12-March 05 From: Kiel, Germany Member No.: 20561 |
Is the port done publicly, like on github or similar? This community has some very knowledgeable C++ hackers, so it might speed the process and help with finding and fixing bugs.
This post has been edited by Kohlrabi: Aug 22 2012, 20:49 -------------------- Audiophiles live in constant fear of jitter.
|
|
|
|
Aug 22 2012, 23:11
Post
#4
|
|
|
Group: Members Posts: 345 Joined: 5-August 03 Member No.: 8183 |
JAZ, Thanks, I was aware of the C# translation of version 1.0, but had missed out your java translation. Nice. There are a lot of changes in 1.3 though, and much of the work is to convert the I/O handling and runtime linking with fftw3-3 library. First step is something that compiles with gnu g++ on windows. Next would be VS2010, and then Linux/Mac g++, but that could easily someone else do.
Kohlrabi, I haven't thought about using github yet. My initial thought was just to get most of the code to compile, and then upload the code here. Useful help would be that people browsed through it and verified that the .pas and the .h/.cpp files does the same thing, but I wouldn't mind if people worked on it too. I think that modern optimized C++ compilers (both 32 and 64 bit) are able to improve on speed a fair bit, but portability and accessibility is as important. |
|
|
|
Aug 25 2012, 19:55
Post
#5
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
Hi Tycho,
How are you getting on? -------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Aug 25 2012, 23:36
Post
#6
|
|
|
Group: Members Posts: 345 Joined: 5-August 03 Member No.: 8183 |
It's progressing quite well. Many of the files are files are basically compiling now, but there are still some unresolved functions, e.g. the Delphi Write() function must be emulated, or all the calls to it must be rewritten. Also some of the IO routines need some work, as I mentioned.
I can post the code as it is tomorrow evening, so you can have a feel of it. Later I will come back with few questions for you, and tell a few things I've done during translation. E.g. You have a few small functions in assembly only, like the ArcTan_Complex(). Shouldn't that return a complex number and not a float? On googling it, I found an implementation: (C++11 has it in the standard lib now) Complex atan(Complex c) { Complex log_v = log( Complex(1.0 - c.imag(), c.real()) / Complex(1.0 + c.imag(), -c.real()) ); return Complex( log_v.imag() * 0.5, -log_v.real() * 0.5 ); } The float you are returning is maybe the magnitude of the complex number returned here? |
|
|
|
Aug 25 2012, 23:46
Post
#7
|
|
![]() Group: Developer Posts: 2986 Joined: 2-December 07 Member No.: 49183 |
CODE function ArcTan_Complex(const X: tDComplex): Extended; asm FLD X.im FLD X.re FPATAN End; According to google it is arctg(x.im/x.re) so basically it is C function atan2(x.im, x.re). ...IMHO. |
|
|
|
Aug 26 2012, 21:40
Post
#8
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
Apologies - you've found some of the "dirtier" code in lossyWAV....
The ArcTan_Complex function is, as lvqcl has rightly said, equivalent to a two input atan function. -------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Aug 28 2012, 11:55
Post
#9
|
|
|
Group: Members Posts: 21 Joined: 16-August 12 Member No.: 102388 |
Once we have C++ version can we expect nice speed up after compiling with Intel Compiler with enabled auto vectorization and auto paralyzation? I must admit that delphi's version is rather slooow. It would be awesome if code was multithreaded and SIMD friendly.
This post has been edited by Atak_Snajpera: Aug 28 2012, 11:56 |
|
|
|
Aug 28 2012, 18:22
Post
#10
|
|
|
Group: Members Posts: 345 Joined: 5-August 03 Member No.: 8183 |
I haven't studied enough how the data is processed, but I believe that the code must be made more reentrant, so that central functions relies exclusively on own stack data, and not global data structures (except readonly) as today. This opens the door for parallel computation if the algorithm allows for it, which I believe it does.
|
|
|
|
Aug 28 2012, 19:01
Post
#11
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
A simple parallelism would be to process each channel concurrently as channels are independent (even if linked then that linking of bits_to_remove would occur after all the FFT analyses have been completed for a given codec block).
-------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Aug 28 2012, 20:35
Post
#12
|
|
|
Group: Members Posts: 21 Joined: 16-August 12 Member No.: 102388 |
A simple parallelism would be to process each channel concurrently as channels are independent (even if linked then that linking of bits_to_remove would occur after all the FFT analyses have been completed for a given codec block). that would be a good start. 2x faster proccesing on stereo track and even more for typical 5.1 movie sound track (assuming that user has atleast quad core). |
|
|
|
Aug 28 2012, 20:49
Post
#13
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
Another would be to have the FFT analyses run in parallel - each 512 sample codec block (44.1kHz / 48kHz samplerate) has 1x 1024 sample, 16x 64 sample and 32x 32 sample FFT analyses carried out on it (per channel).
[edit] can't count, apparently.... [/edit] This post has been edited by Nick.C: Aug 28 2012, 20:50 -------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Aug 29 2012, 14:18
Post
#14
|
|
|
Group: Members Posts: 21 Joined: 16-August 12 Member No.: 102388 |
I have noticed that original LossyWav 1.3 does not support .wavs larger than 4GB. My wav file is 5.2GB and lossyWAV sees only 1.2 GB. LossyWav also does not support wave64 format either.
![]() Due to the same reason pipes do not work either with large flacs CODE flac.exe -d "E:\Avatar.2009.BluRay.REMUX.1080p.AVC.DTS-HD.MA5.1.flac" --stdout --silent | lossywav.exe - --stdout | flac.exe - -b 512 -8 --silent -o "E\lossy.flac" i think that new version should have something like --readtoeof or --ignorelength switch like other encoders (Aften AC3 , FhGAACEnc or OpusEnc) This post has been edited by Atak_Snajpera: Aug 29 2012, 14:36 |
|
|
|
Aug 29 2012, 17:49
Post
#15
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
A specification compliant WAV file can be no larger than 4GB (minus a few bytes for header and format information).
Maybe looking at RIFF64 or BWF would be a better way forward to cope with very large files. -------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Aug 29 2012, 18:40
Post
#16
|
|
|
Group: Members Posts: 21 Joined: 16-August 12 Member No.: 102388 |
Without --ignorelength switch lossyWav is useless for movie sound tracks. I can't even use pipe for direct processing.
BTW. Do you know maybe why your sources won't compile in delphi 7 pro? This post has been edited by Atak_Snajpera: Aug 29 2012, 18:44 |
|
|
|
Aug 29 2012, 22:30
Post
#17
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
You could split the soundtrack into chapters, process with lossyWAV and then recombine using foobar2000.
I don't know about Delphi 7 Pro - I have been using Turbo Delphi Explorer 2006. -------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Aug 30 2012, 12:44
Post
#18
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
Tycho,
Are there any specific compiler options that I should be using for compilation of the project? I have downloaded the Dev-CPP IDE with MinGW 4.6.0.2 - primarily because I wanted a portable mode. Quite liking it and have started "playing" with it to get my head round C++. On the Write() issue, would fprintf() be better? It would certainly make formatting the output much easier. I have got v0.3 to compile as far as nOutput.cpp. -------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Aug 30 2012, 23:31
Post
#19
|
|
|
Group: Members Posts: 345 Joined: 5-August 03 Member No.: 8183 |
Nick,
Good to hear you're progressing with c++. Yes, the old ANSI C printf (stdio.h) is in many ways easier and more compact to use, although less type safe (it normally does not check arguments in the printf statements with the formatting string). Personally I would prefer to use the current standard which is the fstream/iostream interface. To be blunt, DEV Cpp has been dead for years, and it's Windows only (written i Delphi actually). There are better alternatives as I have mentioned earlier. For cross platform I would first recommend Qt Creator (available on Win,Linux,OS X). It is meant for Qt apps, but you may easily develop pure C++ projects without Qt and qmake. It supports many compilers, .e.g Visual Studio (Express) and GNU Mingw. You may download Qt libraries 4.8.2 (not the whole Qt SDK) for the qmake and cross platform GUI ++ libs. As a second alternative you can look at CodeLite, which is a one-man project only, then Code::Blocks which is similar. I am going to configure Qt Creator myself with Mingw to fix the compilation issues there. It behaves different than VC++. I have currently Mingw 4.7.0 on my machine so there may be differences from 4.6.2. Don't worry about the Write() now, I will take care of that one when we get there. This is probably information overload, so take it easy. This post has been edited by tycho: Aug 30 2012, 23:35 |
|
|
|
Sep 7 2012, 19:05
Post
#20
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
Updated executable later tonight - huge thanks to Tycho for getting me off my butt to delve into C++ with his translation of the Delphi source code.
A few issues found and corrected, not least the in FFT code - there were a few issues in there (int equates to FLOOR; >> is shift-arithmetic-right, not a simple shift right; log is ln, not log10....). This post has been edited by Nick.C: Sep 7 2012, 21:28 -------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Sep 7 2012, 20:36
Post
#21
|
|
|
Group: Members Posts: 21 Joined: 16-August 12 Member No.: 102388 |
what is still missing in current c version vs original?
|
|
|
|
Sep 7 2012, 20:49
Post
#22
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
A bit of accuracy - there's a bug somewhere in the chain after the FFT analyses that still has to be tracked. Adaptive noise shaping is confirmed to be working though.
-------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Sep 7 2012, 21:01
Post
#23
|
|
![]() lossyWAV Developer Group: Developer Posts: 1722 Joined: 11-April 07 From: Wherever here is Member No.: 42400 |
lossyWAV beta 1.3.0b
Changelog: Internal FFT routines now work. To do list: Piped input / output. Track down accuracy error post FFT analyses. This post has been edited by Nick.C: Sep 15 2012, 12:04 -------------------- lossyWAV -q X | FLAC -8 ~= 308kbps
SGS III (Rooted) + 64GB |
|
|
|
Sep 7 2012, 21:29
Post
#24
|
|
|
Group: Members Posts: 21 Joined: 16-August 12 Member No.: 102388 |
|
|
|
|
Sep 8 2012, 01:37
Post
#25
|
|
![]() Group: Developer (Donating) Posts: 713 Joined: 1-December 07 Member No.: 49165 |
Is there any reason for custom FFT? Why not something like KISSFFT or something?
|
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 26th May 2013 - 07:00 |