IPB

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
tycho
post Aug 26 2012, 22:02
Post #1





Group: Members
Posts: 345
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)

Optimizations:
* 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: 75
 
Go to the top of the page
+Quote Post
 
Start new topic
Replies
[JAZ]
post Aug 27 2012, 20:22
Post #2





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



A couple of code snippets:

in nSupport.h:

CODE

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())
{
filetest.close();
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
CODE

#if defined _MSC_VER
#if _MSC_VER > 1500
#include <stdint>
#else
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;
#endif
#endif

I also needed to redefine the way you declared the FFTW interface, like this:
fftw_interface.h
CODE

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_interface.cpp
CODE

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
riff.cpp
riff.hpp
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
db1989
post Aug 27 2012, 21:40
Post #3





Group: Super Moderator
Posts: 5157
Joined: 23-June 06
Member No.: 32180



QUOTE ([JAZ] @ Aug 27 2012, 20:22) *
in nCore.h, stdint is not present in VS 2008 and below
CODE

#if defined _MSC_VER
#if _MSC_VER > 1500
#include <stdint>
#else
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;
#endif
#endif
I canít claim to be an expert, but I thought that the reason C99 introduced these numbered types in its stdint.h was due to a demand for integers of known and fixed widths, with the result that these types are guaranteed to have the corresponding widths in bits. Although it may not matter for lossyWAV, I would say in a general sense that typedefing them to be equivalent to standard types, which come with no guarantee of a given fixed width (you get a minimum width at best), doesnít seem an adequate compensation for a compiler that lacks stdint.h.
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: 20th April 2014 - 07:22