Audio:
[blender.git] / intern / audaspace / intern / AUD_C-API.cpp
index 9100a277124b67a5e0a7f59acf366b277fe7828f..50b476506969a014356a386eec367f19fce66b9f 100644 (file)
@@ -41,6 +41,7 @@
 #include <cstdlib>
 #include <cstring>
 #include <cmath>
+#include <sstream>
 
 #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<AUD_SequencerFactory*>(sound->get());
+
+               f->setSpecs(specs.specs);
+
+               std::vector<AUD_Reference<AUD_IWriter> > 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<AUD_IReader> 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