How can I load sound in OpenAL
How can I load sound in OpenAL? In the programmers guide I got from developer.creative.com, it mentions alutLoadWAVFile, but it also says, "This function is not guaranteed to be included with any OpenAL distribution, as it is not part of the
specification of OpenAL. This function or a similar one will probably exist, however."
In my program I get a called to undefined function conserning it. So, is there a similar fuction existing? If so, what is it?
Since it''s not guaranteed to be packed with the rest of OpenGL, you should try to find the library & download it.
Isn't this the wrong forum? This is for OpenG L _not_ OpenA L
AFAIK OAL uses PCM data... so you could probably make your own file loaders(for .au, .mp3, .wav, etc.) to load the waveform data from a file then send it to OpenAL...
I haven't had any experience with this though(I'm D/loading the SDK right now), but in theory it should work.
Check out Wotsit's Format for audio file format specifications.
Henrym
[Edit: typo]
[edited by - henrym on June 3, 2002 6:25:28 AM]
AFAIK OAL uses PCM data... so you could probably make your own file loaders(for .au, .mp3, .wav, etc.) to load the waveform data from a file then send it to OpenAL...
I haven't had any experience with this though(I'm D/loading the SDK right now), but in theory it should work.
Check out Wotsit's Format for audio file format specifications.
Henrym
[Edit: typo]
[edited by - henrym on June 3, 2002 6:25:28 AM]
i havent try OpenAL,
i think ALut is something like GLut,
so, try to include something like alut.h
i think ALut is something like GLut,
so, try to include something like alut.h
Yeah, OpenAL just takes PCM data, so it''s easy to make loaders for it. For example:
I removed most of the obvious functions (and ctors/dtors), along with saving functions and all that. To complete the heirarchy, there''s also a ''gSoundSource'' class that gives positional data to gSound''s.
// Ripped from the (my) GTW engine (minizimed for space)class gPCM { protected: gByte *Data; gBool FreeMem; gAudioFormatEnum Format; unsigned int Freq, Size; public: typedef size_t (*LoadFunc)(gPCM *, gFile &); size_t Load(LoadFunc, gFile &);};class gPCMWave : public gPCMType { private: public: static size_t Load(gPCM *, gFile &);};size_t gPCMWave::Load(gPCM *This, gFile &File) { gDebugStackRegister("gPCMWave::Load (static)"); gWaveHeader RIFFHeader; gWaveChunkHeader Chunk; gWaveFormatHeader FormatChunk; long FileOffset = File.Tell(); // A hackish method of testing if the format chunk has already been read FormatChunk.Channels = 0; File.Read(&RIFFHeader,sizeof(gWaveHeader),1); gEndianFixLittle(RIFFHeader.GroupID); gEndianFixLittle(RIFFHeader.Type); if(RIFFHeader.GroupID != 0x46464952) { // RIFF gError("Not a RIFF file."); } if(RIFFHeader.Type != 0x45564157) { // WAVE gError("Not a Wave file."); } for( ; ; ) { File.Read(&Chunk,sizeof(gWaveChunkHeader),1); switch(Chunk.ID) { case 0x20746D66: // Format Chunk if(Chunk.Size != 16) { gError("Non-PCM formatted data."); } File.Read(&FormatChunk,sizeof(gWaveFormatHeader),1); if(FormatChunk.Format != 1) { gError("Non-PCM formatted data."); } break; case 0x61746164: // Data Chunk This->SetData(gNewArray(gByte,Chunk.Size)); This->SetFreeMem(true); File.Read(This->GetData(),1,Chunk.Size); This->SetSize(Chunk.Size); break; default: File.Seek(Chunk.Size, SEEK_CUR); } if(This->GetData() && FormatChunk.Channels != 0) break; } This->SetFreq(FormatChunk.SampleRate); switch(FormatChunk.Channels) { case 1: // Mono switch(FormatChunk.BitsPS) { case 8: // Byte This->SetFormat(gPCMFormat::MONO_8); break; case 16: // Word This->SetFormat(gPCMFormat::MONO_16); break; default: gError("Unsupported BitsPS for single channel."); } break; case 2: // Stereo switch(FormatChunk.BitsPS) { case 8: // Byte This->SetFormat(gPCMFormat::STEREO_8); break; case 16: // Word This->SetFormat(gPCMFormat::STEREO_16); break; default: gError("Unsupported BitsPS for two channels."); } break; default: gError("Unsupported channel count."); } return File.Tell()-FileOffset;}class gSound { protected: unsigned int ID; public: void Spawn(const gPCM *);};void gSound::Spawn(const gPCM *PCM) { alGenBuffers(1, &ID); alBufferData(ID, PCM->GetFormat(), (ALvoid *)PCM->GetData(), PCM->GetSize(), PCM->GetFreq());}
I removed most of the obvious functions (and ctors/dtors), along with saving functions and all that. To complete the heirarchy, there''s also a ''gSoundSource'' class that gives positional data to gSound''s.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement