mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 01:19:19 +02:00
Merge pull request #19 from antonisauren/tmj-master
Logarytmiczny fade sampli dzwiekow skladanych.
This commit is contained in:
11
sound.cpp
11
sound.cpp
@@ -814,12 +814,15 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
|
|||||||
// chunks other than the first can have fadein
|
// chunks other than the first can have fadein
|
||||||
auto const fadeinwidth { chunkdata.threshold - chunkdata.fadein };
|
auto const fadeinwidth { chunkdata.threshold - chunkdata.fadein };
|
||||||
if( soundpoint < chunkdata.threshold ) {
|
if( soundpoint < chunkdata.threshold ) {
|
||||||
m_properties.gain *=
|
float lineargain =
|
||||||
interpolate(
|
interpolate(
|
||||||
0.f, 1.f,
|
0.f, 1.f,
|
||||||
clamp(
|
clamp(
|
||||||
( soundpoint - chunkdata.fadein ) / fadeinwidth,
|
( soundpoint - chunkdata.fadein ) / fadeinwidth,
|
||||||
0.f, 1.f ) );
|
0.f, 1.f ) );
|
||||||
|
m_properties.gain *=
|
||||||
|
lineargain /
|
||||||
|
(1 + (1 - lineargain) * (-0.57)); // approximation of logarytmic fade in
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -831,12 +834,14 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
|
|||||||
auto const fadeoutwidth { chunkdata.fadeout - m_soundchunks[ chunkindex + 1 ].second.fadein };
|
auto const fadeoutwidth { chunkdata.fadeout - m_soundchunks[ chunkindex + 1 ].second.fadein };
|
||||||
auto const fadeoutstart { chunkdata.fadeout - fadeoutwidth };
|
auto const fadeoutstart { chunkdata.fadeout - fadeoutwidth };
|
||||||
if( soundpoint > fadeoutstart ) {
|
if( soundpoint > fadeoutstart ) {
|
||||||
m_properties.gain *=
|
float lineargain =
|
||||||
interpolate(
|
interpolate(
|
||||||
1.f, 0.f,
|
0.f, 1.f,
|
||||||
clamp(
|
clamp(
|
||||||
( soundpoint - fadeoutstart ) / fadeoutwidth,
|
( soundpoint - fadeoutstart ) / fadeoutwidth,
|
||||||
0.f, 1.f ) );
|
0.f, 1.f ) );
|
||||||
|
m_properties.gain *= (-lineargain + 1) /
|
||||||
|
(1 + lineargain * (-0.57)); // approximation of logarytmic fade out
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user