Sha256: c0e2fe130772b05b3259022bf7b5c5131a712db7cea891c8cc69bc1b3c7f1d62

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

// -*- objc -*-
#include "beeps/beeps.h"


#include <stdlib.h>
#include "Stk.h"
#include "beeps/openal.h"
#include "beeps/exception.h"


namespace Beeps
{


	namespace global
	{

		static ALCdevice* device   = NULL;

		static ALCcontext* context = NULL;

	}// global


	namespace g = global;


	static void
	cleanup ()
	{
		alcMakeContextCurrent(NULL);

		if (g::context)
		{
			alcDestroyContext(g::context);
			g::context = NULL;
		}

		if (g::device)
		{
			alcCloseDevice(g::device);
			g::device = NULL;
		}
	}

	void
	init ()
	{
		if (g::device || g::context)
			beeps_error(__FILE__, __LINE__, "Beeps::init(): already initialized.");

		stk::Stk::setSampleRate(44100);

		g::device = alcOpenDevice(NULL);
		if (!g::device) goto FAILED;

		g::context = alcCreateContext(g::device, NULL);
		if (!g::context) goto FAILED;

		if (!alcMakeContextCurrent(g::context))
			goto FAILED;

		return;

	FAILED:
		cleanup();
		openal_error(__FILE__, __LINE__, "failed to setup OpenAL.");
	}

	void
	fin ()
	{
		if (!g::context)
			beeps_error(__FILE__, __LINE__, "Beeps::fin(): not initialized.");

		cleanup();
	}

	ALCdevice*
	get_device ()
	{
		return g::device;
	}


	uint
	sampling_rate ()
	{
		return stk::Stk::sampleRate();
	}


}// Beeps

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
beeps-0.1.10 src/beeps.cpp