small fix, better sound to test
This commit is contained in:
1 parent
dea9549d44
commit
7432c39ac1
2 files changed
+65
-7
No files matched your search
+4
-4
@@ -128,10 +128,10 @@ std::vector<int16_t> generateAudio(const std::vector<Wave>& waves, int totalDura
|
|||||||
|
|
||||||
// Generate the waveform for the specified duration
|
// Generate the waveform for the specified duration
|
||||||
for (int t = startSample; t < endSample; ++t) {
|
for (int t = startSample; t < endSample; ++t) {
|
||||||
|
if (t >= samples.size()) break; // Prevent out-of-bounds access
|
||||||
double time = static_cast<double>(t) / SAMPLE_RATE;
|
double time = static_cast<double>(t) / SAMPLE_RATE;
|
||||||
double sample = generateWave(wave.type, wave.frequency, time);
|
double sample = generateWave(wave.type, wave.frequency, time);
|
||||||
sample *= wave.volume; // Apply the volume to the waveform
|
sample *= wave.volume; // Apply volume
|
||||||
|
|
||||||
samples[t] += static_cast<int16_t>(sample * 32767); // Linear mixing
|
samples[t] += static_cast<int16_t>(sample * 32767); // Linear mixing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,8 +193,8 @@ int main() {
|
|||||||
std::vector<int16_t> samples = generateAudio(waves, totalDuration);
|
std::vector<int16_t> samples = generateAudio(waves, totalDuration);
|
||||||
|
|
||||||
// Write the audio to a WAV file
|
// Write the audio to a WAV file
|
||||||
writeWav("output_mixed_with_volume.wav", samples);
|
writeWav("output.wav", samples);
|
||||||
|
|
||||||
std::cout << "WAV file generated: output_mixed_with_volume.wav" << std::endl;
|
std::cout << "WAV file generated: output.wav" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,61 @@
|
|||||||
TOTAL_DURATION(5000) // Total duration in milliseconds
|
TOTAL_DURATION(10000)
|
||||||
SINE 0 1000 440 1.0 // Sine wave starts at 0 ms, lasts for 1000 ms, frequency 440 Hz, full volume
|
|
||||||
SQUARE 0 1000 440 0.5 // Square wave starts at 0 ms, lasts for 1000 ms, frequency 440 Hz, 50% volume
|
SQUARE 0 400 392 0.7
|
||||||
|
SAWTOOTH 0 400 392 0.4
|
||||||
|
SINE 0 400 392 0.3
|
||||||
|
TRIANGLE 0 400 392 0.2
|
||||||
|
|
||||||
|
SQUARE 450 400 392 0.7
|
||||||
|
SAWTOOTH 450 400 392 0.4
|
||||||
|
SINE 450 400 392 0.3
|
||||||
|
TRIANGLE 450 400 392 0.2
|
||||||
|
|
||||||
|
SQUARE 900 800 440 0.7
|
||||||
|
SAWTOOTH 900 800 440 0.4
|
||||||
|
SINE 900 800 440 0.3
|
||||||
|
TRIANGLE 900 800 440 0.2
|
||||||
|
|
||||||
|
SQUARE 1800 800 392 0.7
|
||||||
|
SAWTOOTH 1800 800 392 0.4
|
||||||
|
SINE 1800 800 392 0.3
|
||||||
|
TRIANGLE 1800 800 392 0.2
|
||||||
|
|
||||||
|
SQUARE 2700 800 523 0.7
|
||||||
|
SAWTOOTH 2700 800 523 0.4
|
||||||
|
SINE 2700 800 523 0.3
|
||||||
|
TRIANGLE 2700 800 523 0.2
|
||||||
|
|
||||||
|
SQUARE 3600 1600 494 0.7
|
||||||
|
SAWTOOTH 3600 1600 494 0.4
|
||||||
|
SINE 3600 1600 494 0.3
|
||||||
|
TRIANGLE 3600 1600 494 0.2
|
||||||
|
|
||||||
|
SQUARE 5400 400 392 0.7
|
||||||
|
SAWTOOTH 5400 400 392 0.4
|
||||||
|
SINE 5400 400 392 0.3
|
||||||
|
TRIANGLE 5400 400 392 0.2
|
||||||
|
|
||||||
|
SQUARE 5850 400 392 0.7
|
||||||
|
SAWTOOTH 5850 400 392 0.4
|
||||||
|
SINE 5850 400 392 0.3
|
||||||
|
TRIANGLE 5850 400 392 0.2
|
||||||
|
|
||||||
|
SQUARE 6300 800 440 0.7
|
||||||
|
SAWTOOTH 6300 800 440 0.4
|
||||||
|
SINE 6300 800 440 0.3
|
||||||
|
TRIANGLE 6300 800 440 0.2
|
||||||
|
|
||||||
|
SQUARE 7200 800 392 0.7
|
||||||
|
SAWTOOTH 7200 800 392 0.4
|
||||||
|
SINE 7200 800 392 0.3
|
||||||
|
TRIANGLE 7200 800 392 0.2
|
||||||
|
|
||||||
|
SQUARE 8100 800 587 0.7
|
||||||
|
SAWTOOTH 8100 800 587 0.4
|
||||||
|
SINE 8100 800 587 0.3
|
||||||
|
TRIANGLE 8100 800 587 0.2
|
||||||
|
|
||||||
|
SQUARE 9000 1600 523 0.7
|
||||||
|
SAWTOOTH 9000 1600 523 0.4
|
||||||
|
SINE 9000 1600 523 0.3
|
||||||
|
TRIANGLE 9000 1600 523 0.2
|
||||||
Reference in new issue
Block a user