Skip to content

Commit

Permalink
#781_tweak_ReaScript_RMS_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nofishonfriday committed Sep 27, 2017
2 parents 4839af5 + 11dd88c commit 3340de9
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 14 deletions.
17 changes: 15 additions & 2 deletions Breeder/BR_ReaScript.cpp
Expand Up @@ -937,10 +937,23 @@ double NF_GetMediaItemMaxPeak(MediaItem* item)
return maxPeak;
}

double NF_GetMediaItemPeakRMS_Windowed(MediaItem* item)
{
double peakRMS = GetMediaItemPeakRMS_Windowed(item);
return peakRMS;
}

double NF_GetMediaItemPeakRMS_NonWindowed(MediaItem* item)
{
double peakRMSperChannel = GetMediaItemPeakRMS_NonWindowed(item);
return peakRMSperChannel;
}

double NF_GetMediaItemAverageRMS(MediaItem* item)
{
double avrgRMS = GetMediaItemAverageRMS(item);
return avrgRMS;
double averageRMS = GetMediaItemAverageRMS(item);
return averageRMS;

}

// #880
Expand Down
2 changes: 2 additions & 0 deletions Breeder/BR_ReaScript.h
Expand Up @@ -99,7 +99,9 @@ bool BR_Win32_WritePrivateProfileString (const char* sectionName, con

// #781
double NF_GetMediaItemMaxPeak(MediaItem* item);
double NF_GetMediaItemPeakRMS_Windowed(MediaItem* item);
double NF_GetMediaItemAverageRMS(MediaItem* item);
double NF_GetMediaItemPeakRMS_NonWindowed(MediaItem* item);

// #880
bool NF_AnalyzeTakeLoudness_IntegratedOnly(MediaItem_Take* take, double* lufsIntegratedOut);
Expand Down
101 changes: 93 additions & 8 deletions Misc/Analysis.cpp
Expand Up @@ -268,15 +268,16 @@ double GetMediaItemMaxPeak(MediaItem* mi)
}
}

double GetMediaItemAverageRMS(MediaItem* mi)
double GetMediaItemPeakRMS_Windowed(MediaItem* mi)
{
double curAvrgRMS = -150.0;
double maxAvrgRMS = -150.0;
// double curPeakRMS = -150.0;
// double maxPeakRMS = -150.0;

// if MIDI item, don't scan
double sampleRate = ((PCM_source*)mi)->GetSampleRate(); // will rtn. 0 for MIDI items
if (sampleRate == 0.0) return -150.0;

/*
int iChannels = ((PCM_source*)mi)->GetNumChannels();
if (iChannels)
{
Expand All @@ -285,21 +286,105 @@ double GetMediaItemAverageRMS(MediaItem* mi)
a.iChannels = iChannels;
a.dRMSs = new double[iChannels];
// set window size
char str[100];
GetPrivateProfileString(SWS_INI, SWS_RMS_KEY, "-20,0.1", str, 100, get_ini_file());
char* pWindow = strchr(str, ',');
a.dWindowSize = pWindow ? atof(pWindow + 1) : 0.1;
if (AnalyzeItem(mi, &a))
{
for (int i = 0; i < iChannels; i++) {
curAvrgRMS = VAL2DB(a.dRMSs[i]);
if (maxAvrgRMS < curAvrgRMS) {
maxAvrgRMS = curAvrgRMS;
curPeakRMS = VAL2DB(a.dRMSs[i]);
if (maxPeakRMS < curPeakRMS) {
maxPeakRMS = curPeakRMS;
}
}
}
delete[] a.dRMSs;
return maxAvrgRMS;
return maxPeakRMS;
} else {
return -150.0;
}
*/

ANALYZE_PCM a;
memset(&a, 0, sizeof(a));

char str[100];
GetPrivateProfileString(SWS_INI, SWS_RMS_KEY, "-20,0.1", str, 100, get_ini_file());
char* pWindow = strchr(str, ',');
a.dWindowSize = pWindow ? atof(pWindow + 1) : 0.1;

if (AnalyzeItem(mi, &a)) {
return VAL2DB(a.dRMS);
} else {
return -150.0;
}
}

double GetMediaItemPeakRMS_NonWindowed(MediaItem* mi)
{
double curPeakRMS = -150.0;
double maxPeakRMS = -150.0;

// if MIDI item, don't scan
double sampleRate = ((PCM_source*)mi)->GetSampleRate(); // will rtn. 0 for MIDI items
if (sampleRate == 0.0) return -150.0;


int iChannels = ((PCM_source*)mi)->GetNumChannels();
if (iChannels)
{
ANALYZE_PCM a;
memset(&a, 0, sizeof(a));
a.iChannels = iChannels;
a.dRMSs = new double[iChannels];

/*
// set window size
char str[100];
GetPrivateProfileString(SWS_INI, SWS_RMS_KEY, "-20,0.1", str, 100, get_ini_file());
char* pWindow = strchr(str, ',');
a.dWindowSize = pWindow ? atof(pWindow + 1) : 0.1;
*/

if (AnalyzeItem(mi, &a))
{
for (int i = 0; i < iChannels; i++) {
curPeakRMS = VAL2DB(a.dRMSs[i]);
if (maxPeakRMS < curPeakRMS) {
maxPeakRMS = curPeakRMS;
}
}
}

delete[] a.dRMSs;
return maxPeakRMS;
} else {
return -150.0;
}
}

double GetMediaItemAverageRMS(MediaItem* mi)
{
double sampleRate = ((PCM_source*)mi)->GetSampleRate(); // will rtn. 0 for MIDI items
if (sampleRate == 0.0) return -150.0;

ANALYZE_PCM a;
memset(&a, 0, sizeof(a));
a.dWindowSize = 0.0; // non-windowed


if (AnalyzeItem(mi, &a)) {
return VAL2DB(a.dRMS);
}
else {
return -150.0;
}
} // /#781
}
// /#781

void FindItemPeak(COMMAND_T*)
{
Expand Down
2 changes: 2 additions & 0 deletions Misc/Analysis.h
Expand Up @@ -52,4 +52,6 @@ bool AnalyzeItem(MediaItem* mi, ANALYZE_PCM* a);

// #781
double GetMediaItemMaxPeak(MediaItem*);
double GetMediaItemPeakRMS_Windowed(MediaItem*);
double GetMediaItemAverageRMS(MediaItem*);
double GetMediaItemPeakRMS_NonWindowed(MediaItem*);
10 changes: 6 additions & 4 deletions ReaScript.cpp
Expand Up @@ -231,9 +231,11 @@ APIdef g_apidefs[] =
{ APIFUNC(ULT_GetMediaItemNote), "const char*", "MediaItem*", "item", "[ULT] Get item notes.", },
{ APIFUNC(ULT_SetMediaItemNote), "void", "MediaItem*,const char*", "item,note", "[ULT] Set item notes.", },

// #781
{ APIFUNC(NF_GetMediaItemMaxPeak), "double", "MediaItem*", "item", "Returns the greatest max. peak value of active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. Returns -150.0 if MIDI item or empty item.", },
{ APIFUNC(NF_GetMediaItemAverageRMS), "double", "MediaItem*", "item", "Returns the RMS peak level of active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. Returns -150.0 if MIDI item or empty item.", },
// #781
{ APIFUNC(NF_GetMediaItemMaxPeak), "double", "MediaItem*", "item", "Returns the greatest max. peak value of all active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. \n Returns -150.0 if MIDI take or empty item.", },
{ APIFUNC(NF_GetMediaItemPeakRMS_Windowed), "double", "MediaItem*", "item", "Returns the average RMS peak level of all active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. \n Obeys 'Window size for peak RMS' setting in 'SWS: Set RMS analysis/normalize options' for calculation. Returns -150.0 if MIDI take or empty item.", },
{ APIFUNC(NF_GetMediaItemPeakRMS_NonWindowed), "double", "MediaItem*", "item", "Returns the greatest overall (non-windowed) RMS peak level of all active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. \n Returns -150.0 if MIDI take or empty item.", },
{ APIFUNC(NF_GetMediaItemAverageRMS), "double", "MediaItem*", "item", "Returns the average overall (non-windowed) RMS level of active channels of an audio item active take, post item gain, post take volume envelope, post-fade, pre fader, pre item FX. \n Returns -150.0 if MIDI take or empty item.", },

// #880
{ APIFUNC(NF_AnalyzeTakeLoudness_IntegratedOnly), "bool", "MediaItem_Take*,double*", "take,lufsIntegratedOut", "Does LUFS integrated analysis only. Faster than full loudness analysis (<a href=\"#NF_AnalyzeTakeLoudness\">NF_AnalyzeTakeLoudness</a>) . Use this if only LUFS integrated is required." },
Expand Down Expand Up @@ -294,4 +296,4 @@ bool RegisterExportedAPI(reaper_plugin_info_t* _rec)
}
}
return ok;
}
}
16 changes: 16 additions & 0 deletions reascript_vararg.h
Expand Up @@ -543,6 +543,22 @@ static void* __vararg_NF_GetMediaItemMaxPeak(void** arglist, int numparms)
return p;
}

static void* __vararg_NF_GetMediaItemPeakRMS_Windowed(void** arglist, int numparms)
{
double* p =(double*)arglist[numparms-1];
double d = NF_GetMediaItemPeakRMS_Windowed((MediaItem*)arglist[0]);
if (p) *p=d;
return p;
}

static void* __vararg_NF_GetMediaItemPeakRMS_NonWindowed(void** arglist, int numparms)
{
double* p =(double*)arglist[numparms-1];
double d = NF_GetMediaItemPeakRMS_NonWindowed((MediaItem*)arglist[0]);
if (p) *p=d;
return p;
}

static void* __vararg_NF_GetMediaItemAverageRMS(void** arglist, int numparms)
{
double* p =(double*)arglist[numparms-1];
Expand Down
4 changes: 4 additions & 0 deletions whatsnew.txt
@@ -1,3 +1,7 @@
ReaScript RMS functions:
+Fix NF_GetMediaItemAverageRMS() calculation
+Add NF_GetMediaItemPeakRMS_Windowed(), NF_GetMediaItemPeakRMS_NonWindowed()

+Fix issue with action "SWS/AW/NF: Toggle assign random colors if auto group newly recorded items is enabled" (p=1882461&postcount=422)

!v2.9.6 featured build (September 4, 2017)
Expand Down

0 comments on commit 3340de9

Please sign in to comment.