generated from CoolLibs/library-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b05f621
commit 2ea44b1
Showing
6 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#pragma once | ||
|
||
#include "../../src/load_audio_file.h" | ||
#include "../../src/compute_volume.hpp" | ||
#include "../../src/load_audio_file.hpp" | ||
#include "RtAudioWrapper/RtAudioWrapper.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "compute_volume.hpp" | ||
#include <cstdint> | ||
|
||
namespace Cool { | ||
|
||
auto compute_volume(RtAudioW::Player const& player, float average_duration_in_seconds /*TODO(Audio) better name*/) -> float | ||
{ | ||
if (!player.has_audio_data()) | ||
return 0.f; | ||
|
||
auto const width = static_cast<int64_t>(static_cast<float>(player.audio_data().sample_rate) * average_duration_in_seconds); | ||
|
||
float volume{0.f}; | ||
for (int64_t i = 0; i < width; ++i) | ||
{ | ||
int64_t const offset = i - width / 2; | ||
for (int64_t channel_index = 0; channel_index < player.audio_data().channels_count; ++channel_index) | ||
{ | ||
// TODO(Audio) When the audio loops, we might start sampling the next play of the audio. But since the width is small, this is probably not a noticeable problem ? | ||
volume += std::abs(player.sample_unaltered_volume(player.current_frame_index() + offset, channel_index)); | ||
} | ||
} | ||
return volume / static_cast<float>(width) / static_cast<float>(player.audio_data().channels_count); | ||
} | ||
|
||
} // namespace Cool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
#include "RtAudioWrapper/RtAudioWrapper.hpp" | ||
|
||
namespace Cool { | ||
|
||
/// Returns a number between 0 and 1. | ||
auto compute_volume(RtAudioW::Player const& player, float average_duration_in_seconds) -> float; | ||
|
||
} // namespace Cool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.