progress
This commit is contained in:
1 parent
48dc9ec180
commit
c44757430d
2 files changed
+22
-5
No files matched your search
@@ -3,6 +3,8 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
|
||||
void WriteWAVHeader(std::ofstream &file, DWORD length) {
|
||||
DWORD dataChunkSize = length;
|
||||
@@ -34,7 +36,13 @@ void WriteWAVHeader(std::ofstream &file, DWORD length) {
|
||||
file.write(reinterpret_cast<const char*>(&dataChunkSize), 4);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(int argc, char** argv) {
|
||||
std::cout << "Program start\n";
|
||||
if (argc != 2) {
|
||||
std::cerr << "Wrong arguments!\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 1) Initialize BASS: default device, 44100 Hz, no flags
|
||||
if (!BASS_Init(-1, 44100, 0, NULL, NULL)) {
|
||||
std::cerr << "BASS_Init error: " << BASS_ErrorGetCode() << std::endl;
|
||||
@@ -50,7 +58,7 @@ int main() {
|
||||
}
|
||||
|
||||
// Create decoding stream (no playback)
|
||||
HSTREAM midiStream = BASS_MIDI_StreamCreateFile(FALSE, "Rapapara_POL_07753.mid", 0, 0,
|
||||
HSTREAM midiStream = BASS_MIDI_StreamCreateFile(FALSE, argv[1], 0, 0,
|
||||
BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT, 44100);
|
||||
if (!midiStream) {
|
||||
std::cerr << "BASS_MIDI_StreamCreateFile error: " << BASS_ErrorGetCode() << std::endl;
|
||||
@@ -81,11 +89,16 @@ int main() {
|
||||
const int bufferSize = 44100 * 2 * sizeof(float); // 1 second float stereo
|
||||
float buffer[44100 * 2];
|
||||
|
||||
std::cout << "Synthesis start\n";
|
||||
|
||||
QWORD totalRead = 0;
|
||||
QWORD totalStreamLength = BASS_ChannelGetLength(midiStream, BASS_POS_BYTE);
|
||||
auto lastUpdate = std::chrono::steady_clock::now();
|
||||
|
||||
while (true) {
|
||||
int bytes = BASS_ChannelGetData(midiStream, buffer, bufferSize);
|
||||
if (bytes <= 0) break;
|
||||
|
||||
// Convert float samples to 16-bit PCM
|
||||
short pcm[44100 * 2];
|
||||
for (int i = 0; i < bytes / 4; ++i) {
|
||||
float sample = buffer[i] * 32767.0f;
|
||||
@@ -94,14 +107,18 @@ int main() {
|
||||
pcm[i] = static_cast<short>(sample);
|
||||
}
|
||||
|
||||
wav.write(reinterpret_cast<const char*>(pcm), bytes / 2); // float->16bit halves size
|
||||
totalBytes += bytes / 2;
|
||||
wav.write(reinterpret_cast<const char*>(pcm), bytes / 2);
|
||||
totalRead += bytes;
|
||||
|
||||
float percent = (totalStreamLength > 0) ? (100.0f * totalRead / totalStreamLength) : 0.0f;
|
||||
printf("\rProgress: %.2f%%", percent);
|
||||
}
|
||||
|
||||
wav.seekp(0);
|
||||
WriteWAVHeader(wav, totalBytes);
|
||||
wav.close();
|
||||
|
||||
std::cout << "\nSynthesis end\n";
|
||||
std::cout << "Exported to output.wav" << std::endl;
|
||||
|
||||
// 6) Clean up
|
||||
|
||||
Reference in new issue
Block a user