|
Post by xpiotoc333 on Oct 5, 2024 0:23:09 GMT
Seems powerful this is a beta version of it as i just created this , room for formatting will also add change of frequencies to use and a duration option. Try this in accordance to your daily manifestations , now it repeats the text a large number of times in the sine wave and it gives a good cerebral effect so i want to see how this works Attachments:TTW.exe (188 KB)
|
|
|
Post by AnthroHeart on Oct 5, 2024 1:03:37 GMT
Seems powerful this is a beta version of it as i just created this , room for formatting will also add change of frequencies to use and a duration option. Try this in accordance to your daily manifestations , now it repeats the text a large number of times in the sine wave and it gives a good cerebral effect so i want to see how this works Do you have the source code for that binary?
|
|
|
Post by xpiotoc333 on Oct 5, 2024 10:46:56 GMT
Yes sir i do ill post it now
|
|
|
Post by xpiotoc333 on Oct 5, 2024 13:33:02 GMT
#include <iostream> #include <fstream> #include <cmath> #include <vector> #include <cstdint> #include <string>
// Constants for WAV file generation const int SAMPLE_RATE = 44100; const int DURATION = 5; // Duration of the audio in seconds const double PI = 3.14159265358979323846; const int AMPLITUDE = 32767;
// Function to write the WAV file header void write_wav_header(std::ofstream &file, int sample_rate, int num_samples) { int byte_rate = sample_rate * 2; int block_align = 2; int data_size = num_samples * 2;
// RIFF header file << "RIFF"; file.write(reinterpret_cast<const char *>(&data_size), 4); file << "WAVE";
// Format chunk file << "fmt "; int fmt_size = 16; int audio_format = 1; int num_channels = 1; int bits_per_sample = 16; file.write(reinterpret_cast<const char *>(&fmt_size), 4); file.write(reinterpret_cast<const char *>(&audio_format), 2); file.write(reinterpret_cast<const char *>(&num_channels), 2); file.write(reinterpret_cast<const char *>(&sample_rate), 4); file.write(reinterpret_cast<const char *>(&byte_rate), 4); file.write(reinterpret_cast<const char *>(&block_align), 2); file.write(reinterpret_cast<const char *>(&bits_per_sample), 2);
// Data chunk file << "data"; file.write(reinterpret_cast<const char *>(&data_size), 4); }
// Function to generate sine wave samples with text modulation and pitch-shifting std::vector<int16_t> generate_sine_wave_with_pitch_shift(const std::string &text, int sample_rate, int duration, double base_freq, double target_freq) { std::vector<int16_t> samples; int num_samples = sample_rate * duration; int text_index = 0; int text_length = text.length(); double pitch_shift_ratio = target_freq / base_freq; for (int i = 0; i < num_samples; ++i) { double time = static_cast<double>(i) / sample_rate; // Apply pitch shift to the sine wave (frequency modulated) double sine_value = sin(2.0 * PI * target_freq * time); // Modulate the sine wave amplitude with text repeated 1 million times per second int16_t modulated_sample = static_cast<int16_t>(AMPLITUDE * sine_value * (text[text_index % text_length] / 128.0)); samples.push_back(modulated_sample); text_index += 1000000 / sample_rate; // Repeat text 1 million times per second } return samples; }
int main() { // Prompt the user for text input std::string text; std::cout << "Enter the text to be embedded in the sine wave: "; std::getline(std::cin, text);
std::string output_file = "output_pitch_shifted.wav";
// Generate sine wave samples with user input text modulated inside and pitch-shifting from 432 Hz to 200 Hz std::vector<int16_t> samples = generate_sine_wave_with_pitch_shift(text, SAMPLE_RATE, DURATION, 432.0, 200.0);
// Write to WAV file std::ofstream wav_file(output_file, std::ios::binary); write_wav_header(wav_file, SAMPLE_RATE, samples.size());
for (int16_t sample : samples) { wav_file.write(reinterpret_cast<const char *>(&sample), 2); }
wav_file.close();
std::cout << "Pitch-shifted WAV file generated: " << output_file << std::endl; return 0; }
|
|
|
Post by AnthroHeart on Oct 5, 2024 13:34:26 GMT
If you put that inside of a code block, it will format better. Like below. Thank you for this code. I was able to compile it. I removed the "double pitch_shift_ratio" because it wasn't ever used. I'm listening to a WAV created from this.
I updated it so that it can read from a file as well if specified.
#include <iostream> #include <fstream> #include <cmath> #include <vector> #include <cstdint> #include <string>
// Constants for WAV file generation const int SAMPLE_RATE = 44100; const int DURATION = 5; // Duration of the audio in seconds const double PI = 3.14159265358979323846; const int AMPLITUDE = 32767;
// Function to write the WAV file header void write_wav_header(std::ofstream &file, int sample_rate, int num_samples) { int byte_rate = sample_rate * 2; int block_align = 2; int data_size = num_samples * 2;
// RIFF header file << "RIFF"; file.write(reinterpret_cast<const char *>(&data_size), 4); file << "WAVE";
// Format chunk file << "fmt "; int fmt_size = 16; int audio_format = 1; int num_channels = 1; int bits_per_sample = 16; file.write(reinterpret_cast<const char *>(&fmt_size), 4); file.write(reinterpret_cast<const char *>(&audio_format), 2); file.write(reinterpret_cast<const char *>(&num_channels), 2); file.write(reinterpret_cast<const char *>(&sample_rate), 4); file.write(reinterpret_cast<const char *>(&byte_rate), 4); file.write(reinterpret_cast<const char *>(&block_align), 2); file.write(reinterpret_cast<const char *>(&bits_per_sample), 2);
// Data chunk file << "data"; file.write(reinterpret_cast<const char *>(&data_size), 4); }
// Function to generate sine wave samples with text modulation and pitch-shifting std::vector<int16_t> generate_sine_wave_with_pitch_shift(const std::string &text, int sample_rate, int duration, double base_freq, double target_freq) { std::vector<int16_t> samples; int num_samples = sample_rate * duration; int text_index = 0; int text_length = text.length();
for (int i = 0; i < num_samples; ++i) { double time = static_cast<double>(i) / sample_rate; // Apply pitch shift to the sine wave (frequency modulated) double sine_value = sin(2.0 * PI * target_freq * time); // Modulate the sine wave amplitude with text repeated 1 million times per second int16_t modulated_sample = static_cast<int16_t>(AMPLITUDE * sine_value * (text[text_index % text_length] / 128.0)); samples.push_back(modulated_sample); text_index += 1000000 / sample_rate; // Repeat text 1 million times per second } return samples; }
int main() { // Prompt the user for text input std::string text; std::cout << "Enter the text to be embedded in the sine wave (or a filename): "; std::getline(std::cin, text);
// Check if the input is a filename and read file contents std::ifstream file(text); bool used_file = false; if (file.is_open()) { std::string file_content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); text = file_content; file.close(); used_file = true; }
if (used_file) { std::cout << "Using text read from file." << std::endl; } else { std::cout << "Using entered intention." << std::endl; }
std::string output_file = "output_pitch_shifted.wav";
// Generate sine wave samples with user input text modulated inside and pitch-shifting from 432 Hz to 200 Hz std::vector<int16_t> samples = generate_sine_wave_with_pitch_shift(text, SAMPLE_RATE, DURATION, 432.0, 200.0);
// Write to WAV file std::ofstream wav_file(output_file, std::ios::binary); write_wav_header(wav_file, SAMPLE_RATE, samples.size());
for (int16_t sample : samples) { wav_file.write(reinterpret_cast<const char *>(&sample), 2); }
wav_file.close();
std::cout << "Pitch-shifted WAV file generated: " << output_file << std::endl; return 0; }
|
|
|
Post by AnthroHeart on Oct 5, 2024 14:40:56 GMT
I highly recommend using OpenAI ChatGPT Canvas. In ChatGPT you can say "use canvas" and it gives a much better interface for updating your code.
|
|