Post by nathanmyersc on Nov 7, 2024 12:09:58 GMT
#include <sndfile.h>
#include <Eigen/Dense>
#include <cmath>
#include <vector>
#include <iostream>
#include <filesystem>
const double PI = 3.14159265358979323846;
// Generate a sine wave oscillator for carrier frequency
std::vector<double> generateCarrier(int sampleRate, double carrierFreq, int length) {
std::vector<double> carrier(length);
for (int i = 0; i < length; ++i) {
carrier[i] = std::sin(2 * PI * carrierFreq * i / sampleRate);
}
return carrier;
}
// Low-pass filter using a basic implementation (for more complex, consider FFT or IIR/FIR)
void lowpassFilter(std::vector<double>& signal, double cutoffFreq, int sampleRate) {
// Simple implementation - more effective filtering may be needed.
// Replace with FIR/IIR filter implementation as needed.
for (int i = 1; i < signal.size(); ++i) {
double rc = 1.0 / (2 * PI * cutoffFreq);
double dt = 1.0 / sampleRate;
double alpha = dt / (rc + dt);
signal[i] = alpha * signal[i] + (1 - alpha) * signal[i - 1];
}
}
// High-pass filter similar to the lowpass method above
void highpassFilter(std::vector<double>& signal, double cutoffFreq, int sampleRate) {
for (int i = 1; i < signal.size(); ++i) {
double rc = 1.0 / (2 * PI * cutoffFreq);
double dt = 1.0 / sampleRate;
double alpha = rc / (rc + dt);
signal[i] = alpha * (signal[i - 1] + signal[i] - signal[i - 1]);
}
}
// Modulate signal by multiplying it with carrier signal
void modulate(std::vector<double>& signal, const std::vector<double>& carrier) {
for (size_t i = 0; i < signal.size(); ++i) {
signal[i] *= carrier[i % carrier.size()];
}
}
int main() {
// Ask for input file name and validate
std::string inputFilename;
std::cout << "Enter the input filename (e.g., input.wav): ";
std::getline(std::cin, inputFilename);
// Check if the input file exists
if (!std::filesystem::exists(inputFilename)) {
std::cerr << "Error: The file does not exist.\n";
return 1;
}
// Generate output filename
std::filesystem::path inputPath(inputFilename);
std::string outputFilename = inputPath.stem().string() + "_ultrasonic" + inputPath.extension().string();
// Load audio file
SF_INFO sfinfo;
SNDFILE* infile = sf_open(inputFilename.c_str(), SFM_READ, &sfinfo);
if (!infile) {
std::cerr << "Could not open input file.\n";
return 1;
}
int sampleRate = sfinfo.samplerate;
int numSamples = sfinfo.frames * sfinfo.channels;
std::vector<double> signal(numSamples);
sf_read_double(infile, signal.data(), numSamples);
sf_close(infile);
// Define carrier frequency and cutoff based on Nyquist frequency
double carrierFreq = 17500; // 17.5 kHz as per the plugin defaults
double nyquistFreq = sampleRate / 2.0;
double cutoffFreq = std::min(carrierFreq / 2.0, nyquistFreq - carrierFreq);
// Generate carrier wave
std::vector<double> carrier = generateCarrier(sampleRate, carrierFreq, numSamples);
// Apply filters
lowpassFilter(signal, cutoffFreq, sampleRate);
highpassFilter(signal, 80, sampleRate); // High-pass with 80Hz as in the original plugin
// Modulate signal with the carrier wave
modulate(signal, carrier);
// Save to output file
SNDFILE* outfile = sf_open(outputFilename.c_str(), SFM_WRITE, &sfinfo);
if (!outfile) {
std::cerr << "Could not open output file.\n";
return 1;
}
sf_write_double(outfile, signal.data(), numSamples);
sf_close(outfile);
std::cout << "Subliminal processing completed. Output saved to: " << outputFilename << "\n";
return 0;
}
Download Link easyupload.io/9gg4ey
It currently presumes your file is a 32 bit float wav type.
usage either use your words and create a affirmation track or use a TTS generator and generate Artifical affirmation track.
Place the file in the same folder as this program.
Type the filename of the program and hit enter. That is all.