New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ Code cleanup #566
C++ Code cleanup #566
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general not a big fan of the naming of function arguments or member variables. Hungarian type notation should really be avoided as it is totally redundant information.
for (int i = 0; i < sampleCount*channels && i < 4095; i++, iter++) { | ||
if (samples[i] > 0) { | ||
currentSample = 20.0f * log10((float)samples[i]); | ||
ACRE_RESULT CAmplitudeAttenuation::process(int16_t *const a_samples, const int32_t ac_sampleCount, const int32_t ac_channels, CPlayer *const a_player) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please not do pseudo hungarian notation? If you want to signify a variable is an argument I've always prefered a trailing _, so player_
. Noting the constiness of an argument is also not super helpful in most modern editors/IDEs. It should show a redline.
Can do |
@@ -16,13 +16,13 @@ | |||
|
|||
// trim from start | |||
static inline std::string <rim(std::string &s) { | |||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace)))); | |||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int32_t, int32_t>(std::isspace)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really be converted to using a lambda. std::ptr_fun has been deprecated in C++11. and std::not1 has been deprecated in c++17.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is example code for ltrim/rtrim https://github.com/dedmen/armake/blob/cpp/src/utils.cpp#L251
Also supporting tabs.
@@ -210,7 +212,7 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) | |||
char *value = new char[4096]; | |||
//DEBUG("Read from pipe [%d]\n", hPipe); | |||
ret = ReadFile(readHandle, (LPVOID)value, 4096, &cbRead, NULL); | |||
if ( ! ret) { | |||
if ( !ret) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( !ret) { | |
if (!ret) { |
?
m_sfreq = 48000.0f; | ||
m_mfreq = 5200.0f; | ||
lpFilter1.setup(4, (float64_t) m_sfreq, (float64_t) m_mfreq*0.3); | ||
lpFilter2.setup(4, (float64_t) m_sfreq, (float64_t) m_mfreq*0.5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use proper c++ static_cast
short maxAmp = 1; | ||
for (int i = 0; i < sampleCount; ++i) { | ||
samples[i] = (short)(((float)tempSamples[i]*1.0f)*cos(((float)i/(sfreq/mfreq))*1.4*M_PI)); | ||
int16_t *tempSamples = new int16_t[sampleCount]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use std::vector with resize for a temp array. That way you don't have to worry about cleanup.
|
||
g_Log = (Log *)new Log(const_cast<char *>(loggingPath.c_str())); | ||
g_Log = (Log *) new Log(const_cast<char *>(loggingPath.c_str())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the reason of casting Log*
to Log*
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And why is it casting a constant string to a non constant char*, That might be undefined behavior.
for (int i = 0; i < n; ++i) | ||
result[i] /= n; | ||
return result; | ||
if (m_inverse == false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== false
?
if (m_inverse == false) | |
if (!m_inverse) |
#define TS_SAMPLE_RATE 48000 | ||
#define CUTTOFF_FREQ 15000 | ||
#define TS_SAMPLE_RATE_Hz 48000 | ||
#define CUTTOFF_FREQ_Hz 15000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#define CUTTOFF_FREQ_Hz 15000 | |
#define CUTTOFF_FREQ_Hz 15000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Macros are usually identified by being all upper case. The z is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is accepted when trying to define units. mHz is not the same as MHz and so on.
|
||
DECLARE_MEMBER(int, ChannelCount); | ||
virtual __inline void setChannelCount(const int32_t value) { this->m_channelCount = value; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__inline is MSVC specific, inline
is the real keyword.
Also inline doesn't make much sense on virtual functions. If the compiler doesn't know exactly that the class will be that exact type, then it won't be able to inline. And if it knew that it was that type, then it would also inline if you don't put the inline keyword there.
bool getConnected() const { return (this->getConnectedRead() && this->getConnectedWrite()); }; | ||
void setConnected (const bool value) { this->setConnectedRead(value); this->setConnectedWrite(value); }; | ||
|
||
virtual __inline void setPipeHandleRead(const HANDLE value) { this->m_pipeHandleRead = value; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions should be override
, not virtual
virtual __inline void setPipeHandleRead(const HANDLE value) { this->m_pipeHandleRead = value; } | |
void setPipeHandleRead(const HANDLE value) override { this->m_pipeHandleRead = value; } |
delete this->buffer; | ||
this->buffer = NULL; | ||
if (this->m_buffer) { | ||
delete this->m_buffer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just make it a vector and it will cleanup itself.
@@ -21,11 +21,11 @@ RPC_FUNCTION(ext_remoteStopSpeaking) { | |||
this->getSelf()->getCurveScale() | |||
) */ | |||
|
|||
ACRE_ID id = (ACRE_ID)vMessage->getParameterAsInt(0); | |||
ACRE_ID id = (ACRE_ID) vMessage->getParameterAsInt(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast and auto?
Is the cast even necessary? Can't it implictly convert on =?
@@ -5,7 +5,7 @@ | |||
|
|||
Log *g_Log = NULL; | |||
|
|||
Log::Log(char *logFile) { | |||
Log::Log(char *logFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const char* ?
ACRE_RESULT updateShouldSwitchTS3Channel(const bool state); | ||
bool shouldSwitchTS3Channel(); | ||
|
||
virtual __inline void sethadVAD(const bool value) { this->m_hadVAD = value; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setHadVad* ?
Also override.
@@ -6,53 +6,48 @@ | |||
#include <string> | |||
|
|||
|
|||
typedef struct __WAVEDESCR | |||
typedef struct __waveDescr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a library struct
https://github.com/xinshangbo/WendySpeech/blob/master/src/CutVoiceCPP/Wave.h#L6
No further activity and tons of conflicts, would need to get re-done. |
When merged this pull request will: