microphone: less throwy, more MAX()y

This commit is contained in:
Nevyn Bengtsson 2020-01-20 08:52:58 +01:00
parent a5c59e2d12
commit e10799b8c8
1 changed files with 4 additions and 5 deletions

View File

@ -46,13 +46,12 @@ SoundData* lovrMicrophoneGetData(Microphone* microphone, size_t samples) {
return NULL;
}
size_t maxSamples = lovrMicrophoneGetSampleCount(microphone);
if (maxSamples == 0) {
size_t availableSamples = lovrMicrophoneGetSampleCount(microphone);
if (availableSamples == 0) {
return NULL;
}
lovrAssert(samples <= maxSamples, "Requested more audio data than is buffered by the microphone");
if (samples == 0) {
samples = maxSamples;
if (samples == 0 || samples > availableSamples) {
samples = availableSamples;
}
SoundData* soundData = lovrSoundDataCreate(samples, microphone->sampleRate, microphone->bitDepth, microphone->channelCount);