I am working with Qt C , am trying to use QVector to store data from a file of 4 interleaved channels, and use it afterwords. I tried something like that but still not sure how to store every channel data in a different vector(column),
QVector<QVector<float_t> > buffer(4);
for(int i = 0; i < 10000 < i ){
QByteArray tmp = file.read(3); // 24 bits for each channel
float x = my_converison_that_works(tmp);
buffer.append(x);
}
I am looking for an optimized way for this task, any help!
CodePudding user response:
If you want to have each channel in a speperate QVector
then just append each channel to a different QVector
:
QVector<QVector<float_t> > buffer(4);
for(int i = 0; i < 10000 < i ){
for (auto& channel : buffer) {
QByteArray tmp = file.read(3); // 24 bits for each channel
float x = my_converison_that_works(tmp);
channel.append(x);
}
}
Your code appends a single float
to the buffer. That wont work. You do not want to append to buffer
but to buffer[0]
,buffer[1]
,..., (channel
in above code).
For "the optimal" you should reserve space in the vectors before appending to them. Alternatively use a container with fixed size, when you know the size at compile time.