|
Hi,
I need to develop an application that records sound amplitude and plot in on a graph with a function of time, using a microphone. Is the best approach to do this using DirectSound. If so is there any sample code that is available for this, or some kind of tutorial.
Thanks in Advance.
|
|
|
|
|
Either DirectSound or the Windows Multimedia APIs will work. If you choose DirectSound then download the latest
DirectSound SDK and you'll find sample apps to get you started, along with documentation. The "CaptureSound Sample"
is a good start
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have an application where everything is written in serial fashion, one after the other and this included computation and updating certain displays within the main application. All these secondary displays are the child windows of the main application. This is a closed loop system where I need to update the displays in each iteration. While updating these displays takes 80% of the total time for each iteration, we want to increase the speed of the closed loop. So, I created different thread for updating displays while the computation loop works on it own and sets the flag for the display datasets when they r ready. My threads are defined in main application dialog file.
Here comes the problem, inorder to update the displays I am calling a method of the corresponding dialog box, which inturn calls the OnPaint() function of that dialog. This is where the program crashes with Abort Assertion Failed error.
Any ideas??
-Pavan.
Pavan
|
|
|
|
|
At first glance, this sounds like a bad design, destined for failure. How many dialogs and threads are we talking about here? Are the threads directly updating a UI component that does not belong to them?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yes, its not a good design at all, but its been written long time back at the time when I am not here. The application is a common dialog box design with 9 child dialog boxes in it. I have defined a separate thread in the main dialog box(where all the child dialog boxes are defined). There is only one thread that is defined additionally where atleast 4 dialog boxes are being refreshed by calling the methods one after the other already defined in them which inturn calls OnPaint() function of the corresponding dialog box. So we are looking at updating 4 dialog boxes from that thread. This thread is created whenever user starts closeloop and they are terminated when he stops closeloop.
Pavan
|
|
|
|
|
Pavan Berkeley wrote: So we are looking at updating 4 dialog boxes from that thread.
By posting or sending a message?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi all. I made a simple function that acts off of whether there's a certain string placed in a buffer.
<br />
string match1;<br />
string match2="virtualspace";<br />
<br />
if(client.find("matchup") != string::npos){<br />
if(client.find(word) != string::npos){<br />
if(match1 == match2){<br />
cout << "Found a match";<br />
}<br />
else{<br />
cout << "No match";<br />
}<br />
So once the first function is called and the buffer is filled it works fine. Then .clear() to empty the buffer works fine too. But when i try to fill the same buffer with the same characters from before it doesnt work. So i figured, maybe theres something left over in the buffer. So i tried to clear the buffer several times with .erase() and .clear() and i even did something like this.
string var="";
buffer << var;
Again it cleared the buffer (i think) but didnt allow me to put anything back in it.
My question is, once you wipe a buffer is there no way to re-fill it with the same data from before? And if you can, how? I've searched far and wide for an explanation. I've never dealt with something like this so i have no clue as to what i should be doing. Any suggestions? Thanx in advance!
|
|
|
|
|
void yourecrazy()
{
string str = "you are crazy";
cout << str.c_str() << endl;
str.clear();
cout << str.c_str() << endl;
str = "you are crazy";
cout << str.c_str() << endl;
}
|
|
|
|
|
.clear() doesnt work with VC++ 6
<br />
string password="logmein";<br />
stringstream loginsys;<br />
string loggedin;<br />
string loggedin2="Loggedin";<br />
<br />
bool loginsystem(const string& login){ <br />
if(buff.find(password) != string::npos){<br />
loginsys << "Loggedin";<br />
loggedin=loginsys.str();<br />
cout << "Logged in " << endl;<br />
return true;<br />
}<br />
else{<br />
cout << "Cannot log you in " << endl;<br />
return false;<br />
}<br />
}<br />
<br />
void logout(void){<br />
loggedin.erase();<br />
loggedin2.erase();<br />
cout << "Your now logged out. " << endl;<br />
}<br />
<br />
if(buff.find(".hi") != string::npos){<br />
if(buff.find(host) != string::npos){<br />
if(loggedin == loggedin2){<br />
cout << "Hello " << endl;<br />
}<br />
}<br />
}<br />
Even once loggedin and loggedin2 string buffers are emptied, i cant seem to find out how to fill it again with "Loggedin" so that the bottom function can check to see if the characters are in the buffer.
|
|
|
|
|
dellthinker wrote: i cant seem to find out how to fill it agai
Where are you trying to assign loggedin and loggedin2 new values?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Where are you trying to assign loggedin and loggedin2 new values?
<br />
void logout(void){<br />
string empty="";<br />
string empty2="";<br />
loggedin=empty;<br />
loggedin2=empty;<br />
cout << "Your now logged out. " << endl;<br />
}<br />
This method clears the buffers, because the client doesnt respond when i type a command because it checks to see if those particular buffers have "Loggedin" inside. The problem is when i login again and it "re-fills" the buffer with the words "Loggedin" it doesnt respond .
|
|
|
|
|
I must admit that I'm a bit confused as to what the problem is. Assigning (empty) values to string variables is not going to cause your program to not respond.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i have a window console application used to generate signal ouput from a board. When i try to write this into a MFC dialog, using the same code(i mean a specific part), a warning occurs.
The signal generator board comes with its own .h file and library that includes driver functions.
in one .h file, following types are defined:
# define int16 short int
# define int32 long int
# define ptr8 char*
in the library, following driver function prototype is defined;
HEAD SpcSetParam (int16 nNr, int32 lReg, int32 lValue);
in my header file; i declared 2 char pointers:
ptr8 pbyData[2];
in my cpp, i allocated 2 char array;
for (i=0; i<2; i++)
pbyData = (ptr8) GlobalAlloc (GMEM_FIXED,1024);
then i write data to the array,and need to pass the address of this two array to the driver function.
Using the function provided:
for (i=0; i<2; i++){
nErr = SpcSetParam (hDrv, SPC_FIFO_BUFADR0+i, (int32) pbyData); <---------warning occurs here
ignore the nErr and hDrv, SPC_FIFO_BUFADR0+i is the value for specific register, and (int32) pbyData i think is the address of the the array
the code works fine in console application, no warnings, however, using the same code in a MFC dialog, following error generated:
warning C4311: 'type cast' : pointer truncation from 'char *' to 'long'
could anybody tell me whats going on and how to fix it??
Thanks
g, following error generated:
warning C4311: 'type cast' : pointer truncation from 'char *' to 'long'
could anybody tell me whats going on and how to fix it??
Thanks
|
|
|
|
|
It looks like a 64-bit warning - In a 64-bit build, converting a pointer to a long will chop 32 bits off the pointer.
You can disable the 64-bit portability warnings in the compiler options or use #pragma warning(disable: 4311).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Pointers are unsigned values, you're casting a pointer to a (signed) int. Mark is also right about the code not being 64-bit safe.
|
|
|
|
|
i have 2 char pointers, and this 2 char pointer store and the address of two array i globally allocated. and the address should be 32bit, right? i don't anything wrong with casting int32
|
|
|
|
|
As Michael mentioned, try using an unsigned int -
#define uint32 unsigned long
...
If you want your code to be 64-bit ready, you can use LONG_PTR instead of long int. A LONG_PTR will always
be large enough to hold a pointer regardless of platform.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi, I am implementing an OpenGL program that redraws the view while mouse drag. Also, the cursor will change to my custom cursors according to which mouse button is pressed. However, during the drag, the custom cursor blinks non-stoply while the OpenGL view is redrawing. I have already used a flag to block the message so that it won't call SetCursor frequently along the mousemove, Here is some of my code:
BOOL COpenGLView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
static CameraMode mode = m_cameraMode;
if (mode == m_cameraMode) return FALSE;
mode = m_cameraMode;
switch (m_cameraMode)
{
case CAMERA_IDLE: SetCursor(LoadCursor(NULL, IDC_ARROW)); break;
case CAMERA_ORBIT: SetCursor(m_hCurOrbit); break;
case CAMERA_PAN: SetCursor(m_hCurPan); break;
case CAMERA_ZOOM: SetCursor(m_hCurZoom); break;
}
return TRUE;
}
void COpenGLView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
switch (nFlags)
{
case MK_LBUTTON: m_cameraMode = CAMERA_ORBIT; break;
case MK_RBUTTON: m_cameraMode = CAMERA_PAN; break;
case MK_MBUTTON: m_cameraMode = CAMERA_ZOOM; break;
default: m_cameraMode = CAMERA_IDLE; break;
}
Redraw();
}
What have I done wrong? Why the cursor cannot stop blinking? Would someone tell me what should I do? Many thanks.
|
|
|
|
|
I have no clue about OpenGL, but why are you calling Redraw() in OnMouseMove() ?
Given my limited knowledge I would expect a blinking cursor if you call Redraw() everytime the mouse moves.
|
|
|
|
|
Thanks for your reply. Actually Redraw() is my custom function to render the scene/view by OpenGL as the mouse is drag moving (like those mouse action in Maya).
|
|
|
|
|
There are two cursor situations that could apply to an OpenGL window:
1.
What you are doing - using windows to paint the cursor.
In this case you do not need to repaint the window on a mouse move.
There are so many reasons why there might be flickering that it may not be related to SetCursor().
As a start, instead of calling Redraw() try InvalidateRect().
Also, i would not block any messages to SetCursor() or you will get cases where the wrong cursor is showing (or none at all).
2.
Paint the cursor in OpenGL.
In this case you do need to repaint the window on a mouse move.
Because you would be painting everything any flickering would (likely) be due to either low frame rate or poorly created/setup window.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Thanks for your reply.
1. Actually Redraw() is my function to render the OpenGL view when the user mouse drag the view. I do call InvalidateRect() inside Redraw().
2. This suggestion is so valuable to me. I would go this way. Thanks so much.
|
|
|
|
|
Hi all,
i want to create an XML file with root node RTCS having value remote.
Then i want to create child node of this named Connection:
which has elements:
1. Connect ,value:connect_val
2. Port,value:port_number.
actually i am able to create xml file but it is having root node and its value only:
like this:
<rtcs xmlns="Remote Target Control System">
but i am not able the attach child node Connection to this root.
Any help is highly appreciated.
Regards
|
|
|
|
|
please review the guidelines regarding posting questions with embedded HTML/XML before asking this question again (basically you need to mark the relevant section as code or mark the whole message as 'ignore HTML tags in this message') example code of exactly how you are creating the child nodes might help. Oh and given that XML is a flat text self describing format when writing XML from C++/MFC I tend to write it as just that a flat text format using CreateFile() / WriteFile() / CloseHandle().
|
|
|
|
|
Hi there,
I have noticed when I debug a win32 C++ application, often I see a lot of .dll are loaded some which are required some which are not. One of the dlls loaded tend to crash my application, such as nl_lsp.dll from NetLimiter. Well, I need to use netlimiter from time to time, but the library was neither use nor included in my code, so how's that possible in the first place?
Can anyone shed some light regarding what happens at runtime when you debug an application using Visual Studio? Is this a VS problem or just my computer. Is there a way to exclude or prevent the dll from loading into my application. Thanks.
I'm using Windows XP Professional with SP2, VS2005 MDE with SP1
|
|
|
|