binary files, sound, waveformat

Started by
2 comments, last by mbalex 20 years, 5 months ago
Hello, (Introduction.. ^^) I just started programming in C++, i got as far that I could implement a RegEx Cpp Wrapper around pcre. (I was a former perl-only guru). I''m just working with Mingw, for I dont want to spend all my money for Visual C++. I was starting to program small stuff with OpenGL/GLUT and everything worked fine. Then I wanted to add some Sound stuff with OpenAL. ("problem1..") Some Testprograms I found on the Internet worked just fine but as soon as i wanted to implement my own stuff i got linker errors (the Alut and OpenAL lib were reimped). the funny thing is that suddenly alut doesn''t seem to find some functions in openal but in the test program it worked. that doesn''t matter, because i dont need the alut functions at all. (only the alutLoadWAVFile would have been helpfull) (problem2..) now i wanted to implement my own alutloadwavefile, but suddenly i realised that i had NO idea about opening, parsing binary files... and getting a wavefile from it, forget it. the look into the alutloadwavefile function (openal cvs source) didn''t helped at all. is there any tutorial about loading binary files? And how Wave works? (got some file format specs, but what does DWORD mean? i dont even get the first lines of these specs) (problem3..) now, since wave files are pretty BIG i wanted to implement a free sound format.. and i found ogg. i just looked into the docs and now i know i need help. anyone got an easy ogg/vorbis tutorial? bye Alex PS: no fmod pls.. wont learn anything from it (since it does everything already for me)
Advertisement
problem1: sounds like your not linking in the right libraries, check the makefiles for the example programs.

problem2: check wotsit wotsit.org for file format specs.
open a file (for reading) in binary mode: FILE *fin=fopen("bin.wav","rb"); use fread to read data.
you will want to get a copy of windows.h if your working with wav files. this will tell you what all those microsoft specific types are. (get it with mingw). DWORD is defined as unsigned long. its supposed to stand for double-word, i think.

problem3:ogg will be dificult to understand, try some simpler formats from sun etc..

[edited by - aboeing on November 18, 2003 10:52:49 AM]
problem1:
im using exacly the same .dev file as the example file. (actually I'm just renaming the example file and renamning my own source file). The example file just links, mine doesnt. (Both create their .o files... but only the example create the exe which works...)

here's the source (since it's the only difference).

EXAMPLE FILE:
#include <stdlib.h>#include <conio.h>#include <al/al.h>#include <al/alc.h>#include <al/alut.h>#include <vector>using namespace std;#define NUM_BUFFERS 1ALuint Buffers[NUM_BUFFERS];vector<ALuint> Sources;ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };ALboolean InitOpenAL(){    ALCdevice* pDevice;    ALCcontext* pContext;    ALCubyte* defaultDevice;    pDevice = alcOpenDevice((ALCubyte*)"DirectSound3D");    pContext = alcCreateContext(pDevice, NULL);    alcMakeContextCurrent(pContext);    if(alcGetError(pDevice) != ALC_NO_ERROR)        return AL_FALSE;            alGetError();    return AL_TRUE;}void ExitOpenAL(){    ALCcontext* pCurContext;    ALCdevice* pCurDevice;    pCurContext = alcGetCurrentContext();    pCurDevice = alcGetContextsDevice(pCurContext);    alcMakeContextCurrent(NULL);    alcDestroyContext(pCurContext);    alcCloseDevice(pCurDevice);}ALboolean LoadALData(){	ALenum format;	ALsizei size;	ALvoid* data;	ALsizei freq;	ALboolean loop;	alGenBuffers(NUM_BUFFERS, Buffers);	if(alGetError() != AL_NO_ERROR)		return AL_FALSE;	alutLoadWAVFile("test.wav", &format, &data, &size, &freq, &loop);	alBufferData(Buffers[0], format, data, size, freq);	alutUnloadWAV(format, data, size, freq);	if(alGetError() != AL_NO_ERROR)		return AL_FALSE;	return AL_TRUE;}void AddSource(ALint type){	ALuint Source;	alGenSources(1, &Source);	if(alGetError() != AL_NO_ERROR)	{		printf("Error generating audio source.");		exit(-1);	}	alSourcei (Source, AL_BUFFER,   Buffers[type]);	alSourcef (Source, AL_PITCH,    1.0f         );	alSourcef (Source, AL_GAIN,     1.0f         );	alSourcefv(Source, AL_POSITION, SourcePos    );	alSourcefv(Source, AL_VELOCITY, SourceVel    );	alSourcei (Source, AL_LOOPING,  AL_TRUE      );	alSourcePlay(Source);	Sources.push_back(Source);}void SetListenerValues(){	alListenerfv(AL_POSITION,    ListenerPos);	alListenerfv(AL_VELOCITY,    ListenerVel);	alListenerfv(AL_ORIENTATION, ListenerOri);}void KillALData(){	for(vector<ALuint>::iterator iter = Sources.begin(); iter != Sources.end(); iter++)		alDeleteSources(1, &(*iter));	Sources.clear();	alDeleteBuffers(NUM_BUFFERS, Buffers);	ExitOpenAL();}int main(int argc, char *argv[]){	if(InitOpenAL() == AL_FALSE)	{		printf("Could not initialize.");		getche();		return 0;	}        	printf("MindCode's OpenAL Lesson 5: Sources Sharing Buffers\n\n");	printf("Controls:\n");	printf("p) Play test.wav.\n");	printf("c) Change listener Vel.\n");	printf("q) Quit program.\n");	if(LoadALData() == AL_FALSE)		return 0;	SetListenerValues();	atexit(KillALData);	// Loop.	ALubyte c = ' ';	while(c != 'q')	{		c = getche();		switch(c)		{			case 'p': AddSource(0); break;			case 'c':				ListenerVel[0] = 100.0;				ListenerVel[1] = 100.0;				ListenerVel[2] = 100.0;				alListenerfv(AL_VELOCITY, ListenerVel);				break;		};	}	return 0;}


My Source:
#include <stdlib.h>#include <stdio.h>#include <al/al.h>#include <al/alc.h>#include <al/alut.h>#include <vector>#include <string>#define DEFAULT_DEVICE "DirectSound3D"class ZSound {private:	ALCdevice* pDevice;	ALCcontext* pContext;	std::vector<ALuint> vBuffers;	std::vector<ALuint> vSources;	ALfloat ListPos[3];	ALfloat ListVel[3];	ALfloat ListOri[6];public:	ZSound();	~ZSound();	void ListenerPos( float pos[3] );	void ListenerVel( float vel[3] );	void ListenerOri( float ori[6] );	int AddBuffer( std::string& );	int AddSource();};ZSound::ZSound(){    this->pDevice = alcOpenDevice((ALCubyte*)DEFAULT_DEVICE);	//(ALCubyte*)DEFAULT_DEVICE    this->pContext = alcCreateContext(this->pDevice, NULL);    alcMakeContextCurrent(this->pContext);    if(alcGetError(this->pDevice) != ALC_NO_ERROR)        throw AL_FALSE;    alGetError();}ZSound::~ZSound(){	//delete all sources/buffers    alcDestroyContext(this->pContext);    alcCloseDevice(this->pDevice);}void ZSound::ListenerPos( float pos[3] ){	alListenerfv(AL_POSITION,pos);}void ZSound::ListenerVel( float vel[3] ){	alListenerfv(AL_VELOCITY,vel);}void ZSound::ListenerOri( float ori[6] ){	alListenerfv(AL_ORIENTATION,ori);/*	vec[0] = fvecx; //forward vector x value	vec[1] = fvecy; //forward vector y value	vec[2] = fvecz; //forward vector z value	vec[3] = uvecx; //up vector x value	vec[4] = uvecy; //up vector y value	vec[5] = uvecz; //up vector z value*/}int ZSound::AddBuffer( std::string& filename ){	ALenum format;	ALsizei size;	ALvoid* data;	ALsizei freq;	ALboolean loop;	if(alGetError() != AL_NO_ERROR)		return -1;	//alutLoadWAVFile( (ALbyte*)filename.c_str(), &format, &data, &size, &freq, &loop);	//alBufferData(Buffers[0], format, data, size, freq);	//alutUnloadWAV(format, data, size, freq);	if(alGetError() != AL_NO_ERROR)		return -1;}int main(int argc, char *argv[]){	ZSound a;	while(1==1) {		_sleep(500);	}	return 0;}




if i reintergrate the alut routine it cant link anymore...

OUTPUT compiling with example file:
Compiler: Default compilerBuilding Makefile: "D:\MyDocs\Projekte\programs\Star Trek Federation United\ZSound\src\lesson5\Makefile.win"Executing  make cleanrm -f main.o  Lesson5.exeg++.exe -c main.cpp -o main.o -I"D:/MyPrograms/DevCpp/include/c++"  -I"D:/MyPrograms/DevCpp/include/c++/mingw32"  -I"D:/MyPrograms/DevCpp/include/c++/backward"  -I"D:/MyPrograms/DevCpp/include"  -I"."  g++.exe main.o  -o "Lesson5.exe" -L"D:/MyPrograms/DevCpp/lib" libOpenAL32.a libALut.a Execution terminatedCompilation successful 


OUTPUT compiling with my file:
Compiler: Default compilerBuilding Makefile: "D:\MyDocs\Projekte\programs\Star Trek Federation United\ZSound\src\lesson5\Makefile.win"Executing  make cleanrm -f main.o  Lesson5.exeg++.exe -c main.cpp -o main.o -I"D:/MyPrograms/DevCpp/include/c++"  -I"D:/MyPrograms/DevCpp/include/c++/mingw32"  -I"D:/MyPrograms/DevCpp/include/c++/backward"  -I"D:/MyPrograms/DevCpp/include"  -I"."  g++.exe main.o  -o "Lesson5.exe" -L"D:/MyPrograms/DevCpp/lib" libOpenAL32.a libALut.a libALut.a(./Release/ALut.obj.b)(.text+0x3):E:\Projects\OpenAL: undefined reference to `alcGetCurrentContext'libALut.a(./Release/ALut.obj.b)(.text+0xb):E:\Projects\OpenAL: undefined reference to `alcGetContextsDevice'make.exe: *** [Lesson5.exe] Error 1Execution terminated 


[edited by - mbalex on November 18, 2003 11:30:47 AM]
problem2&3:

whats the simplest format with the best documentation/tutorials out there?

This topic is closed to new replies.

Advertisement