Click here to Skip to main content
15,922,533 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to convert binary values into decimal by getting these values from dialog box? Pin
enhzflep29-Dec-08 20:48
enhzflep29-Dec-08 20:48 
GeneralRe: how to convert binary values into decimal by getting these values from dialog box? Pin
CPallini29-Dec-08 21:04
mveCPallini29-Dec-08 21:04 
Questionstd::map or stdex:hash_map Pin
Swinefeaster29-Dec-08 18:13
Swinefeaster29-Dec-08 18:13 
QuestionLinking to another project [SOLVED] Pin
Christian Flutcher29-Dec-08 17:17
Christian Flutcher29-Dec-08 17:17 
AnswerRe: Linking to another project [SOLVED] Pin
Cedric Moonen29-Dec-08 21:40
Cedric Moonen29-Dec-08 21:40 
GeneralRe: Linking to another project [SOLVED] Pin
Christian Flutcher30-Dec-08 1:12
Christian Flutcher30-Dec-08 1:12 
GeneralRe: Linking to another project [SOLVED] Pin
Cedric Moonen30-Dec-08 22:15
Cedric Moonen30-Dec-08 22:15 
QuestionNeed help with writing an audio stream in avi Pin
monoceres29-Dec-08 14:41
monoceres29-Dec-08 14:41 
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! Smile | :)
QuestioncapCreateCaptureWindow - source code wanted Pin
Vaclav_29-Dec-08 8:21
Vaclav_29-Dec-08 8:21 
AnswerRe: capCreateCaptureWindow - source code wanted Pin
Randor 29-Dec-08 8:52
professional Randor 29-Dec-08 8:52 
GeneralRe: capCreateCaptureWindow - source code wanted Pin
Vaclav_30-Dec-08 7:09
Vaclav_30-Dec-08 7:09 
QuestionHow to find an Access violation error(involving CStringT) in 3rd Party program Pin
Larry Mills Sr29-Dec-08 6:37
Larry Mills Sr29-Dec-08 6:37 
GeneralRe: How to find an Access violation error(involving CStringT) in 3rd Party program Pin
CPallini29-Dec-08 7:56
mveCPallini29-Dec-08 7:56 
GeneralRe: How to find an Access violation error(involving CStringT) in 3rd Party program Pin
Randor 29-Dec-08 9:02
professional Randor 29-Dec-08 9:02 
GeneralRe: How to find an Access violation error(involving CStringT) in 3rd Party program Pin
Larry Mills Sr29-Dec-08 11:35
Larry Mills Sr29-Dec-08 11:35 
QuestionRandom seeding in C++ different to Java? Pin
c#_keithy29-Dec-08 6:16
c#_keithy29-Dec-08 6:16 
GeneralRe: Random seeding in C++ different to Java? Pin
Luc Pattyn29-Dec-08 6:26
sitebuilderLuc Pattyn29-Dec-08 6:26 
QuestionRe: Random seeding in C++ different to Java? Pin
CPallini29-Dec-08 7:50
mveCPallini29-Dec-08 7:50 
AnswerRe: Random seeding in C++ different to Java? Pin
BobInNJ29-Dec-08 9:44
BobInNJ29-Dec-08 9:44 
GeneralRe: Random seeding in C++ different to Java? Pin
CPallini29-Dec-08 10:07
mveCPallini29-Dec-08 10:07 
GeneralRe: Random seeding in C++ different to Java? Pin
BobInNJ29-Dec-08 10:33
BobInNJ29-Dec-08 10:33 
GeneralRe: Random seeding in C++ different to Java? Pin
Luc Pattyn29-Dec-08 10:43
sitebuilderLuc Pattyn29-Dec-08 10:43 
QuestionWM_USER ignored by View window? (CHtmlView) Pin
nobaq29-Dec-08 1:43
nobaq29-Dec-08 1:43 
AnswerRe: WM_USER ignored by View window? (CHtmlView) Pin
Roger Stoltz29-Dec-08 2:24
Roger Stoltz29-Dec-08 2:24 
AnswerRe: WM_USER ignored by View window? (CHtmlView) Pin
KASR129-Dec-08 19:21
KASR129-Dec-08 19:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.