| View previous topic :: View next topic |
| Author |
Message |
lutfi
Joined: 06 Jun 2011 Posts: 31 Location: Indonesia
|
Posted: Tue Jul 05, 2011 11:32 pm Post subject: How to generate a waveform from buffer |
|
|
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  |
|
| Back to top |
|
 |
jhenderson Site Admin
Joined: 07 Mar 2006 Posts: 2252 Location: So. Cal. USA
|
Posted: Wed Jul 06, 2011 2:19 pm Post subject: |
|
|
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 |
|
 |
lutfi
Joined: 06 Jun 2011 Posts: 31 Location: Indonesia
|
Posted: Fri Jul 08, 2011 1:09 am Post subject: |
|
|
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 |
|
 |
jhenderson Site Admin
Joined: 07 Mar 2006 Posts: 2252 Location: So. Cal. USA
|
Posted: Fri Jul 08, 2011 3:31 am Post subject: |
|
|
| 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 |
|
 |
lutfi
Joined: 06 Jun 2011 Posts: 31 Location: Indonesia
|
Posted: Sun Jul 10, 2011 6:40 pm Post subject: |
|
|
it crash at memcpy(&DG[0], LteBuffer, LteBufferLen);
buffer is variable I create in BuildWave function Innovative::Buffer buffer |
|
| Back to top |
|
 |
jhenderson Site Admin
Joined: 07 Mar 2006 Posts: 2252 Location: So. Cal. USA
|
Posted: Mon Jul 11, 2011 4:55 am Post subject: |
|
|
The fragment:
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 |
|
 |
bree
Joined: 11 Jul 2011 Posts: 7
|
Posted: Wed Jul 13, 2011 7:57 pm Post subject: Can't generate correct waveform |
|
|
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 |
|
 |
jhenderson Site Admin
Joined: 07 Mar 2006 Posts: 2252 Location: So. Cal. USA
|
Posted: Thu Jul 14, 2011 9:06 am Post subject: |
|
|
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 |
|
 |
|