comparison transform/FeatureExtractionModelTransformer.cpp @ 1096:4d9816ba0ebe simple-fft-model

Rework audio file reader API to prefer using std containers
author Chris Cannam
date Mon, 15 Jun 2015 12:19:47 +0100
parents 420fc961c0c4
children aa588c391d1a
comparison
equal deleted inserted replaced
1095:b66734b5f806 1096:4d9816ba0ebe
785 785
786 sv_frame_t got = 0; 786 sv_frame_t got = 0;
787 787
788 if (channelCount == 1) { 788 if (channelCount == 1) {
789 789
790 got = input->getData(m_input.getChannel(), startFrame, size, 790 auto data = input->getData(m_input.getChannel(), startFrame, size);
791 buffers[0] + offset); 791 got = data.size();
792
793 copy(data.begin(), data.end(), buffers[0] + offset);
792 794
793 if (m_input.getChannel() == -1 && input->getChannelCount() > 1) { 795 if (m_input.getChannel() == -1 && input->getChannelCount() > 1) {
794 // use mean instead of sum, as plugin input 796 // use mean instead of sum, as plugin input
795 float cc = float(input->getChannelCount()); 797 float cc = float(input->getChannelCount());
796 for (sv_frame_t i = 0; i < size; ++i) { 798 for (sv_frame_t i = 0; i < got; ++i) {
797 buffers[0][i + offset] /= cc; 799 buffers[0][i + offset] /= cc;
798 } 800 }
799 } 801 }
800 802
801 } else { 803 } else {
802 804
803 float **writebuf = buffers; 805 auto data = input->getMultiChannelData(0, channelCount-1, startFrame, size);
804 if (offset > 0) { 806 if (!data.empty()) {
805 writebuf = new float *[channelCount]; 807 got = data[0].size();
806 for (int i = 0; i < channelCount; ++i) { 808 for (int c = 0; in_range_for(data, c); ++c) {
807 writebuf[i] = buffers[i] + offset; 809 copy(data[c].begin(), data[c].end(), buffers[c] + offset);
808 } 810 }
809 } 811 }
810
811 got = input->getMultiChannelData
812 (0, channelCount-1, startFrame, size, writebuf);
813
814 if (writebuf != buffers) delete[] writebuf;
815 } 812 }
816 813
817 while (got < size) { 814 while (got < size) {
818 for (int c = 0; c < channelCount; ++c) { 815 for (int c = 0; c < channelCount; ++c) {
819 buffers[c][got + offset] = 0.0; 816 buffers[c][got + offset] = 0.0;