Skip to content

Commit

Permalink
ofxSoundUtils: setting tickcount and device id in buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
roymacdonald committed Nov 30, 2023
1 parent 8db1207 commit 98688e9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/ofxSoundUtils.cpp
Expand Up @@ -23,21 +23,25 @@ void ofxSoundUtils::getBufferFromChannelGroup(const ofSoundBuffer & sourceBuffer
ofLogWarning("ofxSoundBaseMultiplexer") << "no valid group indices";
return;
}
if (group.size() >= channels){
ofLogNotice("ofxSoundBaseMultiplexer") << "getChannels requested more channels than available ";
if (group.size() > channels){
ofLogNotice("ofxSoundBaseMultiplexer") << "getChannels requested more channels than available ";
}

// targetBuffer.setNumChannels(group.size());
targetBuffer.setSampleRate(sourceBuffer.getSampleRate());
targetBuffer.setTickCount(sourceBuffer.getTickCount());
targetBuffer.setDeviceID(sourceBuffer.getDeviceID());

auto nFrames = sourceBuffer.getNumFrames();
// if(channels == 1){
// sourceBuffer.copyTo(targetBuffer, nFrames, 0, 0);
// }else{
auto & buffer = sourceBuffer.getBuffer();
targetBuffer.allocate(nFrames, group.size());
for (std::size_t k = 0; k < group.size(); k++) {
auto gs = group.size();
targetBuffer.allocate(nFrames, gs);
for (std::size_t k = 0; k < gs; k++) {
for(std::size_t i = 0; i < nFrames; i++){
targetBuffer[k + i * group.size()] = buffer[group[k] + i * channels];
targetBuffer[k + i * gs] = buffer[group[k] + i * channels];
}
}
// }
Expand All @@ -52,9 +56,10 @@ void ofxSoundUtils::setBufferFromChannelGroup(const ofSoundBuffer & sourceBuffer
}
auto nFrames = targetBuffer.getNumFrames();
auto & buffer = targetBuffer.getBuffer();
auto nc = targetBuffer.getNumChannels();
for (std::size_t k = 0; k < group.size(); k++) {
for(std::size_t i = 0; i < nFrames; i++){
buffer[group[k]+ i * targetBuffer.getNumChannels()] = sourceBuffer[k + i * group.size()];
buffer[group[k]+ i * nc] = sourceBuffer[k + i * group.size()];
}
}
}
Expand Down

0 comments on commit 98688e9

Please sign in to comment.