1 /* 2 * SampleCopy.h 3 * ------------ 4 * Purpose: Functions for copying sample data. 5 * Notes : (currently none) 6 * Authors: OpenMPT Devs 7 * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. 8 */ 9 10 11 #pragma once 12 13 #include "openmpt/all/BuildSettings.hpp" 14 15 #include "openmpt/soundbase/SampleConvert.hpp" 16 #include "openmpt/soundbase/SampleDecode.hpp" 17 18 19 OPENMPT_NAMESPACE_BEGIN 20 21 22 // Copy a sample data buffer. 23 // targetBuffer: Buffer in which the sample should be copied into. 24 // numSamples: Number of samples of size T that should be copied. targetBuffer is expected to be able to hold "numSamples * incTarget" samples. 25 // incTarget: Number of samples by which the target data pointer is increased each time. 26 // sourceBuffer: Buffer from which the samples should be read. 27 // sourceSize: Size of source buffer, in bytes. 28 // incSource: Number of samples by which the source data pointer is increased each time. 29 // 30 // Template arguments: 31 // SampleConversion: Functor of type SampleConversionFunctor to apply sample conversion (see above for existing functors). 32 template <typename SampleConversion> 33 size_t CopySample(typename SampleConversion::output_t *MPT_RESTRICT outBuf, size_t numSamples, size_t incTarget, const typename SampleConversion::input_t *MPT_RESTRICT inBuf, size_t sourceSize, size_t incSource, SampleConversion conv = SampleConversion()) 34 { 35 const size_t sampleSize = incSource * SampleConversion::input_inc * sizeof(typename SampleConversion::input_t); 36 LimitMax(numSamples, sourceSize / sampleSize); 37 const size_t copySize = numSamples * sampleSize; 38 39 SampleConversion sampleConv(conv); 40 while(numSamples--) 41 { 42 *outBuf = sampleConv(inBuf); 43 outBuf += incTarget; 44 inBuf += incSource * SampleConversion::input_inc; 45 } 46 47 return copySize; 48 } 49 50 51 OPENMPT_NAMESPACE_END 52