|
Hi!
I have been trying for hours now to get a code snippet to work. It's just a simple little code that is supposed to write an audio stream in a newly created avi file. I've worked out writing bitmaps but this just won't work! I get no errors from AVIStreamSetFormat and no error from AVIStreamWrite() but when I listen to the resulting avi file I just hear random noise (this plus the fact that my code crashes when I try to write bigger chunks of data leads me to believe that AVIStreamWrite tried to write from memory I did not tell it to).
Here's my code:
#include <windows.h><br />
#include <iostream><br />
#include <vfw.h><br />
#pragma comment (lib,"Vfw32.lib")<br />
using namespace std;<br />
<br />
#define INPUT_WAVE L"C:\\cosmic.wav"<br />
#define OUTPUT_AVI L"C:\\testarN.avi"<br />
<br />
struct WAVE_HEADER<br />
{<br />
char ChunkID[4];<br />
int ChunkSize;<br />
char Format[4];<br />
char SubChunk1ID[4];<br />
int SubChunk1Size;<br />
short AudioFormat;<br />
short NumChannels;<br />
int SampleRate;<br />
int ByteRate;<br />
short BlockAlign;<br />
short BitsPerSample;<br />
int Subchunk2ID;<br />
int Subchunk2Size;<br />
};<br />
<br />
<br />
int main ()<br />
{<br />
DeleteFile(OUTPUT_AVI);<br />
DWORD meh;<br />
<br />
HANDLE fhandle;<br />
fhandle=CreateFile(INPUT_WAVE,GENERIC_READ,0,NULL,3,0,NULL);<br />
<br />
<br />
WAVE_HEADER wh;<br />
cout << sizeof(wh) << endl;<br />
ReadFile(fhandle,&wh,sizeof(wh),&meh,NULL);<br />
<br />
cout << wh.Subchunk2Size << endl;<br />
<br />
<br />
BYTE *audiodata = new BYTE[wh.Subchunk2Size];<br />
ReadFile(fhandle,audiodata,wh.Subchunk2Size,&meh,NULL);<br />
cout << meh << endl;<br />
<br />
<br />
<br />
<br />
PAVIFILE avifile;<br />
PAVISTREAM avistream;<br />
<br />
AVIFileInit();<br />
<br />
AVIFileOpen(&avifile,OUTPUT_AVI,OF_CREATE,NULL);<br />
<br />
WAVEFORMATEX wfx;<br />
memset(&wfx,0,sizeof(wfx));<br />
wfx.wFormatTag=wh.AudioFormat;<br />
wfx.nBlockAlign=wh.BlockAlign;<br />
wfx.nAvgBytesPerSec=wh.ByteRate;<br />
wfx.nChannels=wh.NumChannels;<br />
wfx.wBitsPerSample=wh.BitsPerSample;<br />
wfx.nSamplesPerSec=wh.SampleRate;<br />
<br />
AVISTREAMINFO asi;<br />
memset(&asi,0,sizeof(asi));<br />
asi.fccType=streamtypeAUDIO;<br />
asi.dwScale=wfx.nBlockAlign;<br />
asi.dwRate=wfx.nSamplesPerSec*wfx.nBlockAlign; <br />
asi.dwQuality=-1;<br />
<br />
<br />
AVIFileCreateStream(avifile,&avistream,&asi);<br />
cout << avistream << endl;<br />
<br />
<br />
cout << AVIStreamSetFormat(avistream,0,&wfx,sizeof(wfx)) << endl;<br />
<br />
cout << wh.Subchunk2Size/(wh.BitsPerSample/8)/wh.NumChannels << endl;<br />
cout << AVIStreamWrite(avistream,0,100*1000,<br />
&audiodata,100*1000*2,0,0,0) << endl;<br />
<br />
<br />
<br />
AVIStreamRelease(avistream);<br />
AVIFileRelease(avifile);<br />
AVIFileExit();<br />
<br />
delete [wh.Subchunk2Size]audiodata;<br />
<br />
CloseHandle(fhandle);<br />
<br />
return 0;<br />
}<br />
<br />
<br />
<br />
</vfw.h></iostream></windows.h>
I've used resources from the following places:
http://msdn.microsoft.com/en-us/library/ms712636(VS.85).aspx[^]
http://ccrma.stanford.edu/courses/422/projects/WaveFormat/[^]
http://www.adp-gmbh.ch/win/programming/avi/avi.html[^]
Hopefully someone can take the time to look over my code and give me some suggestions.
Thanks in advance!
|
|
|
|
|
Could someone help me / point me to where I can find a source code of this API?
No such thing in Google searches.
Thanks for reading
Vaclav
|
|
|
|
|
|
Also sorry, but I am not looking for applications of this API.
Unless I have missed it, in your search, all of these are just that - applications of capCreateCaptureWindow.
capCreateCaptureWindow "creates" preview of the AVI frame and I am assuming that it does it using bitmap. I like to see the actual source code for it.
Anyway, thanks for your help.
Vaclav
|
|
|
|
|
I get the following error upon program close - NOT while program is running, but when it shuts down:
'Notify.exe': Loaded 'C:\Windows\System32\rsaenh.dll'
First-chance exception at 0x01001df6 in Notify.exe: 0xC0000005: Access violation reading location 0xfeeefeee.
Unhandled exception at 0x01001df6 in Notify.exe: 0xC0000005: Access violation reading location 0xfeeefeee.
How do I find the error. Doesn't happen in Debug compilation l only in Release mode.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: I get the following error upon program close - NOT while program is running, but when it shuts down
Welcome in the CP's memorable quotes [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
More information is needed. How do you know it involves a CString if the application is third party? The rsaenh.dll is a Microsoft DLL which provides cryptographic functionality. The 0xfeeefeee value is heap memory that has been deleted.
Btw, you can attach the visual studio debugger to release builds.
How to: Debug a Release Build[^]
Best Wishes,
-David Delaune
|
|
|
|
|
I say CStringT because that is what is shown when I ask for debug info ie,
" ~CStringT
{
}
"
I'm already setup for release build debugging. But as I said I don't use CStringT I use only CString.
A C++ programming language novice, but striving to learn
|
|
|
|
|
In the main method of some code I'm re-factoring to Java there is this call in the main method, which i presume is seeding all the random numbers.
srand(0);
In my java interpretation of this code I have used the following call
app.randomiser.setSeed(0); //(randomiser = new Random());
The main problem is that as I posted earlier, I'm trying to do in-line what the following #define call in the C++ code does;
#define rand01 (0.9999999*double(rand())/RAND_MAX)
I know this produces random numbers between 0 and 1, which is then applied to a integer variable Ne (800) to produce a random value from 0 to 800 which is then floored to produce the integer value.
neurSwitch = randomiser.nextDouble(); // This is how I produce the random in Java
r = (int)(Math.floor(Ne*generateRandom())); //Random applied to the variable Ne in Java, getRandom returns the value of neurSwitch
The C++ code does this all in one line thanks to the #define statement
val = floor(N*rand01);
The two different implementations are producing massively different results, which is kinda an issue, as I'm trying to exactly reproduce the functionality from the C++ code.
My 2 questions are:
Does the seeding function work differently in Java and C++?
Is the Java reproduction of the #define rand01, doing the correct thing?
Many thanks
Give me strength, give me caffeine
|
|
|
|
|
Hi,
why would the built-in random function in Java behave the same as the built-in random function in
the one C++ implementation you have been using so far? There is an infinite number of random generators after all, so even starting from the same seed value, the sequence is unlikely to be the same. Have you ever compared random generators from different C++ systems?
If you need this to be identical, you have but two choices:
- call the original implementation, use Java Native Interface (JNI) to get it;
- copy the C++ implementation using your own Java code.
What I have done in the past is turn the random stuff into my own class, and in there choose between the built-in random generator (which is fast and good), and my own (which is portable, slower and
maybe good, and helps in comparing app results).
|
|
|
|
|
c#_keithy wrote: Does the seeding function work differently in Java and C++?
Are two random generators supposed to produce the same sequence?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Pallini,
Given a seed, two different random number generation algorithms will return different random values. Worse yet, all random number generators have the property have after a certain number of random numbers being generated, they repeat themselves. The length of this sequence is called the period.
Over the years, there has been a fair amount of theory on how to develop a good random number generator. I believe the one that comes with the Microsoft C++ compiler is a good one and it has a very long period. I do not know about the one that comes with the Java compiler except that it almost certainly uses a slightly different algorithm and therefore it will have a different period. If you need the same results on both C++ and Java, I strongly recommend that you implement your own random number generator.
Bob
|
|
|
|
|
BobInNJ wrote: Given a seed, two different random number generation algorithms will return different random values.
I know, that's fine.
BobInNJ wrote: Worse yet, all random number generators have the property have after a certain number of random numbers being generated, they repeat themselves.
I know, there's a reason they're called pseudo-random generators.
BobInNJ wrote: The length of this sequence is called the period.
Of course: repetaing patterns have a period.
BobInNJ wrote: Over the years, there has been a fair amount of theory on how to develop a good random number generator. I believe the one that comes with the Microsoft C++ compiler is a good one and it has a very long period. I do not know about the one that comes with the Java compiler except that it almost certainly uses a slightly different algorithm and therefore it will have a different period.
Why a slightly different algorithm should have a different period?
BobInNJ wrote: If you need the same results on both C++ and Java, I strongly recommend that you implement your own random number generator.
That's not a good suggestion. As you probably know, writing a good random generator is not a simple matter. It is better (as suggested by Luc Pattyn) to use some technique to exploit the same number generator code or simply adapt an existing one.
BTW: Bob, did you find a bit irony in my OP, didn't you?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
When I wrote:
write your own random number gennerator
I meant that your application should define one not that you need to come up with your own algorithm
for one. I guess I was not clear about that.
Bob
|
|
|
|
|
Hi Bob,
obviously a state-machine with a finite number of state bits will sooner or later repeat itself.
an N-bit random number generator has a maximum period equal to (2^N)-1 which basically tells you the
internal "counter" has one value that is not generated at all (typically zero).
|
|
|
|
|
Hi,
I am desperated: I want to send a WM_USER message to a CHtmlView but the message handler is never called
In my *.h file I have:
#define WM_HYLGETCONTENT WM_USER + 79
afx_msg LRESULT OnHylGetContent(WPARAM wParam, LPARAM lParam);
In my *cpp file I have:
BEGIN_MESSAGE_MAP(CHyperlexView, CHtmlView)
[...]
ON_MESSAGE(WM_HYLGETCONTENT, OnHylGetContent)
END_MESSAGE_MAP()
[...].
afx_msg LRESULT CHyperlexView::OnHylGetContent(WPARAM wParam, LPARAM lParam)
{
MessageBox("I get called!");
return 1111;
}
But the function is never called
I checked with Spy++: The message is sent successfully to the window but the LRESULT is 0 instead of 1111. The message does not appear too.
What could be the problem here?
I have also checked other values for WM_USER, I get the same result
Thank you,
Niki
|
|
|
|
|
You've probably hit a conflict with another existing message ID.
Use WM_APP instead of WM_USER , the latter is obsolete.
What you really should do is use a registered windows message.
Read more about message management here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
From where your sendmessage(...) has been called
|
|
|
|
|
hiz all,
i have an assignment to write a code in c++ using gui including the code of binary search tree to form a window with three buttons one for pre order and one for inorder and one for post order and when we click on any of these buttons it must show the order (like this site http://nova.umuc.edu/~jarc/idsv/lesson1.html[^])open this link and then click start exercise then u'll see a window...
this what i need to do in c++ ,a program that show such window by using c++...
i wrote the code but i have a problem in gui becuase i don't know anything about it in c++ i'm a beginner in programing and i need help in this code
i appreciate any help you can offer
|
|
|
|
|
first, review all you should have been studying in order to do this assignment.
second, ask question to your teacher, instructors about what you did not understand in "first"
third, write down ON PAPER, how the 3 searches should work, play a game with pen and paper.
fourth, start designing your program, define what data structure you will need, start defining algorithms
fifth, code what you design in "four"
sixth, run what you've coded in "five"
if it works, then, you've learn something.
if it does not work, go back to "first" and/or "second"
if it still does not work, ask a CLEAR, CONSISED and PRECISE question here; and I'm certain we will
be able to help.
|
|
|
|
|
Hi all,
I have IntelliSense:'No additional information available' problem in VC++2005 how can i resolve this.
Help me for this.
thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Do you have this problem on all projects or no and do you have open programs except VS?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
No
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Do you have latest Service pack installed? I found a similar thread[^] which says that its a bug in Visual Studio and the fix will be available in the latest service pack. So try installing the latest VS 2005 service pack from here[^], incase if you don't have it.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Close your project/solution and delete the NCB file associated with your project. Its a binary-tree containing the intelliSense data. Deleting it will force it to be rebuilt the next time you open the project. Hopefully that fixes your issue.
Best Wishes,
-David Delaune
|
|
|
|
|