Audaspace: port changes from upstream.
Adds possibility to report progress during audio mixdown.
This commit is contained in:
8
extern/audaspace/bindings/C/AUD_Special.cpp
vendored
8
extern/audaspace/bindings/C/AUD_Special.cpp
vendored
@@ -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;
|
||||
}
|
||||
|
10
extern/audaspace/bindings/C/AUD_Special.h
vendored
10
extern/audaspace/bindings/C/AUD_Special.h
vendored
@@ -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.
|
||||
|
4
extern/audaspace/include/file/FileWriter.h
vendored
4
extern/audaspace/include/file/FileWriter.h
vendored
@@ -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
|
||||
|
20
extern/audaspace/src/file/FileWriter.cpp
vendored
20
extern/audaspace/src/file/FileWriter.cpp
vendored
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user