Panning the sound output of an ofVideoPlayer

Is it possible?

If you’re using quicktime you can use the MediaSetSoundBalance() method, which takes a reference to a MediaHandler (take a look at ofQtUtils) and an int which works like so:

The balance parameter value may range from -128 to 127. Negative values emphasize the left sound channel, while positive values emphasize the right sound channel. A value of -128 forces all output through the left channel. Similarly, a value of 127 forces all output through the right channel.

Passing a positive balance value causes the left channel to get quieter.

Passing a negative balance value causes the right channel to get quieter.

The amount it gets quieter can be seen in the following examples:

A balance value of 32 would lower the left volume by one quarter of its current value (since 32 is a quarter of 127, the full volume setting). A balance value of -96 would lower the right volume by 3/4 of its current value (since 96 is 3/4 of 128).

Maybe one of the gStreamer folks can chime in with the gStreamer version. I’ll try to get something working with it tonight just to play around. Hope that helps.

I just did this actually:

  
class myPanVideoPlayer : public ofVideoPlayer{  
	public:	  
	void setPan(float pan){  
		SetMovieAudioBalance(moviePtr, pan, 0);  
	}  
};  

Brilliant! Thank you very much, gents.

The balance parameter value may range from -128 to 127. Negative values emphasize the left sound channel, while positive values emphasize the right sound channel. A value of -128 forces all output through the left channel. Similarly, a value of 127 forces all output through the right channel.

Passing a positive balance value causes the left channel to get quieter.

Passing a negative balance value causes the right channel to get quieter.

The amount it gets quieter can be seen in the following examples:

A balance value of 32 would lower the left volume by one quarter of its current value (since 32 is a quarter of 127, the full volume setting). A balance value of -96 would lower the right volume by 3/4 of its current value (since 96 is 3/4 of 128).

By the way, in practice, the -128 to 127 range didn’t work for me. -1 gave a full pan left and 1 gave a full pan right and going beyond those values made it just not work.

Yeah, that’s just the MediaSetSoundBalance(), which operates differently than the SetMovieAudioBalance().

leftRight
A pointer to the new balance setting for the movie. The balance setting is a 32-bit floating-point value that controls the relative volume of the left and right sound channels. A value of 0 sets the balance to neutral. Positive values up to 1.0 shift the balance to the right channel, negative values up to –1.0 to the left channel.

but yeah, Theos suggestion uses a way more updated (and easier) way to do it

In windows 0.61 is compiled against Quicktime 6.x … SetMovieAudioBalance requires 7.x

I downloaded the SDK from here and just copied headers and lib folders into the appropriate lib/quicktime folders…appears to re-compile fine.

NB: I just copied the same lib files into the win_cb and vs2008 folders, again, for me it worked fine and was easier than renegotiating the project linkages…

There’s an extended ofVideoPlayer example (as part of a threaded video loader) over here.

Not sure if I should post it, but here it is anyways :wink:

[edit] wouldn’t upload, so for now you can get it from my website

but after I copied all quick 7.x SDK related lib and include files, I got error messages as follows:

…\libs\quicktime\include\fp.h|89|error: conflicting declaration ‘typedef double float_t’
c:\program files\codeblocks\mingw\bin…\lib\gcc\mingw32\4.4.1…\include\math.h|324|error: ‘float_t’ has a previous declaration as ‘typedef long double float_t’|
…\libs\quicktime\include\fp.h|90|error: conflicting declaration ‘typedef double double_t’
c:\program files\codeblocks\mingw\bin…\lib\gcc\mingw32\4.4.1…\include\math.h|325|error: ‘double_t’ has a previous declaration as ‘typedef long double double_t’|

seems some settings in math.h conflicts with fp.h??

ummm…it’s been ages since I was doing this, but I seem to remember something like that.

You might need to put a:

  
#ifdef float_t  
#undef float_t  
#endif  

and

  
#ifdef double_t  
#undef double_t  
#endif  

into either fp.h or math.h…it’s not pretty but I think it will work :slight_smile: