* implementation of a trivial positional-sound audio

Wed, 18 Feb 2015 17:32:24 +0200

author
cengizkandemir
date
Wed, 18 Feb 2015 17:32:24 +0200
branch
audio
changeset 632
87e903442cce
parent 623
581cbdea2a18
child 644
0725cb6b1a4b

* implementation of a trivial positional-sound

Testing/Source/Manual/Audio.cpp file | annotate | diff | comparison | revisions
--- a/Testing/Source/Manual/Audio.cpp	Tue Feb 10 14:30:45 2015 +0200
+++ b/Testing/Source/Manual/Audio.cpp	Wed Feb 18 17:32:24 2015 +0200
@@ -11,6 +11,7 @@
 typedef PaStreamCallbackTimeInfo PATimeInfo;
 typedef PaStreamCallbackFlags PAFlags;
 
+
 struct Wave
 {
 	Wave(): current(0) {}
@@ -20,6 +21,13 @@
 	std::uint16_t channels;
 	std::uint32_t samplepersec;
 	float lrbalance;
+	
+	float xleftlistener;
+	float xrightlistener;
+	float yleftlistener;
+	float yrightlistener;
+	float xsource;
+	float ysource;
 };
 
 
@@ -114,13 +122,27 @@
 
 	auto status = paContinue;
 
+	float leftdist = 0.f, rightdist = 0.f;
+
+	leftdist = std::sqrt((wave->xleftlistener - wave->xsource) * (wave->xleftlistener - wave->xsource) +
+		                 (wave->yleftlistener - wave->ysource) * (wave->yleftlistener - wave->ysource));
+	rightdist = std::sqrt((wave->xrightlistener - wave->xsource) * (wave->xrightlistener - wave->xsource) +
+						  (wave->yrightlistener - wave->ysource) * (wave->yrightlistener - wave->ysource));
+
     for(unsigned int i = 0; i < framecnt; i++) {
 		if(wave->current == wave->data.size()) {
 			status = paComplete;
 			break;
 		}
-		*out++ = wave->data[wave->current] * (1.f - wave->lrbalance);
-		*out++ = wave->data[wave->current] * wave->lrbalance;
+		// left
+		*out = wave->data[wave->current] * (1.f - wave->lrbalance);
+		*out = wave->data[wave->current] * (1.f / leftdist);
+		out++;
+
+		// right
+		*out = wave->data[wave->current] * wave->lrbalance;
+		*out = wave->data[wave->current] * (1.f / rightdist);
+		out++;
 		wave->current++;
 	}
 
@@ -134,9 +156,15 @@
 
 	CHECK(ImportWave("../Resources/sample.wav", wave))
 
-	wave.lrbalance = 0.9f;
+	wave.lrbalance = 0.5f;
 	wave.channels = 2;
 
+	wave.xleftlistener = -30.f;
+	wave.xrightlistener = 10.f;
+	wave.yleftlistener = wave.yrightlistener = 0.f;
+	wave.xsource = 10.f;
+	wave.ysource = 10.f;
+
 	CHECK(Pa_Initialize())
 
 	PaStream *stream = nullptr;

mercurial