openframeworks / openframeworks/openFrameworks
ofSoundBuffer::getChannel() causes exception
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
On MacOS, Xcode 9.4.1
void ofSoundBuffer::getChannel(ofSoundBuffer & targetBuffer, std::size_t sourceChannel) const {
//...
if(channels == 1){
//third argument is zero
copyTo(targetBuffer, getNumFrames(), 0, 0);
}
//...
}
void ofSoundBuffer::copyTo(ofSoundBuffer & soundBuffer, std::size_t nFrames, std::size_t outChannels,std::size_t fromFrame,bool loop) const{
soundBuffer.resize(nFrames*outChannels);
soundBuffer.setNumChannels(outChannels);
soundBuffer.setSampleRate(samplerate);
//third argument (outChannels) passed as zero
copyTo(&soundBuffer[0], nFrames, outChannels, fromFrame, loop);
}
void ofSoundBuffer::setNumChannels(int channels){
//this line assigns this->channels to zero
this->channels = channels;
checkSizeAndChannelsConsistency("setNumChannels");
}
bool ofSoundBuffer::checkSizeAndChannelsConsistency(const std::string& _function ) {
std::string function = _function;
if ( function.size()!= 0 ){
function += ": ";
}
//if statement results in division by zero, causing exception
if ( (size()%channels) != 0 ){
ofLogWarning("ofSoundBuffer") << function << "channel count " << channels << " is not consistent with sample count " << size() << " (non-zero remainder)";
return false;
}
return true;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ofSoundBuffer::getChannel() and follow its call to copyTo(), setNumChannels(), and checkSizeAndChannelsConsistency(). Reproduce the mono-channel path on MacOS with Xcode 9.4.1; done means getChannel() completes without an exception when the buffer has one channel.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- audio-video-rtc
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100