Skip to content

Commit 4ec9a84

Browse files
authored
AESND_AllocateVoiceWithArg: Return NULL when all voices are being used (#135)
* Return NULL when all voices are being used Current behavior when all voices are being used is to return the address of the last AESNDPB in __aesndvoicepb[], which is being used already * Clean up test logic in `for` loop (mostly) remove a layer of indents
1 parent 2ed8077 commit 4ec9a84

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

libaesnd/aesndlib.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -545,23 +545,24 @@ AESNDPB* AESND_AllocateVoiceWithArg(AESNDVoiceCallbackArg cb,void *cbArg)
545545

546546
_CPU_ISR_Disable(level);
547547
for(i=0;i<MAX_VOICES;i++) {
548+
if(__aesndvoicepb[i].flags&VOICE_USED)
549+
continue;
550+
548551
pb = &__aesndvoicepb[i];
549-
if(!(pb->flags&VOICE_USED)) {
550-
pb->voiceno = i;
551-
pb->flags = (VOICE_USED|VOICE_STOPPED);
552-
pb->pds = pb->yn1 = pb->yn2 = 0;
553-
pb->buf_start = 0;
554-
pb->buf_curr = 0;
555-
pb->buf_end = 0;
556-
pb->counter = 0;
557-
pb->volume_l = 0x100;
558-
pb->volume_r = 0x100;
559-
pb->freq_h = 0x0001;
560-
pb->freq_l = 0x0000;
561-
pb->cb = cb;
562-
pb->cbArg = cbArg;
563-
break;
564-
}
552+
pb->voiceno = i;
553+
pb->flags = (VOICE_USED|VOICE_STOPPED);
554+
pb->pds = pb->yn1 = pb->yn2 = 0;
555+
pb->buf_start = 0;
556+
pb->buf_curr = 0;
557+
pb->buf_end = 0;
558+
pb->counter = 0;
559+
pb->volume_l = 0x100;
560+
pb->volume_r = 0x100;
561+
pb->freq_h = 0x0001;
562+
pb->freq_l = 0x0000;
563+
pb->cb = cb;
564+
pb->cbArg = cbArg;
565+
break;
565566
}
566567
_CPU_ISR_Restore(level);
567568

0 commit comments

Comments
 (0)