From ef3acaedc1eb530b263e9235d83d853f8282a278 Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Sat, 28 Apr 2012 13:16:29 +0000 Subject: Audio: * Fix for [#31099] Audio in Meta-Strips Plays Beyond Strip Cut * Adding a split files option to the mixdown operator which then renders each channel into a separate file --- intern/audaspace/intern/AUD_C-API.cpp | 42 ++++++++++++++++++++++++++++++ intern/audaspace/intern/AUD_C-API.h | 15 +++++++++++ intern/audaspace/intern/AUD_FileWriter.cpp | 36 +++++++++++++++++++++++++ intern/audaspace/intern/AUD_FileWriter.h | 10 +++++++ 4 files changed, 103 insertions(+) (limited to 'intern/audaspace') diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp index 9100a277124..50b47650696 100644 --- a/intern/audaspace/intern/AUD_C-API.cpp +++ b/intern/audaspace/intern/AUD_C-API.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include "AUD_NULLDevice.h" #include "AUD_I3DDevice.h" @@ -1236,6 +1237,47 @@ const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned int lengt } } +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) +{ + try + { + AUD_SequencerFactory* f = dynamic_cast(sound->get()); + + f->setSpecs(specs.specs); + + std::vector > writers; + + int channels = specs.channels; + specs.channels = AUD_CHANNELS_MONO; + + for(int i = 0; i < channels; i++) + { + std::stringstream stream; + std::string fn = filename; + size_t index = fn.find_last_of('.'); + size_t index_slash = fn.find_last_of('/'); + size_t index_backslash = fn.find_last_of('\\'); + if((index == std::string::npos) || + ((index < index_slash) && (index_slash != std::string::npos)) || + ((index < index_backslash) && (index_backslash != std::string::npos))) + stream << filename << "_" << (i + 1); + else + stream << fn.substr(0, index) << "_" << (i + 1) << fn.substr(index); + writers.push_back(AUD_FileWriter::createWriter(stream.str(), specs, format, codec, bitrate)); + } + + AUD_Reference reader = f->createQualityReader(); + reader->seek(start); + AUD_FileWriter::writeReader(reader, writers, length, buffersize); + + return NULL; + } + catch(AUD_Exception& e) + { + return e.str; + } +} + AUD_Device* AUD_openMixdownDevice(AUD_DeviceSpecs specs, AUD_Sound* sequencer, float volume, float start) { try diff --git a/intern/audaspace/intern/AUD_C-API.h b/intern/audaspace/intern/AUD_C-API.h index 8388af2170d..a52a1fa8369 100644 --- a/intern/audaspace/intern/AUD_C-API.h +++ b/intern/audaspace/intern/AUD_C-API.h @@ -709,6 +709,21 @@ extern void* AUD_getSet(void* set); */ extern 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); +/** + * Mixes a sound down into multiple files. + * \param sound The sound scene to mix down. + * \param start The start frame. + * \param length The count of frames to write. + * \param buffersize How many samples should be written at once. + * \param filename The file to write to, the channel number and an underscore are added at the beginning. + * \param specs The file's audio specification. + * \param format The file's container format. + * \param codec The codec used for encoding the audio data. + * \param bitrate The bitrate for encoding. + * \return An error message or NULL in case of success. + */ +extern 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); + /** * Opens a read device and prepares it for mixdown of the sound scene. * \param specs Output audio specifications. diff --git a/intern/audaspace/intern/AUD_FileWriter.cpp b/intern/audaspace/intern/AUD_FileWriter.cpp index df76b667e3f..f74021acad1 100644 --- a/intern/audaspace/intern/AUD_FileWriter.cpp +++ b/intern/audaspace/intern/AUD_FileWriter.cpp @@ -93,3 +93,39 @@ void AUD_FileWriter::writeReader(AUD_Reference reader, AUD_Referenc writer->write(len, buf); } } + +void AUD_FileWriter::writeReader(AUD_Reference reader, std::vector >& writers, unsigned int length, unsigned int buffersize) +{ + AUD_Buffer buffer(buffersize * AUD_SAMPLE_SIZE(reader->getSpecs())); + AUD_Buffer buffer2(buffersize * sizeof(sample_t)); + sample_t* buf = buffer.getBuffer(); + sample_t* buf2 = buffer2.getBuffer(); + + int len; + bool eos = false; + int channels = reader->getSpecs().channels; + + for(unsigned int pos = 0; ((pos < length) || (length <= 0)) && !eos; pos += len) + { + len = buffersize; + if((len > length - pos) && (length > 0)) + len = length - pos; + reader->read(len, eos, buf); + + for(int channel = 0; channel < channels; channel++) + { + for(int i = 0; i < len; i++) + { + // clamping! + if(buf[i * channels + channel] > 1) + buf2[i] = 1; + else if(buf[i * channels + channel] < -1) + buf2[i] = -1; + else + buf2[i] = buf[i * channels + channel]; + } + + writers[channel]->write(len, buf2); + } + } +} diff --git a/intern/audaspace/intern/AUD_FileWriter.h b/intern/audaspace/intern/AUD_FileWriter.h index c9ee2b1ee12..385aba5ef45 100644 --- a/intern/audaspace/intern/AUD_FileWriter.h +++ b/intern/audaspace/intern/AUD_FileWriter.h @@ -31,6 +31,7 @@ #define __AUD_FILEWRITER_H__ #include +#include #include "AUD_Reference.h" @@ -68,6 +69,15 @@ public: * \param buffersize How many samples should be transfered at once. */ static void writeReader(AUD_Reference reader, AUD_Reference writer, unsigned int length, unsigned int buffersize); + + /** + * Writes a reader to several writers. + * \param reader The reader to read from. + * \param writers The writers to write to. + * \param length How many samples should be transfered. + * \param buffersize How many samples should be transfered at once. + */ + static void writeReader(AUD_Reference reader, std::vector >& writers, unsigned int length, unsigned int buffersize); }; #endif //__AUD_FILEWRITER_H__ -- cgit v1.2.3