diff --git a/Ona_mowi_POL_07998.mid b/Ona_mowi_POL_07998.mid new file mode 100644 index 0000000..ae32849 Binary files /dev/null and b/Ona_mowi_POL_07998.mid differ diff --git a/main.cpp b/main.cpp index 3f281cf..c79c548 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include 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(&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(sample); } - wav.write(reinterpret_cast(pcm), bytes / 2); // float->16bit halves size - totalBytes += bytes / 2; + wav.write(reinterpret_cast(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