MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / xs_audioout_enqueue

Function xs_audioout_enqueue

modules/pins/i2s/audioout.c:739–1058  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

737};
738
739void xs_audioout_enqueue(xsMachine *the)
740{
741 modAudioOut out = xsmcGetHostDataValidate(xsThis, (void *)&xsAudioOutHooks);
742 int streamIndex, argc = xsmcArgc;
743 int repeat = 1, sampleOffset = 0, samplesToUse = -1, volume, i, samplesInBuffer;
744 uint8_t kind;
745 uint8_t *buffer;
746 xsUnsignedValue bufferLength;
747 uint16_t sampleRate;
748 uint8_t numChannels;
749 uint8_t bitsPerSample;
750 uint8_t sampleFormat = kSampleFormatUncompressed;
751 modAudioOutStream stream;
752 modAudioQueueElement element;
753 int activeStreamCount = out->activeStreamCount;
754
755 xsmcVars(1);
756
757 streamIndex = xsmcToInteger(xsArg(0));
758 if ((streamIndex < 0) || (streamIndex >= out->streamCount))
759 xsRangeError("invalid stream");
760 stream = &out->stream[streamIndex];
761
762 kind = xsmcToInteger(xsArg(1));
763 if (kKindFlush != kind) {
764 if (MODDEF_AUDIOOUT_QUEUELENGTH == stream->elementCount)
765 xsUnknownError("queue full");
766 }
767
768 switch (kind) {
769 case kKindSamples:
770 case kKindRawSamples:
771 if (argc > 3) {
772 if ((xsNumberType == xsmcTypeOf(xsArg(3))) && (C_INFINITY == xsmcToNumber(xsArg(3))))
773 repeat = -1;
774 else {
775 repeat = xsmcToInteger(xsArg(3));
776 if (repeat <= 0)
777 xsUnknownError("invalid repeat");
778 }
779 if (argc > 4) {
780 sampleOffset = xsmcToInteger(xsArg(4));
781 if (argc > 5)
782 samplesToUse = xsmcToInteger(xsArg(5));
783 }
784 }
785
786 if (xsBufferNonrelocatable != xsmcGetBufferReadable(xsArg(2), (void **)&buffer, &bufferLength))
787 xsUnknownError("non-relocatable block required");
788
789 if (kKindSamples == kind) {
790 if (('m' != c_read8(buffer + 0)) || ('a' != c_read8(buffer + 1)) || (1 != c_read8(buffer + 2)))
791 xsUnknownError("bad header");
792
793 bitsPerSample = c_read8(buffer + 3);
794 sampleRate = c_read16(buffer + 4);
795 numChannels = c_read8(buffer + 6);
796 sampleFormat = c_read8(buffer + 7);

Callers

nothing calls this directly

Calls 9

doLockFunction · 0.85
sbc_initFunction · 0.85
streamDecompressNextFunction · 0.85
updateActiveStreamsFunction · 0.85
doUnlockFunction · 0.85
queueCallbackFunction · 0.85
invokeCallbacksFunction · 0.85
setStreamVolumeFunction · 0.85
deliverCallbacksFunction · 0.70

Tested by

no test coverage detected