Line data Source code
1 : /** 2 : * \file OutSndFileFilter.cpp 3 : */ 4 : 5 : #include "OutSndFileFilter.h" 6 : #include <ATK/IO/libsndfile/sndfile_traits.h> 7 : 8 : #include <sndfile.hh> 9 : 10 : namespace ATK 11 : { 12 : template<typename DataType> 13 2 : OutSndFileFilter<DataType>::OutSndFileFilter(const std::string& filename, int ports) 14 2 : :TypedBaseFilter<DataType>(0, 0), filename(filename) 15 : { 16 2 : set_nb_input_ports(ports); 17 2 : } 18 : 19 : template<typename DataType> 20 2 : void OutSndFileFilter<DataType>::setup() 21 : { 22 2 : stream = std::make_unique<SndfileHandle>(filename.c_str(), SFM_WRITE, SndfileTraits<DataType>::get_type() | SF_FORMAT_WAV, converted_inputs.size(), input_sampling_rate); 23 2 : stream->command(SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, 1); 24 2 : } 25 : 26 : template<typename DataType> 27 2 : OutSndFileFilter<DataType>::~OutSndFileFilter() 28 : { 29 : 30 2 : } 31 : 32 : template<typename DataType> 33 2 : void OutSndFileFilter<DataType>::process_impl(gsl::index size) const 34 : { 35 4 : std::vector<DataType> temp(size * converted_inputs.size()); 36 : 37 2050 : for(gsl::index i = 0; i < size; ++i) 38 : { 39 5120 : for(gsl::index j = 0; j < converted_inputs.size(); ++j) 40 : { 41 3072 : temp[j + i * converted_inputs.size()] = converted_inputs[j][i]; 42 : } 43 : } 44 : 45 2 : stream->write(temp.data(), size * converted_inputs.size()); 46 2 : } 47 : 48 : #if ATK_ENABLE_INSTANTIATION 49 : template class OutSndFileFilter<std::int16_t>; 50 : template class OutSndFileFilter<std::int32_t>; 51 : template class OutSndFileFilter<double>; 52 : #endif 53 : template class OutSndFileFilter<float>; 54 : }