Commit: 9cac181fbead28c0bf963bf2b9f82fddf3c2b7df
Author: Joerg Mueller
Date:   Mon Sep 7 18:11:56 2020 +0200
Branches: master
https://developer.blender.org/rB9cac181fbead28c0bf963bf2b9f82fddf3c2b7df

Audaspace: port changes from upstream.

Adds possibility to report progress during audio mixdown.

===================================================================

M       extern/audaspace/bindings/C/AUD_Special.cpp
M       extern/audaspace/bindings/C/AUD_Special.h
M       extern/audaspace/include/file/FileWriter.h
M       extern/audaspace/src/file/FileWriter.cpp
M       source/blender/editors/sound/sound_ops.c

===================================================================

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<IReader> reader = f->createQualityReader();
                reader->seek(start);
                std::shared_ptr<IWriter> writer = 
FileWriter::createWriter(filename, convCToDSpec(specs), 
static_cast<Container>(format), static_cast<Codec>(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<IReader> 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<IReader> reader, 
std::shared_ptr<IWriter> writer, unsigned int length, unsigned int buffersize);
+       static void writeReader(std::shared_ptr<IReader> reader, 
std::shared_ptr<IWriter> 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<IReader> reader, 
std::vector<std::shared_ptr<IWriter> >& writers, unsigned int length, unsigned 
int buffersize);
+       static void writeReader(std::shared_ptr<IReader> reader, 
std::vector<std::shared_ptr<IWriter> >& 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<IWriter> FileWriter::createWriter(std::string 
filename,DeviceSpe
        return FileManager::createWriter(filename, specs, format, codec, 
bitrate);
 }
 
-void FileWriter::writeReader(std::shared_ptr<IReader> reader, 
std::shared_ptr<IWriter> writer, unsigned int length, unsigned int buffersize)
+void FileWriter::writeReader(std::shared_ptr<IReader> reader, 
std::shared_ptr<IWriter> 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<IReader> 
reader, std::shared_ptr<IW
                }
 
                writer->write(len, buf);
+
+               if(callback)
+               {
+                       float progress = -1;
+                       if(length > 0)
+                               progress = pos / float(length);
+                       callback(progress, data);
+               }
        }
 }
 
-void FileWriter::writeReader(std::shared_ptr<IReader> reader, 
std::vector<std::shared_ptr<IWriter> >& writers, unsigned int length, unsigned 
int buffersize)
+void FileWriter::writeReader(std::shared_ptr<IReader> reader, 
std::vector<std::shared_ptr<IWriter> >& 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<IReader> 
reader, std::vector<std::s
 
                        writers[channel]->write(len, buf2);
                }
+
+               if(callback)
+               {
+                       float progress = -1;
+                       if(length > 0)
+                               progress = pos / float(length);
+                       callback(progress, data);
+               }
        }
 }
 
diff --git a/source/blender/editors/sound/sound_ops.c 
b/source/blender/editors/sound/sound_ops.c
index 87b84c475fd..9d9918a6daf 100644
--- a/source/blender/editors/sound/sound_ops.c
+++ b/source/blender/editors/sound/sound_ops.c
@@ -386,7 +386,9 @@ static int sound_mixdown_exec(bContext *C, wmOperator *op)
                                      specs,
                                      container,
                                      codec,
-                                     bitrate);
+                                     bitrate,
+                                     NULL,
+                                     NULL);
   }
   else {
     result = AUD_mixdown(scene_eval->sound_scene,
@@ -397,7 +399,9 @@ static int sound_mixdown_exec(bContext *C, wmOperator *op)
                          specs,
                          container,
                          codec,
-                         bitrate);
+                         bitrate,
+                         NULL,
+                         NULL);
   }
 
   BKE_sound_reset_scene_specs(scene_eval);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to