mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
fix: Stereo sound visualizations (#1970)
Even tough the sound visualizer has `channels` as one of its parameters it wasn't using it properly. ### Problem description The biggest problem is that at each frame the index was being advanced per channel frame_count increments. The number of channels also determines how many graph will be needed to display the graphs of the visualized sound files. Besides these two problems there were many others like incorrect playback time, cracking audio, etc. which will not be mentioned. ### Implementation description To sample the signal a channel sampler was created based on the one used previously that returns as many sampled signals as there are channels. This PR aims hopefully at fixing all the problems encountered, and it has been tested extensively using `Audacity` exported samples to ensure the visualizer fidelity on playback and graph appearance. ### Screenshots 
This commit is contained in:
@@ -34,6 +34,29 @@ namespace hex {
|
||||
class Provider;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] std::vector<std::vector<T>> sampleChannels(const std::vector<T> &data, size_t count, size_t channels) {
|
||||
if (channels == 0) return {};
|
||||
size_t signalLength = std::max(1.0, double(data.size()) / channels);
|
||||
|
||||
size_t stride = std::max(1.0, double(signalLength) / count);
|
||||
|
||||
std::vector<std::vector<T>> result;
|
||||
result.resize(channels);
|
||||
for (size_t i = 0; i < channels; i++) {
|
||||
result[i].reserve(count);
|
||||
}
|
||||
result.reserve(count);
|
||||
|
||||
for (size_t i = 0; i < data.size(); i += stride) {
|
||||
for (size_t j = 0; j < channels; j++) {
|
||||
result[j].push_back(data[i + j]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] std::vector<T> sampleData(const std::vector<T> &data, size_t count) {
|
||||
size_t stride = std::max(1.0, double(data.size()) / count);
|
||||
|
||||
Reference in New Issue
Block a user