[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38331] branches/soc-2011-pepper/intern/ audaspace: 3D Audio GSoC:

Joerg Mueller nexyon at gmail.com
Tue Jul 12 15:11:01 CEST 2011


Revision: 38331
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38331
Author:   nexyon
Date:     2011-07-12 13:11:00 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
3D Audio GSoC:
Software 3D Audio implementation.

Modified Paths:
--------------
    branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_3DMath.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.h

Modified: branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2011-07-12 13:09:22 UTC (rev 38330)
+++ branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2011-07-12 13:11:00 UTC (rev 38331)
@@ -492,10 +492,10 @@
 
 bool AUD_OpenALDevice::AUD_OpenALHandle::isRelative()
 {
-	int result = std::numeric_limits<float>::quiet_NaN();
+	int result;
 
 	if(!m_status)
-		return result;
+		return false;
 
 	m_device->lock();
 

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_3DMath.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_3DMath.h	2011-07-12 13:09:22 UTC (rev 38330)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_3DMath.h	2011-07-12 13:11:00 UTC (rev 38331)
@@ -32,15 +32,16 @@
 #ifndef AUD_3DMATH
 #define AUD_3DMATH
 
-class AUD_Quaternion
+#include <cmath>
+
+class AUD_Vector3
 {
 private:
 	union
 	{
-		float m_v[4];
+		float m_v[3];
 		struct
 		{
-			float m_w;
 			float m_x;
 			float m_y;
 			float m_z;
@@ -49,28 +50,18 @@
 
 public:
 	/**
-	 * Creates a new quaternion.
-	 * \param w The w component.
+	 * Creates a new 3 dimensional vector.
 	 * \param x The x component.
 	 * \param y The y component.
 	 * \param z The z component.
 	 */
-	inline AUD_Quaternion(float w, float x, float y, float z) :
-		m_w(w), m_x(x), m_y(y), m_z(z)
+	inline AUD_Vector3(float x = 0, float y = 0, float z = 0) :
+		m_x(x), m_y(y), m_z(z)
 	{
 	}
 
 	/**
-	 * Retrieves the w component of the quarternion.
-	 * \return The w component.
-	 */
-	inline const float& w() const
-	{
-		return m_w;
-	}
-
-	/**
-	 * Retrieves the x component of the quarternion.
+	 * Retrieves the x component of the vector.
 	 * \return The x component.
 	 */
 	inline const float& x() const
@@ -79,7 +70,7 @@
 	}
 
 	/**
-	 * Retrieves the y component of the quarternion.
+	 * Retrieves the y component of the vector.
 	 * \return The y component.
 	 */
 	inline const float& y() const
@@ -88,7 +79,7 @@
 	}
 
 	/**
-	 * Retrieves the z component of the quarternion.
+	 * Retrieves the z component of the vector.
 	 * \return The z component.
 	 */
 	inline const float& z() const
@@ -98,34 +89,80 @@
 
 	/**
 	 * Retrieves the components of the vector.
-	 * \param destination Where the 4 float values should be saved to.
+	 * \param destination Where the 3 float values should be saved to.
 	 */
 	inline void get(float* destination) const
 	{
-		destination[0] = m_w;
-		destination[1] = m_x;
-		destination[2] = m_y;
-		destination[3] = m_z;
+		destination[0] = m_x;
+		destination[1] = m_y;
+		destination[2] = m_z;
 	}
 
 	/**
 	 * Retrieves the components of the vector.
-	 * \return The components as float[4].
+	 * \return The components as float[3].
 	 */
 	inline const float* get() const
 	{
 		return m_v;
 	}
+
+	/**
+	 * Retrieves the length of the vector.
+	 * \return The length of the vector.
+	 */
+	inline float length() const
+	{
+		return sqrt(m_x*m_x + m_y*m_y + m_z*m_z);
+	}
+
+	inline AUD_Vector3 cross(const AUD_Vector3& op) const
+	{
+		return AUD_Vector3(m_y * op.m_z - m_z * op.m_y,
+						   m_z * op.m_x - m_x * op.m_z,
+						   m_x * op.m_y - m_y * op.m_x);
+	}
+
+	/**
+	 * Retrieves the dot product.
+	 * \param op The second operand.
+	 * \return The dot product of the two vectors.
+	 */
+	inline float operator*(const AUD_Vector3& op) const
+	{
+		return m_x * op.m_x + m_y * op.m_y + m_z * op.m_z;
+	}
+
+	inline AUD_Vector3 operator*(const float& op) const
+	{
+		return AUD_Vector3(m_x * op, m_y * op, m_z * op);
+	}
+
+	inline AUD_Vector3 operator+(const AUD_Vector3& op) const
+	{
+		return AUD_Vector3(m_x + op.m_x, m_y + op.m_y, m_z + op.m_z);
+	}
+
+	inline AUD_Vector3 operator-(const AUD_Vector3& op) const
+	{
+		return AUD_Vector3(m_x - op.m_x, m_y - op.m_y, m_z - op.m_z);
+	}
+
+	inline AUD_Vector3 operator-() const
+	{
+		return AUD_Vector3(-m_x, -m_y, -m_z);
+	}
 };
 
-class AUD_Vector3
+class AUD_Quaternion
 {
 private:
 	union
 	{
-		float m_v[3];
+		float m_v[4];
 		struct
 		{
+			float m_w;
 			float m_x;
 			float m_y;
 			float m_z;
@@ -134,18 +171,28 @@
 
 public:
 	/**
-	 * Creates a new 3 dimensional vector.
+	 * Creates a new quaternion.
+	 * \param w The w component.
 	 * \param x The x component.
 	 * \param y The y component.
 	 * \param z The z component.
 	 */
-	inline AUD_Vector3(float x, float y, float z) :
-		m_x(x), m_y(y), m_z(z)
+	inline AUD_Quaternion(float w = 1, float x = 0, float y = 0, float z = 0) :
+		m_w(w), m_x(x), m_y(y), m_z(z)
 	{
 	}
 
 	/**
-	 * Retrieves the x component of the vector.
+	 * Retrieves the w component of the quarternion.
+	 * \return The w component.
+	 */
+	inline const float& w() const
+	{
+		return m_w;
+	}
+
+	/**
+	 * Retrieves the x component of the quarternion.
 	 * \return The x component.
 	 */
 	inline const float& x() const
@@ -154,7 +201,7 @@
 	}
 
 	/**
-	 * Retrieves the y component of the vector.
+	 * Retrieves the y component of the quarternion.
 	 * \return The y component.
 	 */
 	inline const float& y() const
@@ -163,7 +210,7 @@
 	}
 
 	/**
-	 * Retrieves the z component of the vector.
+	 * Retrieves the z component of the quarternion.
 	 * \return The z component.
 	 */
 	inline const float& z() const
@@ -173,23 +220,38 @@
 
 	/**
 	 * Retrieves the components of the vector.
-	 * \param destination Where the 3 float values should be saved to.
+	 * \param destination Where the 4 float values should be saved to.
 	 */
 	inline void get(float* destination) const
 	{
-		destination[0] = m_x;
-		destination[1] = m_y;
-		destination[2] = m_z;
+		destination[0] = m_w;
+		destination[1] = m_x;
+		destination[2] = m_y;
+		destination[3] = m_z;
 	}
 
 	/**
 	 * Retrieves the components of the vector.
-	 * \return The components as float[3].
+	 * \return The components as float[4].
 	 */
 	inline const float* get() const
 	{
 		return m_v;
 	}
+
+	inline AUD_Vector3 getLookAt() const
+	{
+		return AUD_Vector3(-2 * (m_w * m_y + m_x * m_z),
+							2 * (m_x * m_w - m_z * m_y),
+							2 * (m_x * m_x + m_y * m_y) - 1);
+	}
+
+	inline AUD_Vector3 getUp() const
+	{
+		return AUD_Vector3(2 * (m_x * m_y - m_w * m_z),
+							1 - 2 * (m_x * m_x + m_z * m_z),
+							2 * (m_w * m_x + m_y * m_z));
+	}
 };
 
 #endif //AUD_3DMATH

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.cpp	2011-07-12 13:09:22 UTC (rev 38330)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.cpp	2011-07-12 13:11:00 UTC (rev 38331)
@@ -43,7 +43,7 @@
 AUD_ChannelMapperReader::AUD_ChannelMapperReader(AUD_Reference<AUD_IReader> reader,
 												 AUD_Channels channels) :
 		AUD_EffectReader(reader), m_target_channels(channels),
-	m_source_channels(AUD_CHANNELS_INVALID), m_mapping(0)
+	m_source_channels(AUD_CHANNELS_INVALID), m_mapping(0), m_map_size(0), m_mono_angle(0)
 {
 }
 
@@ -58,6 +58,13 @@
 	calculateMapping();
 }
 
+void AUD_ChannelMapperReader::setMonoAngle(float angle)
+{
+	m_mono_angle = angle;
+	if(m_source_channels == AUD_CHANNELS_MONO)
+		calculateMapping();
+}
+
 float AUD_ChannelMapperReader::angleDistance(float alpha, float beta)
 {
 	alpha = fabs(alpha - beta);
@@ -68,11 +75,20 @@
 	return alpha;
 }
 
+#include <iostream>
+
 void AUD_ChannelMapperReader::calculateMapping()
 {
-	delete[] m_mapping;
-	m_mapping = new float[m_source_channels * m_target_channels];
+	if(m_map_size < m_source_channels * m_target_channels)
+	{
+		delete[] m_mapping;
+		m_mapping = new float[m_source_channels * m_target_channels];
+		m_map_size = m_source_channels * m_target_channels;
+	}
 
+	for(int i = 0; i < m_source_channels * m_target_channels; i++)
+		m_mapping[i] = 0;
+
 	const AUD_Channel* source_channels = CHANNEL_MAPS[m_source_channels - 1];
 	const AUD_Channel* target_channels = CHANNEL_MAPS[m_target_channels - 1];
 
@@ -90,6 +106,9 @@
 	const float* source_angles = CHANNEL_ANGLES[m_source_channels - 1];
 	const float* target_angles = CHANNEL_ANGLES[m_target_channels - 1];
 
+	if(m_source_channels == AUD_CHANNELS_MONO)
+		source_angles = &m_mono_angle;
+
 	int channel_min1, channel_min2;
 	float angle_min1, angle_min2, angle;
 
@@ -124,17 +143,26 @@
 			}
 		}
 
-		if(channel_min2 == -1)
+		angle = angle_min1 + angle_min2;
+		if(channel_min2 == -1 || angle == 0)
 		{
 			m_mapping[channel_min1 * m_source_channels + i] = 1;
 		}
 		else
 		{
-			angle = angle_min1 + angle_min2;
 			m_mapping[channel_min1 * m_source_channels + i] = cos(M_PI_2 * angle_min1 / angle);
 			m_mapping[channel_min2 * m_source_channels + i] = cos(M_PI_2 * angle_min2 / angle);
 		}
 	}
+
+	/* AUD_XXX for(int i = 0; i < m_source_channels; i++)
+	{
+		for(int j = 0; j < m_target_channels; j++)
+		{
+			std::cout << m_mapping[i * m_source_channels + j] << " ";
+		}
+		std::cout << std::endl;
+	}*/
 }
 
 AUD_Specs AUD_ChannelMapperReader::getSpecs() const

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.h	2011-07-12 13:09:22 UTC (rev 38330)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.h	2011-07-12 13:11:00 UTC (rev 38331)
@@ -62,6 +62,16 @@
 	 */
 	float* m_mapping;
 
+	/**
+	 * The size of the mapping.
+	 */
+	int m_map_size;
+
+	/**
+	 * The mono source angle.
+	 */
+	float m_mono_angle;
+
 	static const AUD_Channel MONO_MAP[];
 	static const AUD_Channel STEREO_MAP[];
 	static const AUD_Channel STEREO_LFE_MAP[];
@@ -111,6 +121,8 @@
 
 	void setChannels(AUD_Channels channels);
 
+	void setMonoAngle(float angle);
+
 	virtual AUD_Specs getSpecs() const;
 	virtual void read(int& length, bool& eos, sample_t* buffer);
 };

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp	2011-07-12 13:09:22 UTC (rev 38330)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp	2011-07-12 13:11:00 UTC (rev 38331)
@@ -38,17 +38,180 @@
 #else
 #include "AUD_LinearResampleReader.h"
 #endif
-#include "AUD_ChannelMapperReader.h"
 
 #include <cstring>
+#include <cmath>
 #include <limits>
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list