Openal


Jan-Nik

Active Member
Joined
Jan 5, 2009
Messages
534
Location
Germany
I just wanted to know if OpenAL is supported on the Wiz? I couldn't find any information about this.

I've never worked with it but just wanted to know if I can use it in the end, before I start looking into it.
 

Pickle

Mega GP Mania
Joined
May 30, 2006
Messages
5,507
Location
Detroit, Michigan
Website
Visit site
Jan-Nik said:
I just wanted to know if OpenAL is supported on the Wiz? I couldn't find any information about this.

I've never worked with it but just wanted to know if I can use it in the end, before I start looking into it.

I think it might work, you will have to compile the lib yourself though. I thought I used for something but it appears maybe it was only for the pandora.
 
Last edited by a moderator:

Ed Welch

Still Fresh
Joined
Sep 14, 2009
Messages
3
I'm interested too, because I want to port my game which uses OpenAL for sound.

From the answers, I take it no one has ever got it to work for Pandora?

sorry, forget that question. I posted in wrong place by mistake
 

Jan-Nik

Active Member
Joined
Jan 5, 2009
Messages
534
Location
Germany
Okay I've managed to build OpenAL Soft for the Wiz: http://dl.openhandhelds.org/cgi-bin/wiz.cgi?0,0,0,0,19,313

I haven't tried playing an actual sound yet, but I will do that this evening.
 

crow_riot

Well-Known Member
Joined
Sep 21, 2009
Messages
1,763
Location
.at
that's nice to see. i was thinking about 3d sound lately :) some performance stuff would be nice - how fast/slow it behaves. :)
 

Jan-Nik

Active Member
Joined
Jan 5, 2009
Messages
534
Location
Germany
Okay tried to play a sound and the good news is: It work's!

The bad news: performance. It wasn't possible to play 3 sounds at the same time without lag.

This is what I get when drawing a simple OpenGL Scene while playing a short sound:

0 sounds playing: 60 FPS
1 sound playing: 46 FPS
2 sounds playing: 36 FPS
3 sounds playing: 27 FPS (and sound stutter)

Listener and source where the same position and the sound was 2 seconds long, 44 kHz and mono.
 

crow_riot

Well-Known Member
Joined
Sep 21, 2009
Messages
1,763
Location
.at
thanks for the info, not very promising, though. i might take a look at it, do you also have the the http://kcat.strangesoft.net/alure.html ported? or how/what file format did you load? wave? ogg? i'm just curious, because i dont really wanna use the blown sdl_mixer incl. sdl if there's a smaller lib can do that :)
 

Jan-Nik

Active Member
Joined
Jan 5, 2009
Messages
534
Location
Germany
crow_riot said:
thanks for the info, not very promising, though. i might take a look at it, do you also have the the http://kcat.strangesoft.net/alure.html ported? or how/what file format did you load? wave? ogg? i'm just curious, because i dont really wanna use the blown sdl_mixer incl. sdl if there's a smaller lib can do that :)
I've been using vorbisfile to load an ogg file. ALURE looks nice though, never heard of it before.

Here's the part of my source code which handles sound:
Code:
#include <AL/al.h>
#include <AL/alc.h>
#include <vorbis/vorbisfile.h>
#include <stdexcept>
#include <boost/noncopyable.hpp>

class Sound : boost::noncopyable {
public:
	Sound(ALuint buffer) : source_(0), buffer_(buffer)
	{
		alGenSources(1, &source_);
		alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f);
		alSource3f(source_, AL_POSITION, 0.0f, 0.0f, 0.0f);
		alSourcei(source_, AL_BUFFER, buffer);
		alSourcePlay(source_);
	}
	~Sound()
	{
		alSourceStop(source_);
		alSourceUnqueueBuffers(source_, 1, &buffer_);
		alDeleteSources(1, &source_);
	}
	bool IsPlaying()
	{
		ALint state;
		alGetSourcei(source_, AL_SOURCE_STATE, &state);
		return state == AL_PLAYING;
	}
	bool Stopped()
	{
		ALint state;
		alGetSourcei(source_, AL_SOURCE_STATE, &state);
		return state == AL_STOPPED;
	}
	void SetPitch(float p)
	{
		alSourcef(source_, AL_PITCH, p);
	}
private:
	ALuint source_;
	ALuint buffer_;
};

class Audio : boost::noncopyable {
public:
	Audio() : device_(0), context_(0)
	{
		device_ = alcOpenDevice(0);
		if(!device_)
		{
			throw std::runtime_error("Could not open audio device.");
		}
		context_ = alcCreateContext(device_, 0);
		if(context_)
		{
			alcMakeContextCurrent(context_);
		}
		else
		{
			throw std::runtime_error("Could not create audio context.");
		}
	}
	~Audio()
	{
		alcMakeContextCurrent(0);
		alcDestroyContext(context_);
		alcCloseDevice(device_);
	}
	void Play(boost::shared_ptr<Sound> sound)
	{
		std::vector<boost::shared_ptr<Sound> >::iterator end = sounds_.end();
		for(std::vector<boost::shared_ptr<Sound> >::iterator it = sounds_.begin(); it != end; ++it)
		{
			if((*it)->Stopped())
			{
				it = sounds_.erase(it);
			}
		}
		sounds_.push_back(boost::shared_ptr<Sound>(sound));
	}
	void Stop(boost::shared_ptr<Sound> sound)
	{
		std::vector<boost::shared_ptr<Sound> >::iterator i;
		if((i = std::find(sounds_.begin(), sounds_.end(), sound)) != sounds_.end()) // sound hasn't been loaded yet?
		{
			sounds_.erase(i);
		}
	}
private:
	std::vector<boost::shared_ptr<Sound> > sounds_;
	ALCdevice* device_;
	ALCcontext* context_;
};

Audio& GetAudio()
{
	static Audio audio_;
	return audio_;
}

class SoundFile : boost::noncopyable {
public:
	SoundFile(const std::string& filename) : sound_((Sound*)0)
	{
		Debug("Decoding "); Debug(filename); Debug(" ... ");
		// based on http://www.gamedev.net/reference/articles/article2031.asp
		FILE* f = fopen(filename.c_str(), "rb");
		if(!f)
		{
			throw std::runtime_error("Could not open OGG file.");
		}

		OggVorbis_File oggFile;
		if(ov_open(f, &oggFile, 0, 0) != 0)
		{
			throw std::runtime_error("Could not open OGG file.");
		}

		vorbis_info* pInfo;
		pInfo = ov_info(&oggFile, -1);
		ALenum format;
		if(pInfo->channels == 1)
		{
			format = AL_FORMAT_MONO16;
		}
		else
		{
			format = AL_FORMAT_STEREO16;
		}
		ALsizei freq = pInfo->rate;

		std::vector<char> bufferData;
		const int bufferSize = 32768;
		char array[bufferSize]; // 32 KB buffers
		const int endian = 0; // 0 for Little-Endian, 1 for Big-Endian
		int bitStream;
		int bytes;
		do
		{
			bytes = ov_read(&oggFile, array, bufferSize, endian, 2, 1, &bitStream);

			if (bytes < 0)
			{
				ov_clear(&oggFile);
				throw std::runtime_error("Error decoding OGG file.");
			}

			bufferData.insert(bufferData.end(), array, array + bytes);
		}
		while(bytes > 0);

		ov_clear(&oggFile);
		Debug("OK\n");
		alGenBuffers(1, &buffer_);
		alBufferData(buffer_, format, &bufferData[0], static_cast<ALsizei>(bufferData.size()), freq);
	}
	~SoundFile()
	{
		alDeleteBuffers(1, &buffer_);
	}
	void Play()
	{
		sound_.reset(new Sound(buffer_));
		GetAudio().Play(sound_);
	}
	void Stop()
	{
		if(sound_)
		{
			GetAudio().Stop(sound_);
			sound_.reset((Sound*)0);
		}
	}
	bool IsPlaying()
	{
		if(sound_)
		{
			return sound_->IsPlaying();
		}
		return false;
	}
	void SetPitch(float p)
	{
		if(sound_)
		{
			sound_->SetPitch(p);
		}
	}
private:
	boost::shared_ptr<Sound> sound_;
	ALuint buffer_;
};
 
Last edited by a moderator:

crow_riot

Well-Known Member
Joined
Sep 21, 2009
Messages
1,763
Location
.at
thanks for sample. i tried SDL_mixer out now and i think i'll stick to that for the time being, though it has it's downsides :)

btw i've compiled the low-memory branch of tremor (an integer-only ogg decoder) for the wiz toolchain. works as a simple replacement for the current libvorbisidec in the toolchain.

source is here
http://svn.xiph.org/branches/lowmem-branch/Tremor/

the binary here
http://crow.riot.org/wiz/libvorbisidec.so.1.0.2.zip

if anyone wants to upload to the archive, feel free to do so :)
 

Jan-Nik

Active Member
Joined
Jan 5, 2009
Messages
534
Location
Germany
crow_riot said:
btw i've compiled the low-memory branch of tremor (an integer-only ogg decoder) for the wiz toolchain. works as a simple replacement for the current libvorbisidec in the toolchain.

source is here
http://svn.xiph.org/branches/lowmem-branch/Tremor/

the binary here
http://crow.riot.org/wiz/libvorbisidec.so.1.0.2.zip
Do I just have to put it next to my binary in order to improve decoding speed?
 
Last edited by a moderator:

Jan-Nik

Active Member
Joined
Jan 5, 2009
Messages
534
Location
Germany
I've just found a mistake in my source, I was creating a new buffer for each source. I fixed it (and updated the source above), but it didn't improve performance :(

I also tried better RAM timings, but that didn't help either. What does help is overclocking.

i tried SDL_mixer out now and i think i'll stick to that for the time being, though it has it's downsides :)
Yeah, SDL_mixer is definitely the better way on the Wiz, but unfortunately I need to change the pitch of sounds in my game which SDL_mixer doesn't support (or does it?).
 

crow_riot

Well-Known Member
Joined
Sep 21, 2009
Messages
1,763
Location
.at
Jan-Nik said:
I've just found a mistake in my source, I was creating a new buffer for each source. I fixed it (and updated the source above), but it didn't improve performance :(

I also tried better RAM timings, but that didn't help either. What does help is overclocking.

i tried SDL_mixer out now and i think i'll stick to that for the time being, though it has it's downsides :)
Yeah, SDL_mixer is definitely the better way on the Wiz, but unfortunately I need to change the pitch of sounds in my game which SDL_mixer doesn't support (or does it?).
nope, sdl_mixer does not support pitching, but i've tried doing something similar. there's soundtouch, an opensource sound processing library @ http://www.surina.net/soundtouch/, which is capable of realtime speed/pitch shifting. in combination with sdl mixer's mix callback i think it could be done.
 
Last edited by a moderator:
Top