NU-Tech Forum Index Back to NU-Tech Web Site
NU-Tech Forum
 
 Forum FAQForum FAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Shared memory between NUTS

 
Post new topic   Reply to topic    NU-Tech Forum Index -> NUTS Development Kit FAQs
View previous topic :: View next topic  
Author Message
Cesco86



Joined: 02 May 2012
Posts: 4

PostPosted: Wed Jun 20, 2012 2:11 pm    Post subject: Shared memory between NUTS Reply with quote

Hi everybody, I've been working on NU-TECH for few weeks trying to implement an AGC (Automatic Gain Control) as a user-defined NUT. Since I need to avoid feedbacks, I have to be able to share a variable, containing the gain value, between 2 NUTS (forward AGC and backward AGC). If I send that value by streaming a feedback occurs in the topology I'm using. I've been looking for some way to share memory and I found the NDKAddendum manual (http://www.nu-tech-dsp.com/_papers_/NDKAddendum.pdf). Here, functions which allow to share memory are described but I can't find them in the NUT template I've downloaded from www.nu-tech-dsp.com (I'm using the last one, for NU_TECH 2.3). Since this functions are not present in LEEffect.h I'm not able to use them. Is there any other NUT template which I need to use them? How can I make it works? Thank you.

Best regards,
Francesco
Back to top
View user's profile Send private message
paoloperetti



Joined: 17 Mar 2006
Posts: 2

PostPosted: Thu Jun 21, 2012 8:24 am    Post subject: Reply with quote

There are some changes in shared memory management. In order to use this NU-Tech feature, in LEEffect.h you should add the following defines:
Code:
#define NUTS_CREATEMEMORY       144
#define NUTS_REMOVEMEMORY       145
#define NUTS_READMEMORY         146
#define NUTS_WRITEMEMORY        147
#define NUTS_ADDNOTIFYMEMORY    148
#define NUTS_REMOVENOTIFYMEMORY 149
#define NUTS_EXISTMEMORY        150
#define NUTS_GETSIZEMEMORY      151

and the following struct:
Code:
struct SharedMemoryHelper
{
 char   *ItemName;
 int    DataSize;
 int    Offset;
 LPVOID pData;
 BOOL   AutoRedim;
 LPVOID pPlug;
 int    Reserved;
};

In yuor plug-in, you shoud declare a variable of type struct SharedMemoryHelper and you should initialize the variable with your desired data. For example:
Code:
struct SharedMemoryHelper fData;

fData.AutoRedim = false;
fData.DataSize = 100 * sizeof(double);
fData.ItemName = new char[100];
sprintf_s(fData.ItemName, 50, "MySharedMemory");
fData.Offset = 0;
fData.pPlug = NULL;
fData.pData = new double[100];
memset(fData.pData, 0, sizeof(double) * 100);

Now, you can use the functions described in the Addeddum by calling a CBFunction where the second parameter is a define relative to a sharedMemory function and the last parameter is a pointer to a struct SharedMemoryHelper variable. For example,
Code:
BOOL CreateItem(LEEffect *eff, char *ItemName, int ItemSize);

becomes
Code:
CBFunction(this, NUTS_CREATEMEMORY, 0, &fData);

Let us know.
Back to top
View user's profile Send private message
Cesco86



Joined: 02 May 2012
Posts: 4

PostPosted: Thu Jun 21, 2012 12:39 pm    Post subject: Reply with quote

Thank you for your reply. I'd like to ask you something else anyway, about my doubts.

First I delcared the SharedMemoryHelper struct in my PlugIn class (private declaration) and i initialized it in the constructor.

Then I writed data from the first NUT by assigning a value to *(fData.pData) and calling:
Code:
CBFunction(this, NUTS_WRITEMEMORY, 0, &fData);

Is this right?

Now, how am I supposed to receive data from the second NUT? In the addendum manual i found this:
Code:
 //receive notifications through LEOnNUTechMessage function:
LPVOID __stdcall PlugIn::LEOnNUTechMessage(int MessageType,int MessageID,WPARAM wParam,LPARAM lParam)
{
if (MessageType==MSG_MEMORY)
{
if (MessageID==MEM_WRITE)
{
double GainValue=0.0;
SharedMemoryHelper *info=(SharedMemoryHelper *)lParam;
ReadItem(this,info->ItemName,&GainValue,info->DataSize,info->Offset);
}
}
return NULL;
}

but MSG_MEMORY and MEM_WRITE are not defined. What value should they have?

Best regards,
Francesco
Back to top
View user's profile Send private message
paoloperetti



Joined: 17 Mar 2006
Posts: 2

PostPosted: Thu Jun 21, 2012 1:51 pm    Post subject: Reply with quote

In your second NUTs you should declare and initialize the struct as in the first NUTs. Subsequently, you can easily use the following CBFunction
Code:
CBFunction(this, NUTS_READMEMORY, 0, &fData);

in order to read the previously stored data.
Back to top
View user's profile Send private message
Cesco86



Joined: 02 May 2012
Posts: 4

PostPosted: Fri Jun 22, 2012 10:02 am    Post subject: Reply with quote

Now it's working! Thank you for your help!

Best regards,
Francesco
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NU-Tech Forum Index -> NUTS Development Kit FAQs All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2001, 2005 phpBB Group