Просмотр исходного кода

clean data structures and fix some functions

mikymod 12 лет назад
Родитель
Сommit
c8b99b4dba
2 измененных файлов с 20 добавлено и 52 удалено
  1. 11 11
      engine/renderers/al/ALRenderer.cpp
  2. 9 41
      engine/renderers/al/ALRenderer.h

+ 11 - 11
engine/renderers/al/ALRenderer.cpp

@@ -137,6 +137,8 @@ SoundBufferId ALRenderer::create_buffer(const void* data, const uint32_t size, c
 	// Generates AL buffer
 	AL_CHECK(alGenBuffers(1, &al_buffer.id));
 
+	ALenum format;
+
 	bool stereo = (channels > 1);
 
 	// Sets sound's format
@@ -146,11 +148,11 @@ SoundBufferId ALRenderer::create_buffer(const void* data, const uint32_t size, c
 		{
 			if (stereo)
 			{
-				al_buffer.format = AL_FORMAT_STEREO8;
+				format = AL_FORMAT_STEREO8;
 			}
 			else
 			{
-				al_buffer.format = AL_FORMAT_MONO8;
+				format = AL_FORMAT_MONO8;
 			}
 
 			break;
@@ -160,11 +162,11 @@ SoundBufferId ALRenderer::create_buffer(const void* data, const uint32_t size, c
 		{
 			if (stereo)
 			{
-				al_buffer.format = AL_FORMAT_STEREO16;
+				format = AL_FORMAT_STEREO16;
 			}
 			else
 			{
-				al_buffer.format = AL_FORMAT_MONO16;
+				format = AL_FORMAT_MONO16;
 			}
 
 			break;
@@ -177,14 +179,8 @@ SoundBufferId ALRenderer::create_buffer(const void* data, const uint32_t size, c
 		}
 	}
 
-	// Sets sound's size
-	al_buffer.size = size;
-
-	// Sets sound's frequency
-	al_buffer.freq = sample_rate;
-
 	// Fills AL buffer
-	AL_CHECK(alBufferData(al_buffer.id, al_buffer.format, data, al_buffer.size, al_buffer.freq));
+	AL_CHECK(alBufferData(al_buffer.id, format, data, size, sample_rate));
 
 	return id;
 }
@@ -197,6 +193,8 @@ void ALRenderer::destroy_buffer(SoundBufferId id)
 	SoundBuffer& al_buffer = m_buffers[id.index];
 
 	AL_CHECK(alDeleteBuffers(1, &al_buffer.id));
+
+	m_buffers_id_table.destroy(id);
 }
 
 
@@ -265,6 +263,8 @@ void ALRenderer::destroy_source(SoundSourceId id)
 	SoundSource& al_source = m_sources[id.index];
 
 	alDeleteSources(1, &al_source.id);
+
+	m_sources_id_table.destroy(id);
 }
 
 //-----------------------------------------------------------------------------

+ 9 - 41
engine/renderers/al/ALRenderer.h

@@ -41,20 +41,12 @@ namespace crown
 struct SoundBuffer
 {
 	ALuint 		id;
-
-	ALenum 		format;
-	ALsizei		size;
-	ALsizei		freq;
 };
 
 //-----------------------------------------------------------------------------
 struct SoundSource
 {
 	ALuint		id;
-
-	ALfloat		pos[3];
-	ALfloat		vel[3];
-	ALfloat		dir[3];
 };
 
 
@@ -62,70 +54,46 @@ struct SoundSource
 //-----------------------------------------------------------------------------
 class ALRenderer : public AudioRenderer
 {
-public:
-
-	static const uint32_t	MAX_SOURCES = 128;
-	static const uint32_t	MAX_BUFFERS_PER_SOURCES = 16;
-	static const uint32_t 	MAX_BUFFERS = MAX_SOURCES * MAX_BUFFERS_PER_SOURCES;
-
 public:
 
 							ALRenderer();
 
-	/// Init AL renderer. Must be called first
 	void					init();
 
-	/// Shutdown AL Renderer
 	void					shutdown();
 
-	/// Sets listener parameters. In OpenAL, @a position affects audibility of sounds, 
-	/// @a velocity affects doppler shift and @a orientation affects how a sound could be heard
 	void					set_listener(const Vec3& pos, const Vec3& vel, const Vec3& or_up, const Vec3& or_at) const;
 
-	/// Creates AL buffer's @a data, with a specific @a size, which contains sound raw data.
-	/// More parameters must be specified, such as @a sample_rate, that is the number of sample per unit of time 
-	/// taken from a continuous signal to make a discrete signal, @a channels which specifies if sound is mono or stereo and @ bxs
-	/// (bits per sample) which specifies the magnitude of samples information.
-	/// N.B: stereo sound can not be attenuated
 	SoundBufferId			create_buffer(const void* data, const uint32_t size, const uint32_t sample_rate, const uint32_t channels, const uint32_t bxs);
 
-	/// Destroys AL buffer
 	void					destroy_buffer(SoundBufferId id);
 
-	/// Creates AL source of sound at the given @position in 3D space
-	/// @a velocity affects doppler shift and @a direction affects how a sound could be heard
 	SoundSourceId			create_source(const Vec3& pos, const Vec3& vel, const Vec3& dir, const bool loop);
 
-	/// Plays a sound, specified by @a id, previously created
 	void 					play_source(SoundSourceId id);
 
-	/// Pauses a sound, specified by @a id, previously created
 	void					pause_source(SoundSourceId id);
 
-	/// Destroys a sound, specified by @a id, previously created
 	void 					destroy_source(SoundSourceId id);
 
-	/// Binds a AL buffer to AL source
 	void					bind_buffer(SoundSourceId sid, SoundBufferId bid);
-	///	Sets source's @a min_distance. From @a min_distance to @a max_distance, sound
-	/// scales from full volume to silence
+
 	void					set_source_min_distance(SoundSourceId id,  const float min_distance);
-	///	Sets source's @a max_distance. From @a min_distance to @a max_distance, sound
-	/// scales from full volume to silence
+
 	void					set_source_max_distance(SoundSourceId id,  const float max_distance);
-	/// Sets source's @a position. It affects sound audibility
+
 	void					set_source_position(SoundSourceId id, const Vec3& pos);
-	/// Sets source's @a velocity. It affects doppler shift
+
 	void					set_source_velocity(SoundSourceId id, const Vec3& vel);
-	/// Sets source's @a direction. It affects how a sound could be heard
+
 	void					set_source_direction(SoundSourceId id, const Vec3& dir);
-	/// Sets source's @a pitch.
+
 	void					set_source_pitch(SoundSourceId id, const float pitch);
-	/// Sets source's @a gain, that is measure sound's amplification
+
 	void 					set_source_gain(SoundSourceId id, const float gain);
-	/// Sets source's @a rolloff factor. Greater it is, greater sound's attenuation is
+
 	void					set_source_rolloff(SoundSourceId id, const float rolloff);
-	/// Is source #@a id playing?
+
 	bool					source_playing(SoundSourceId id);
 
 private: