From 9cac181fbead28c0bf963bf2b9f82fddf3c2b7df Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Mon, 7 Sep 2020 18:11:56 +0200 Subject: Audaspace: port changes from upstream. Adds possibility to report progress during audio mixdown. --- extern/audaspace/bindings/C/AUD_Special.cpp | 8 ++++---- extern/audaspace/bindings/C/AUD_Special.h | 10 ++++++++-- extern/audaspace/include/file/FileWriter.h | 4 ++-- extern/audaspace/src/file/FileWriter.cpp | 20 ++++++++++++++++++-- 4 files changed, 32 insertions(+), 10 deletions(-) (limited to 'extern') diff --git a/extern/audaspace/bindings/C/AUD_Special.cpp b/extern/audaspace/bindings/C/AUD_Special.cpp index c7155276a30..a83465620ab 100644 --- a/extern/audaspace/bindings/C/AUD_Special.cpp +++ b/extern/audaspace/bindings/C/AUD_Special.cpp @@ -270,7 +270,7 @@ AUD_API int AUD_readSound(AUD_Sound* sound, float* buffer, int length, int sampl return length; } -AUD_API const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate) +AUD_API const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate, void(*callback)(float, void*), void* data) { try { @@ -280,7 +280,7 @@ AUD_API const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned i std::shared_ptr reader = f->createQualityReader(); reader->seek(start); std::shared_ptr writer = FileWriter::createWriter(filename, convCToDSpec(specs), static_cast(format), static_cast(codec), bitrate); - FileWriter::writeReader(reader, writer, length, buffersize); + FileWriter::writeReader(reader, writer, length, buffersize, callback, data); return nullptr; } @@ -290,7 +290,7 @@ AUD_API const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned i } } -AUD_API const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate) +AUD_API const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate, void(*callback)(float, void*), void* data) { try { @@ -326,7 +326,7 @@ AUD_API const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start std::shared_ptr reader = f->createQualityReader(); reader->seek(start); - FileWriter::writeReader(reader, writers, length, buffersize); + FileWriter::writeReader(reader, writers, length, buffersize, callback, data); return nullptr; } diff --git a/extern/audaspace/bindings/C/AUD_Special.h b/extern/audaspace/bindings/C/AUD_Special.h index 9faf9e4ee74..ce51fa2e04e 100644 --- a/extern/audaspace/bindings/C/AUD_Special.h +++ b/extern/audaspace/bindings/C/AUD_Special.h @@ -68,12 +68,15 @@ extern AUD_API int AUD_readSound(AUD_Sound* sound, float* buffer, int length, in * \param format The file's container format. * \param codec The codec used for encoding the audio data. * \param bitrate The bitrate for encoding. + * \param callback A callback function that is called periodically during mixdown, reporting progress if length > 0. Can be NULL. + * \param data Pass through parameter that is passed to the callback. * \return An error message or NULL in case of success. */ extern AUD_API const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, - AUD_Codec codec, unsigned int bitrate); + AUD_Codec codec, unsigned int bitrate, + void(*callback)(float, void*), void* data); /** * Mixes a sound down into multiple files. @@ -86,12 +89,15 @@ extern AUD_API const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, uns * \param format The file's container format. * \param codec The codec used for encoding the audio data. * \param bitrate The bitrate for encoding. + * \param callback A callback function that is called periodically during mixdown, reporting progress if length > 0. Can be NULL. + * \param data Pass through parameter that is passed to the callback. * \return An error message or NULL in case of success. */ extern AUD_API const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, - AUD_Codec codec, unsigned int bitrate); + AUD_Codec codec, unsigned int bitrate, + void(*callback)(float, void*), void* data); /** * Opens a read device and prepares it for mixdown of the sound scene. diff --git a/extern/audaspace/include/file/FileWriter.h b/extern/audaspace/include/file/FileWriter.h index dac842f2a8f..13619d4de71 100644 --- a/extern/audaspace/include/file/FileWriter.h +++ b/extern/audaspace/include/file/FileWriter.h @@ -63,7 +63,7 @@ public: * \param length How many samples should be transferred. * \param buffersize How many samples should be transferred at once. */ - static void writeReader(std::shared_ptr reader, std::shared_ptr writer, unsigned int length, unsigned int buffersize); + static void writeReader(std::shared_ptr reader, std::shared_ptr writer, unsigned int length, unsigned int buffersize, void(*callback)(float, void*) = nullptr, void* data = nullptr); /** * Writes a reader to several writers. @@ -72,7 +72,7 @@ public: * \param length How many samples should be transferred. * \param buffersize How many samples should be transferred at once. */ - static void writeReader(std::shared_ptr reader, std::vector >& writers, unsigned int length, unsigned int buffersize); + static void writeReader(std::shared_ptr reader, std::vector >& writers, unsigned int length, unsigned int buffersize, void(*callback)(float, void*) = nullptr, void* data = nullptr); }; AUD_NAMESPACE_END diff --git a/extern/audaspace/src/file/FileWriter.cpp b/extern/audaspace/src/file/FileWriter.cpp index a6bb0f0049a..b28bbc5329d 100644 --- a/extern/audaspace/src/file/FileWriter.cpp +++ b/extern/audaspace/src/file/FileWriter.cpp @@ -27,7 +27,7 @@ std::shared_ptr FileWriter::createWriter(std::string filename,DeviceSpe return FileManager::createWriter(filename, specs, format, codec, bitrate); } -void FileWriter::writeReader(std::shared_ptr reader, std::shared_ptr writer, unsigned int length, unsigned int buffersize) +void FileWriter::writeReader(std::shared_ptr reader, std::shared_ptr writer, unsigned int length, unsigned int buffersize, void(*callback)(float, void*), void* data) { Buffer buffer(buffersize * AUD_SAMPLE_SIZE(writer->getSpecs())); sample_t* buf = buffer.getBuffer(); @@ -53,10 +53,18 @@ void FileWriter::writeReader(std::shared_ptr reader, std::shared_ptrwrite(len, buf); + + if(callback) + { + float progress = -1; + if(length > 0) + progress = pos / float(length); + callback(progress, data); + } } } -void FileWriter::writeReader(std::shared_ptr reader, std::vector >& writers, unsigned int length, unsigned int buffersize) +void FileWriter::writeReader(std::shared_ptr reader, std::vector >& writers, unsigned int length, unsigned int buffersize, void(*callback)(float, void*), void* data) { Buffer buffer(buffersize * AUD_SAMPLE_SIZE(reader->getSpecs())); Buffer buffer2(buffersize * sizeof(sample_t)); @@ -89,6 +97,14 @@ void FileWriter::writeReader(std::shared_ptr reader, std::vectorwrite(len, buf2); } + + if(callback) + { + float progress = -1; + if(length > 0) + progress = pos / float(length); + callback(progress, data); + } } } -- cgit v1.2.3