Innovative Integration
 
Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
How to generate a waveform from buffer

 
Post new topic   Reply to topic    II Support Forum Index -> X5-400M
View previous topic :: View next topic  
Author Message
lutfi



Joined: 06 Jun 2011
Posts: 31
Location: Indonesia

PostPosted: Tue Jul 05, 2011 11:32 pm    Post subject: How to generate a waveform from buffer Reply with quote

Hello everyone,

I need some help, what I want to ask is how to generate a waveform from a buffer instead of an external file? I've tried to change the applicationio.cpp in line 696, from
Code:
WaveFile.Load(Settings.WaveFile, Buffer);
become (after defining DG(buffer) as CharDG)
Code:
{
      DG.Resize(static_cast<size_t>(buffer_size));//code I got from StaticWaveform_App.cpp in void WaveformFile::Load
      memcpy(&DG[0], buffer, DG.SizeInElements());
   }

it couldn't work because I thought the buffer is just like another buffer (array of char) but actually the buffer is a class from Innovative::Buffer and this class is has a lot of function.

So, could anyone help me to solve this problem?

thank you Smile
Back to top
View user's profile Send private message Yahoo Messenger
jhenderson
Site Admin


Joined: 07 Mar 2006
Posts: 2267
Location: So. Cal. USA

PostPosted: Wed Jul 06, 2011 2:19 pm    Post subject: Reply with quote

The code listed should copy DG.SizeInElements() bytes from buffer into the start of the payload of the datagram.

While this operation is legal, it seems inefficient. I would recommend calculating the waveform data directly into the datagram (DG) which would eliminate the copy entirely.
Back to top
View user's profile Send private message Visit poster's website
lutfi



Joined: 06 Jun 2011
Posts: 31
Location: Indonesia

PostPosted: Fri Jul 08, 2011 1:09 am    Post subject: Reply with quote

I've tried your suggestion, so I changed the code become like this:
Code:
char *LteBuffer = new char[19000];
   unsigned int LteBufferLen = 19000;
   for (int i=0; i<LteBufferLen; i++)
      LteBuffer[i] = 1;

    if (WaveType < 4)
        Wave.Apply(Buffer);
    else
      // from malibu
        // WaveFile.Load(Settings.WaveFile, Buffer);

      // from us
   {
          CharDG DG(buffer);
         //DG.Resize(static_cast<size_t>(file.tellg()));
         memcpy(&DG[0], LteBuffer, LteBufferLen);
   }


It compileable, but when I run it, it crashed and give me an error code like this:
Quote:
Unhandled exception at 0x6653ed6a (msvcr90d.dll) in Console.exe: 0xC0000005: Access violation writing location 0x00000000.
Back to top
View user's profile Send private message Yahoo Messenger
jhenderson
Site Admin


Joined: 07 Mar 2006
Posts: 2267
Location: So. Cal. USA

PostPosted: Fri Jul 08, 2011 3:31 am    Post subject: Reply with quote

Where did it crash within this function? Use the debugger to determine this. I don't see where Buffer is defined, yet you are calculating a waveform into it.
Back to top
View user's profile Send private message Visit poster's website
lutfi



Joined: 06 Jun 2011
Posts: 31
Location: Indonesia

PostPosted: Sun Jul 10, 2011 6:40 pm    Post subject: Reply with quote

it crash at memcpy(&DG[0], LteBuffer, LteBufferLen);
buffer is variable I create in BuildWave function Innovative::Buffer buffer
Back to top
View user's profile Send private message Yahoo Messenger
jhenderson
Site Admin


Joined: 07 Mar 2006
Posts: 2267
Location: So. Cal. USA

PostPosted: Mon Jul 11, 2011 4:55 am    Post subject: Reply with quote

The fragment:
Code:
 CharDG DG(buffer);

wraps a datagram around existing array buffer. But, I do not see where you created and sized this array. If the underlying array is not allocated to hold LteBufferLen chars, it would explain the crash.
Back to top
View user's profile Send private message Visit poster's website
bree



Joined: 11 Jul 2011
Posts: 7

PostPosted: Wed Jul 13, 2011 7:57 pm    Post subject: Can't generate correct waveform Reply with quote

Hi everyone, I'm newbie here. Actually, I'm facing same problem with Lutfi. I've transferred values from buffer to CharDG successfully. My buffer is 100000 in length and char-typed. But, I can't generate correct waveform in my oscilloscope.

Code:

void StartBufferStream(Buffer & buffer)
{
        int bufLength = 100000;
   char myBuf[100000];
   for(int i = 0; i < bufLength; i++)
   {
      if(i < 25000)
         myBuf[i] = 100;
      else if(i > 75000)
         myBuf[i] = 0;
      else
         myBuf[i] = i/5;
      cout << (int)myBuf[i] << endl;
   }
   CharDG DG(buffer);

   int buffer_size = (int)(bufLength*sizeof(char));
   DG.Resize(static_cast<size_t>(buffer_size));
   memcpy(&DG[0], &myBuf[0], buffer_size);

   /*Testing copied buffer*/
   for(int i = 0; i < 100; i++)
   {
      cout << "The result: " << (int)DG.at(i) << endl;
   }
}


Is my approach correct? I think I'm missing something here. Thank you! And sorry for my bad english.
Back to top
View user's profile Send private message
jhenderson
Site Admin


Joined: 07 Mar 2006
Posts: 2267
Location: So. Cal. USA

PostPosted: Thu Jul 14, 2011 9:06 am    Post subject: Reply with quote

It is the responsibility of the application software to provide the buffer containing the waveform data to the module using the Send method within the HandleDataRequired() callback event. In the fragment below, it is assumed that the buffer called WaveformPacket contains waveform data to be played on the output device of the module.

Code:
//---------------------------------------------------------------------------
// ApplicationIo::HandleDataRequired()
//---------------------------------------------------------------------------

void ApplicationIo::HandleDataRequired(PacketStreamDataEvent & Event)
{
    ShortDG Packet_DG(WaveformPacket);

    //
    //  No matter what channels are enabled, we have one packet type
    //    to send here
    PS->Send(WaveformPacket);
}


In your code fragment, a buffer object, Buffer, is passed in by reference and it is filled with a waveform. But you did not provide any code illustrating how this waveform is sent to the hardware.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    II Support Forum Index -> X5-400M (GMT - 8 Hours)
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
You cannot attach files in this forum
You cannot download files in this forum

© Copyright 2006-2012 Innovative Integration
Powered by phpBB © 2001, 2002 phpBB Group
Based on iCGstation v1.0 Template By Ray © 2003, 2004 iOptional