Skip to content

Commit

Permalink
[#10] fixed volume handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rgeorgiev583 committed May 29, 2016
1 parent a4f8d35 commit cafdefa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions source/serendipity/app.d
Expand Up @@ -60,11 +60,12 @@ void startEventLoop(SerendipitySettings* settings, SerendipityLogger logger)
{
import std.algorithm : clamp;
auto result = reader.read(chunkSize);
immutable averageAmplitude = result.save.map!(a => a / result.length).sum();
immutable maxAmplitude = result.save.reduce!max;
immutable lpcc = lpccReducer(result.save);
immutable predicted = regressor.predict(lpcc);
synth.volume = (averageAmplitude / maxAmplitude).clamp(0, 1);
auto normalizedAmplitudes = result.save.map!(a => cast(double)(a / result.length));
auto averageAmplitude = normalizedAmplitudes.sum();
auto maxAmplitude = result.length * normalizedAmplitudes.reduce!max();
auto lpcc = lpccReducer(result.save);
auto predicted = regressor.predict(lpcc);
synth.volume = averageAmplitude / maxAmplitude;
synth.tempo = predicted.tempo;
synth.scale = predicted.scale;
synth.play(generatePinkNoise(roundDownToNearestPowerOfTwo(noiseChunkSize)), settings.channel);
Expand Down

0 comments on commit cafdefa

Please sign in to comment.