Welcome Guest ( Log In | Register )

> Upload forum rules

- No over 30 sec clips of copyrighted music. Cite properly and never more than necessary for the discussion.

- No copyrighted software without permission.

- Click here for complete Hydrogenaudio Terms of Service

lossyWAV 1.3.0 source translated to C++ from Delphi
post Aug 26 2012, 22:02
Post #1

Group: Members
Posts: 346
Joined: 5-August 03
Member No.: 8183

Here is the first public preview of the source translation of lossyWAV 1.3.0 to C++. It is not finished, but the main work is done.

- vc10_err.txt list the current compiler output in Visual Studio C++ 2010.
- A number of built-in Delphi functions are not yet converted. Most are trivial, but Write() involves some work.

Please note, I know very little of how the code actually works, I basically translated it line by line, and did minor optimizations.
Developers can look over the code and compare with the Delphi source. I have tried to take into account a number of C++'s quirks, e.g.:
- integer / integer -> integer (not floating point, but if one operand is float, it returns float)
- unsigned int (opr) signed int -> unsigned int
- & is bitwise-and, && is boolean-and, likewise with or: |, ||
- c++ base 0 arrays, versus base X in delphi. (range_array class in nSupport.h emulates that)

* var = var opr value --> var opr= value;
* var = var + 1 --> ++ var;
* and a few more

I added file nSupport.h that has a few Delphi emulation functions and classes. The shared global variables are only declared in the header file. I've not defined them in the cpp files yet.
Attached File(s)
Attached File  lossyWAV_cpp.7z ( 90.42K ) Number of downloads: 116
Go to the top of the page
+Quote Post
Start new topic
post Aug 27 2012, 20:22
Post #2

Group: Members
Posts: 1853
Joined: 24-June 02
From: Catalunya(Spain)
Member No.: 2383

A couple of code snippets:

in nSupport.h:


inline std::string IntToStr(int intval) {
std::stringstream st;
st << intval;
return st.str();
/*Accounts for Delphi's 1-based index*/
inline std::string Copy(const std::string& in, int begin1b, int amount) {
in.substr(begin1b-1, amount);

inline bool FileExists(std::string file_name) {
std::fstream filetest(file_name.c_str(), std::ios_base::in | std::ios_base::binary);
if (filetest.is_open())
return true;
return false;

Also, note that where you have the Copy calls, you're replacing the Length(string) for sizeof(string). That's wrong. use string.length().

in nCore.h, stdint is not present in VS 2008 and below

#if defined _MSC_VER
#if _MSC_VER > 1500
#include <stdint>
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int int64_t;
typedef unsigned long long int uint64_t;

I also needed to redefine the way you declared the FFTW interface, like this:

typedef void * (* FUN_Plan_DFT_r2c_1d) (int, double* , double* , unsigned int );
typedef void* (* FUN_Plan_DFT_1d)(int, double* , double* , int , unsigned int );
typedef void (* FUN_Execute)(void* );
typedef void (* FUN_Destroy_Plan)(void* );

struct FFTW_Rec
FUN_Plan_DFT_r2c_1d Plan_DFT_r2c_1d;
FUN_Plan_DFT_1d Plan_DFT_1d;
FUN_Execute Execute;
FUN_Destroy_Plan Destroy_Plan;
void* Plans [ MAX_FFT_BIT_LENGTH + 1 ];


FFTW.Plan_DFT_r2c_1d = (FUN_Plan_DFT_r2c_1d) GetProcAddress(FFTW_DLL_Handle, "fftw_plan_dft_r2c_1d");
FFTW.Plan_DFT_1d = (FUN_Plan_DFT_1d) GetProcAddress(FFTW_DLL_Handle, "fftw_plan_dft_1d");
FFTW.Execute = (FUN_Execute) GetProcAddress(FFTW_DLL_Handle, "fftw_execute");
FFTW.Destroy_Plan = (FUN_Destroy_Plan) GetProcAddress(FFTW_DLL_Handle, "fftw_destroy_plan");

Also, i had to add some includes here and there ( <cmath> mostly )

At last, i'm not sure if it will be of help, or it will add to confusion, but these two source files might help on the file loading
That's a .wav file load/save in a mixture of C and C++. (Not the best code anyway, it was scheduled for improvement, but since it works, it has been kept)

This post has been edited by [JAZ]: Aug 27 2012, 20:26
Go to the top of the page
+Quote Post

Posts in this topic

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 25th November 2015 - 21:46