Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include <windows.h>
#include <mmsystem.h>
#include <iostream>
#include <fstream>
#include "stdafx.h"

using namespace std;
int endWithError(char *msg,int error =0)
{
	cout<< msg << endl;
	while(cin.get() != 10)
	return error;
}
int _tmain(int argc, _TCHAR* argv[])
{
	
	FILE *fp= NULL;
	fp=fopen("test.wav","r");
	if(!fp)
	{
		endWithError("Error : File Not Open");
	}
	char type[4];
	DWORD size,chunkSize;
	short formatType, channels;
	DWORD sampleRate, avgBytesPerSec;
	short bytesPerSample, bitsPerSample;
	DWORD dataSize;

	fread(type, sizeof(char), 4, fp);
	if(!strcmp(type,"RIFF"))
	{
		return endWithError("Error : NOT RIFF EORMAT");
	}
	fread(&size, sizeof(DWORD), 1, fp);
	fread(type, sizeof(char), 4, fp);
	if(!strcmp(type,"WAVE"))
	{
		endWithError("Error : Not Wave Format");
	}
	fread(type, sizeof(char), 4,fp);
	if(!strcmp(type,"fmt"))
	{
		endWithError("Error : Not Fmt ");
	}
	fread(&chunkSize, sizeof(DWORD), 1, fp);
	fread(&formatType, sizeof(short), 1, fp);
	fread(&channels, sizeof(short), 1, fp);
	fread(&sampleRate, sizeof(DWORD), 1, fp);
	fread(&avgBytesPerSec, sizeof(DWORD), 1, fp);
	fread(&bytesPerSample, sizeof(short), 1, fp);
	fread(&bitsPerSample, sizeof(short), 1, fp);
	fread(type, sizeof(char), 4,fp);
	if(!strcmp(type,"data"))
	{
		endWithError("Error : Error Missing Data");
	}
	fread(&dataSize, sizeof(DWORD), 1, fp);
	cout << "chunk Size: " << chunkSize << endl;
	cout <<"Format Type: "<< formatType <<endl;
	cout <<"Channels: "<< channels <<endl;
	cout <<"Sample Rate: "<< sampleRate <<endl;
	cout <<"Average Bytes Per Sec: "<< avgBytesPerSec <<endl;
    cout <<"Bytes Per Sample: "<< bytesPerSample <<endl;
    cout <<"Bits Per Sample: "<< bitsPerSample <<endl;
    cout <<"Press Enter To End"<< endl;

	while(cin.get() != 10);

	return 0;
}
Posted
Updated 25-Aug-14 13:43pm
v2
Comments
[no name] 25-Aug-14 19:08pm    
This is a code dump not a question or description of a problem.
chaau 25-Aug-14 21:03pm    
This simple function sndPlaySound http://msdn.microsoft.com/en-us/library/aa909803.aspx will play your test.wav file

1 solution

As Andrew Cherednik wrote:
This simple function sndPlaySound() will play your test.wav file. A better link to it: Explanation in MSDN

Tip: use a full path and check that file is found.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900