|
First of all thx for your reply and thx to the other 2 guys replies. All of you helped a lot.
New questions have arised due to replies:
#1: My knowledge of technical differences between 16-32-64 bits is little or none...but I'm definitely gonna need more than 640K lol. There's gotta be a way to bypass the 640K limit! I thought mallocating on C and "New-ing" on Pascal allowed use of extended memory...
Well, if it just can't be done, I can work it out by not exceeding the limit while I use the 486...resigning compatibility with it, it's ok, it wasn't that big deal...nor was Linux compatibility.
It seems I'm gonna need a 32-bit compiler (though I don't really know much what it means), perhaps this is what "BBC32" meaning was (32 bit). What compiler should I use given the new circumstances? Will it still run on the 486?
#2: The graphic issue seems problematic, seems I'll have to make a first version working on the 486 and then the release one. So, given the first one is ok, what would be the better choice for graphic mode compatibility between W98-Me-NT-2000-XP? I should add that there's no way Ima use MFC nor DirectX.
Thx in advance!!
Mariano Lopez-Gappa
|
|
|
|
|
i use thread to animate an opengl object on a dialog box, it use "for" to loop and make a animate,
if not using thread, i use UpdateData(FALSE) and is see animation is moving,
BUT if i use thread i did see the movement, it see if i press button and other activity, any body help me ... plz...
|
|
|
|
|
Please state the question more clearly, possibly post some code.
John
|
|
|
|
|
try to use 'windows messages' to interact with dialogs. a good idea is to use WM_TIMER / SetTimer ...
karo
|
|
|
|
|
Hello,
I'm interested in writing a program that reads an XML input file, and then based on the content of that file, writes another program which is then compiled. I imagine that I'd do this by defining an ofstream and literally writing the new prorgram line by line. The "preprocessing" program would look something like this:
ofstream out("program.cpp");
out << "int main()" << endl;
out << "{" << endl;
out << "return 0;" << endl;
out << "}" << endl;
Where I'd have to write the relevant functions for my problem. I'd then run the proprocessing program and compile the "new" program using a batch file.
My question is this: Is there a name for this type of programming? I'd like to read up about it in general before I dive in but the searches I have done haven't revealed much. Also, does MS VC++ provide any helpful methods for writing such programs?
Thanks,
--Jordan Atlas
|
|
|
|
|
Its called code generation and its a pretty complex topic. Lots of high end programming tools do this. Rational Rose for example can generate code from UML models.
You could look at using Lex.
You could create an object model to represent the C++ entities (classes, function, variables etc etc). A program would be represented by a tree like structure of these objects. Each of these classes could construct itself from the xml and then write iteself to the stream. You could take it a step further and make this object model non language specific then apply formatting objects for the language you want (C++, c#, Java) this would mean however that your xml representation would be limited to features common to these languages.
|
|
|
|
|
Hello,
Is the XML file a something you can change? I mean, if you can influence the data in the XML file, it may be better to stick to scripts. You'll avoid mass complexity of generating C++ code.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi,
Thanks for the replies.
The XML file is a representation of a model (variables and equations). The program that I'm trying to have it automatically write will solve the system of equations represented in the XML file. I'm trying to do this so that the (compiled) new simulation program will be faster than if I repeatedly sampled information in the XML file...
--Jordan
|
|
|
|
|
So you are doing this for performance reasons. Than scripts are probably too slow for you too.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi,
I have a project which i am unable to do myself.It is not a very long project but because of the time constraint,I would like it to be completed at most by the 7th of November.
The specifications of the project are as follows:
I actually am developing a hearing aid and now the problem is in real time implementation of it.
1. I have to capture speech coming in through "mic in" port of the computer.
2. The captured speech would pass through a module(consisting of filters and Fourier transforms)..which i have written below.
3. The output through my module has to be played back out through the "mic out" port of the computer.
Code is :
#include <stdio.h>
#include <math.h>
#include <string.h>
double wdata[13]; //required for the FFT
double datafft[8192]; //length required is twice the inverse FFT
double x[295000]; //input data vector,maximum,length
int expo = 12; //required for the FFT
int main ()
{
double pi,ex,temp,theta1,coefa,coefb,G;
double X2,W1,bf,phikb,phia,phib;
double phi[1260],XR[4096],XI[4096],X[4096],XM[4096];
double w[512]; // vector of hamming window values
double ret[4096]; // vector of the inverse FFT returned data
double x1[512],x2[512],f[512];
double G1;
int a,i,j,k,m,n,FL,NW,L,l,q1,q2,kb,ks,ke;
double sr = 25000.0; // sampling rate
int CF = 15; // compression factor,CF:1
int hfru = 10500; // high frequency range upper limit
int hfrl = 4400; // high frequency range lower limit
int N = 2048; // number of frequency samples,top half
int ND = 512; // length of input data
int M = 4096; // length of inverse FFT
FILE *fp;
fp = fopen("ELPHRG01.WAV","r+b");
i = 0;
*/
while((fscanf(fp,"%f/n",&x[i++])) != EOF);
fclose(fp);
FL = i;
pi = 4.0 * atan(1.0);
ex = exp(1.0);
NW = 512;
W1 = 0.5;
l = 0;
L = 1;
for (n=0; n < NW; n++) {
theta1 = (2 * pi * n) / (NW - 1);
w[n] = W1 - (W1 * cos(theta1));
}
for (n = 0; n < NW; n++) {
x2[n] = 0.0;
}
bf = sr / (2 * CF); // break frequency
phikb = (pi * bf) / (sr / 2); // angle of break frequency
kb = N / CF; // number of samples from DC to break
phia = (hfrl / (sr /2 )) * pi; // high frequency region starting angle
phib = (hfru / (sr /2 )) *pi; // high frequency region ending angle
coefa = 0.00799;
coefb = -0.3722072;
//1. Obtain a windowed Segment of the input data
for (a = 1; a < 2 * FL / NW + 1; a++) {
for (m = 0, n = 1; m < NW; m++, n++) {
f[m] = w[m] * x[n];
}
}
//2. Obtain Nonlinearly Compressed and Transpossed frequency samples
for (k = 0; k < 150; k++) {
temp = coefa * k;
phi[k] = pow(ex, temp) + coefb;
G = pow(ex, temp);
G1 = G * sqrt(G) + 6;
XR[k] = 0.0;
XI[k] = 0.0;
for (n = 0; n < ND; n++) {
XR[k] = XR[k] + f[n] * cos(phi[k] * n);
XI[k] = XI[k] + f[n] * sin(phi[k]*n);
}
XR[k] = G1 * XR[k];
XI[k] = G1 * XI[k];
}
//3. Pad zeros in the center of the Spectrum
for (k = 150; k < M - 150; k++) {
XR[k] = 0.0;
XI[k] = 0.0;
}
//4. Form the Complex conjugate part of the spectrum
for (k = M - 150 + 1; k < M + 1; k++) {
XR[k] = XR[M-k];
XI[k] = -XI[M-k];
}
//5. Convert from Polar to rectangular for the inverse FT
for (i = 0; i < M; i++) {
j = 2 * i;
k = j + 1;
datafft[j] = XR[i];
datafft[k] = XI[i];
}
//6. Call the FFT
f_init(); //I need to implement this FFT function in C++ rather than Foxpro
MAIN_();
//7. Obtain the inverse FFT from the FFT call
ret[0] = datafft[0] / M;
for (i = 2244; i < 2756; i++) {
j = 2 * i;
k = 2 *M - j;
ret[i+1] = datafft[k] / M;
}
for (k = 0; k < 512; k++) {
ret[k] = ret[k+2244];
}
// Multiply by the hamming
q1 = a / 2;
q2 = q1 * 2;
if (q2 == a) {
for (i = 0; i < 256; i++) {
X2 = ret[i] * w[i] + x1[i + 256];
printf("%f\n",X2);
}
for (i = 256; i < 512; i++) {
x2[i] = ret[i] * w[i];
}
} else {
for (i = 0; i < 256; i++) {
X2 = ret[i] * w[i] + x2[i + 256];
printf("%f\n",X2);
}
for (i = 256; i < 512; i++) {
x1[i] = ret[i] * w[i];
}
}
l = (NW * L / 2);
L = L+1;
return 0;
}
MAIN_()
{ //This is again using Fox Pro but i am not sure
fft2c_(datafft,&expo,wdata);
return 0;
}
So,in all i just need code development in C++ to capture speech and play it back and a slight modification in my module to make it compatible.
If somebody can please help me out,I am even willing to pay for the project.
Thanks,
Student
-- modified at 21:21 Monday 24th October, 2005
|
|
|
|
|
There is a ton of source code online for fourier transforms, it's a common problem, and one that is well documented.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ya, but could you help me out in implementing the code which I have written in real time ?
|
|
|
|
|
Real time ? I doubt it. I'm sure I could do it, but not in the timeframe that I could give to helping someone on a forum, sorry. You'd do better to look for a solution than hope for someone to dedicate time to writing this for you specifically.
If you're calling functions in Foxpro somehow, you'll definately gain speed from moving to C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I pulled the following lines from my C program, which captures video and audio, and saves it to a file.
I have an array of video and audio buffers, each 33.3 mSec (NTSC) or 40 mSec (PAL), and I capture to these in turn, wrapping round to the first when I finish the last buffer. When the user stops capture, the buffers can be stored as an AVI file with sound.
I have NOT done any audio output stuff, so I cannot give sample code there!
Use the code given below as hints - I found all of this on the MSDN CDs that came with Visual Studio 6. I have left out most of the error detection code.
uiNumWaveInDevices = waveInGetNumDevs();<br />
<br />
waveInGetDevCaps(0, &WaveInCaps, sizeof(WaveInCaps));
<br />
if (!(WaveInCaps.dwFormats & WAVE_FORMAT_1M16))<br />
<br />
AudioFormat.wFormatTag = WAVE_FORMAT_PCM;<br />
AudioFormat.nChannels = 1;
AudioFormat.nSamplesPerSec = 11025;
AudioFormat.nBlockAlign = 2;
AudioFormat.wBitsPerSample = 16;
AudioFormat.nAvgBytesPerSec = 11025 * 2;
AudioFormat.cbSize = 0;
<br />
hAudioInDevice = NULL;<br />
<br />
uiReturn = waveInOpen(&hAudioInDevice, 0, &AudioFormat, 0, 0, CALLBACK_NULL);<br />
if (uiReturn != MMSYSERR_NOERROR)<br />
<br />
uiAudioBufferMaxSize = AudioFormat.nSamplesPerSec * AudioFormat.nBlockAlign * AudioFormat.nChannels / 25;<br />
<br />
AudioHeader[uiCounter].lpData = GlobalLock(GlobalAlloc(GMEM_FIXED, uiAudioBufferMaxSize));<br />
<br />
for(uiCounter = 1; uiCounter<uiMaxNumOfFrames; uiCounter++)<br />
pAudioDataBlock[uiCounter] = pAudioDataBlock[0] + uiCounter * uiAudioBufferMaxSize;<br />
<br />
uiAudioBufferActualSize = uiAudioBufferMaxSize;<br />
for(uiCounter = 0; uiCounter<DEF_NumberAudioDeviceBuffers; uiCounter++)<br />
{<br />
AudioHeader[uiCounter].dwBufferLength = uiAudioBufferActualSize;<br />
AudioHeader[uiCounter].dwBytesRecorded = 0;<br />
AudioHeader[uiCounter].dwUser = 0;<br />
AudioHeader[uiCounter].dwFlags = 0;<br />
AudioHeader[uiCounter].dwLoops = 0;<br />
uiResult = waveInPrepareHeader(hAudioInDevice, &(AudioHeader[uiCounter]), sizeof(WAVEHDR));<br />
}<br />
<br />
<br />
for (i = 1 to 5)<br />
waveInAddBuffer(hAudioInDevice, &(AudioHeader[uiNextIndexToQueue]), sizeof(WAVEHDR))<br />
<br />
if (bThisIsFirstBuffer)<br />
waveInStart(hAudioInDevice);<br />
<br />
<br />
while (!(AudioHeader[uiAudioNextIndexToProcess].dwFlags & WHDR_DONE))<br />
;<br />
<br />
<br />
memcpy(pAudioDataBlock[uiNextIndexToProcess], AudioHeader[uiAudioNextIndexToProcess].lpData, uiAudioBufferActualSize);<br />
<br />
waveInAddBuffer(hAudioInDevice, &(AudioHeader[uiAudioNextIndexToQueue]), sizeof(WAVEHDR))<br />
<br />
<br />
waveInStop(hAudioInDevice);<br />
<br />
for(uiCounter = 0; uiCounter<DEF_NumberAudioDeviceBuffers; uiCounter++)<br />
{<br />
while (!(AudioHeader[uiCounter ].dwFlags & WHDR_DONE))<br />
;<br />
waveInUnprepareHeader(hAudioInDevice, &(AudioHeader[uiCounter]), sizeof(WAVEHDR)))<br />
GlobalFree(GlobalHandle(AudioHeader[uiCounter].lpData));<br />
}<br />
<br />
GlobalFree(GlobalHandle(pAudioDataBlock[0]));<br />
<br />
GlobalFree(GlobalHandle(pAudioDataBlock));<br />
<br />
waveInClose(hAudioInDevice);
|
|
|
|
|
I have a thread in high priority, which runs at certain peorid. it collect data and send to another thread which is responsible for display.
My question is what is a good way to impliment this. I know I can't use SendMessage() from HighPriorityThread, coz it blocks. if use PostMessage() to pass pointer and length, then the buffer could be overwriten by HighPriorityThread() before LowPriorityThread read the buffer.
May be a buffer with criticalSection control may solve the problem. but Could you give me other inspiration? I think MicroSoft should forsee this kind application.
Thanks
|
|
|
|
|
xianwuluo wrote: if use PostMessage() to pass pointer and length, then the buffer could be overwriten by HighPriorityThread() before LowPriorityThread read the buffer.
Just about there. Use new to allocate a new buffer every time, then delete it in the low priority thread after it has been read.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
This is a definitely a simple way, I should have think of it. Thank you.
|
|
|
|
|
I would use criticalSections and Events.
I've used a circular que before to accomplish this. Each slot consisted of a buffer, allocated to a fixed size at start up (no more allocating required, unless user requested change at runtime). The lower priority thread checks for an event that says there is data in que (that can be read from the current head position). While the prioity thread can still be writing to the tail positon in the que (two seperate critical sections).
Basicaly, I automaticaly try to avoid thrashing memory by constantly allocating and deallocating memory. It slows things down and increases the chance that the a memory exception will occur. So if you can set a side memory for the sole purpose of communicating between your threads, you can avoid unexpected errors.
INTP
Every thing is relative...
|
|
|
|
|
Yes, I had thought this approach. Seems it's better than new and delete. I hate use new, coz u have to remember to delete it. u have to concern about memory leak or something. thank u.
|
|
|
|
|
I am trying to create and set evnets using Win32 API functions CreateEvent, SetEvent and OpenEvent.
Everything works fine if both projects are in the same language and environment (Visual C++) but when I try to create the event in a C++ application and set the event in a different application (VS.NET C#), the event does not exist.
Here is the code for both (c++ and c#):
C++
-----------------------------------------------------------------------------
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
// Get the handler to the event for which we need to wait in
// this thread.
HANDLE hEvent = CreateEvent ( EVENT_ALL_ACCESS, false, alse, "theEvent" );
cout<
|
|
|
|
|
Events are used within an application.
Use Mutexes.
CreateMutex(...)<br />
OpenMutex(...)<br />
ReleaseMutex(...)
this is this.
|
|
|
|
|
|
I have been too much lately.
I was confusing this with the Critical-section stuff.
Thanks for the correction.
this is this.
|
|
|
|
|
suezzz00 wrote: I suspect that the event that is created is not an OS event , but rather local to the running application.
No they are not. See my reply to khan++.
Your SetEvent PInvoke signature is wrong. You can use http://pinvoke.net[^] to get P/Invoke signatures for Win32 API functions.
The following code works fine for me.
C++
HANDLE h = CreateEvent(NULL, FALSE, FALSE, "TestEvent");
WaitForSingleObject(h, 5000);
cout << "past event";
C#
[DllImport("kernel32.dll")]
static extern bool SetEvent(IntPtr hEvent);
[DllImport("Kernel32.dll", SetLastError=true)]
static extern IntPtr OpenEvent(uint dwDesiredAccess, bool bInheritHandle, string lpName);
IntPtr handle = OpenEvent(0x000F0000 | 0x00100000 | 0x3, false, "TestEvent");
SetEvent(handle);
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi,
In my win32 app, I want to draw a line as the user moves the mouse (just as you wud do in paint).
how do I do this. I tried SetPixel(), but it's like drawing dotted line rather than a full line.
I want to use LineTo(), but each time do I have to store the previous mouse point into a global variable as the starting point for lineto().
Is there any other easier way to do this.
Thanks.
|
|
|
|
|