2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
8 #include "SoundImpl.hpp"
10 #include "../SoundShader.hpp"
12 #include "fmod.h" // FMOD
14 #include "fmod_errors.h" // FMOD Error Messages
20 ChannelT::ChannelT(int ChannelHandle_
, const SoundImplT
* Sound_
)
21 : ChannelHandle(ChannelHandle_
),
27 void ChannelT::Update()
29 if (ChannelHandle
==-1 || Sound
==NULL
) return;
32 unsigned int Volume
=(unsigned int)(Sound
->Volume
*255);
34 if(!FSOUND_SetVolume(ChannelHandle
, Volume
>255 ? 255 : Volume
))
35 std::cout
<< "FMOD3: Error setting channel volume\n";
37 // Only make 3D adjustments if the sound really is a 3D sound.
38 if (!Sound
->Is3D()) return;
40 // Note that y and z coordinate are swapped because FMOD uses another coordinate system than Cafu.
41 const double METERS_PER_WORLD_UNIT
= 0.0254;
43 float Pos
[3]={ float(Sound
->Position
.x
* METERS_PER_WORLD_UNIT
),
44 float(Sound
->Position
.z
* METERS_PER_WORLD_UNIT
),
45 float(Sound
->Position
.y
* METERS_PER_WORLD_UNIT
) };
47 float Vel
[3]={ float(Sound
->Velocity
.x
* METERS_PER_WORLD_UNIT
),
48 float(Sound
->Velocity
.z
* METERS_PER_WORLD_UNIT
),
49 float(Sound
->Velocity
.y
* METERS_PER_WORLD_UNIT
) };
51 // Note that direction and sound cones are ignored because they are not supported by FMOD.
53 if (!FSOUND_3D_SetAttributes(ChannelHandle
, Pos
, Vel
))
54 std::cout
<< "FMOD3: Error setting channel position and velocity\n";
56 if (!FSOUND_3D_SetMinMaxDistance(ChannelHandle
, Sound
->MinDistance
, Sound
->MaxDistance
))
57 std::cout
<< "FMOD3: Error setting channel min/max distance\n";