Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echo when modifying pitch or leaving it as is #9

Open
bojeckkk opened this issue Aug 30, 2024 · 1 comment
Open

Echo when modifying pitch or leaving it as is #9

bojeckkk opened this issue Aug 30, 2024 · 1 comment

Comments

@bojeckkk
Copy link

bojeckkk commented Aug 30, 2024

Hey,

I've a simple code for modifying pitch of an audio. Even when I set factor to 1 (no pitch change), there is significant echo hearable in the resulting audio. Sample code below.

#include <fstream>
#include <iostream>
#include <iterator>
#include <vector>
#include <string>

#include "signalsmith-stretch.h"

std::vector<int16_t> convert_to_shorts(const std::vector<float>& input) {
  std::vector<int16_t> shorts;
  shorts.reserve(input.size());
  for (auto&& sample : input) {
    shorts.push_back(sample / 32767.f);
  }
  return shorts;
}

std::vector<float> convert_to_floats(const std::vector<int16_t>&& input) {
  std::vector<float> floats;
  floats.reserve(input.size());
  for (auto&& sample : input) {
    floats.push_back(sample * 32767.f);
  }
  return floats;
}

int main(int argc, char* argv[]) {
std::ifstream input("a.wav", std::ios::binary);
std::vector<unsigned char> input_buffer(std::istreambuf_iterator<char>(input), {});
int samples = (input_buffer.size() - 44) / 2;
auto input_floats = convert_to_floats(std::vector<int16_t>((int16_t*)(input_buffer.data() + 44), (int16_t*)(input_buffer.data() + 44 + samples * 2)));
std::vector<float> output_floats(input_floats.size());
float* input_floats_ptr = input_floats.data();
float* output_floats_ptr = output_floats.data();

signalsmith::stretch::SignalsmithStretch<float> stretch;
stretch.presetDefault(1, 24000);
float factor = 1.5;
if (argc > 1){
  factor = std::stof(argv[1]);
}
stretch.setTransposeFactor(factor);

stretch.process(&input_floats_ptr, samples, &output_floats_ptr, samples);

auto converted = convert_to_shorts(output_floats);

std::ofstream output("a_pitch.wav", std::ios::binary);
output.write(reinterpret_cast<const char*>(input_buffer.data()), 44);
output.write(reinterpret_cast<const char*>(converted.data()), converted.size() * sizeof(decltype(converted)::value_type));
output.close();

}
@bojeckkk
Copy link
Author

bojeckkk commented Sep 2, 2024

The echo is not present in web demo, but webassembly is really obfuscated so I could not get anything useful out of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant