/* ioLoadExternalFunctionOfLengthFromModuleOfLength Entry point for functions looked up through the VM. */ void *ioLoadExternalFunctionOfLengthFromModuleOfLength(sqInt functionNameIndex, sqInt functionNameLength, sqInt moduleNameIndex, sqInt moduleNameLength) { char *functionNamePointer= pointerForIndex_xxx_dmu((usqInt)functionNameIndex); char *moduleNamePointer= pointerForIndex_xxx_dmu((usqInt)moduleNameIndex); char functionName[256]; char moduleName[256]; sqInt i; if(functionNameLength > 255 || moduleNameLength > 255) return 0; /* can't cope with those */ for(i=0; i< functionNameLength; i++) functionName[i] = functionNamePointer[i]; functionName[functionNameLength] = 0; for(i=0; i< moduleNameLength; i++) moduleName[i] = moduleNamePointer[i]; moduleName[moduleNameLength] = 0; return ioLoadFunctionFrom(functionName, moduleName); }
/* ioUnloadModuleOfLength: Entry point for the interpreter. */ sqInt ioUnloadModuleOfLength(sqInt moduleNameIndex, sqInt moduleNameLength) { char *moduleNamePointer= pointerForIndex_xxx_dmu((usqInt) moduleNameIndex); char moduleName[256]; sqInt i; if(moduleNameLength > 255) return 0; /* can't cope with those */ for(i=0; i< moduleNameLength; i++) moduleName[i] = moduleNamePointer[i]; moduleName[moduleNameLength] = 0; return ioUnloadModule(moduleName); }
sqInt vmPathGetLength(sqInt sqVMPathIndex, sqInt length) { char *stVMPath= (char*)pointerForIndex_xxx_dmu(sqVMPathIndex); int count, i; count= strlen(vmPath); count= (length < count) ? length : count; /* copy the file name into the Squeak string */ for (i= 0; i < count; i++) stVMPath[i]= vmPath[i]; return count; }
sqInt imageNameGetLength(sqInt sqImageNameIndex, sqInt length) { char *sqImageName= (char*)pointerForIndex_xxx_dmu(sqImageNameIndex); int count, i; count= strlen(imageName); count= (length < count) ? length : count; /* copy the file name into the Squeak string */ for (i= 0; i < count; i++) sqImageName[i]= imageName[i]; return count; }
/* ioLoadModuleOfLength This entry point is exclusively for the FFI. It does *NOT* call any of the initializers nor does it attempt to lookup stuff internally. */ void *ioLoadModuleOfLength(sqInt moduleNameIndex, sqInt moduleNameLength) { ModuleEntry *module; char *moduleNamePointer= pointerForIndex_xxx_dmu((usqInt)moduleNameIndex); char moduleName[256]; sqInt i; if(moduleNameLength > 255) return 0; /* can't cope with those */ for(i=0; i< moduleNameLength; i++) moduleName[i] = moduleNamePointer[i]; moduleName[moduleNameLength] = 0; module = findOrLoadModule(moduleName, 1); if(module) return module->handle; return 0; }
/* ioLoadSymbolOfLengthFromModule This entry point is exclusively for the FFI. */ void *ioLoadSymbolOfLengthFromModule(sqInt functionNameIndex, sqInt functionNameLength, void *moduleHandle) { char *functionNamePointer= pointerForIndex_xxx_dmu((usqInt)functionNameIndex); char functionName[256]; sqInt i; if(functionNameLength > 255) return 0; /* can't cope with those */ for(i=0; i< functionNameLength; i++) functionName[i] = functionNamePointer[i]; functionName[functionNameLength] = 0; if(moduleHandle) return ioFindExternalFunctionIn(functionName, moduleHandle); else return 0; }
sqInt imageNamePutLength(sqInt sqImageNameIndex, sqInt length) { char *sqImageName= (char*)pointerForIndex_xxx_dmu(sqImageNameIndex); int count, i; count= (IMAGE_NAME_SIZE < length) ? IMAGE_NAME_SIZE : length; /* copy the file name into a null-terminated C string */ for (i= 0; i < count; i++) imageName[i]= sqImageName[i]; imageName[count]= 0; dpy->winSetName(imageName); return count; }
static sqInt sound_RecordSamplesIntoAtLength(sqInt buf, sqInt startSliceIndex, sqInt bufferSizeInBytes) { if (input) { if (Buffer_avail(input->buffer) >= (512 * DeviceFrameSize)) { int start= startSliceIndex * SqueakFrameSize / 2; UInt32 count= min(input->cvtBufSize, bufferSizeInBytes - start); if (kAudioHardwareNoError == AudioConverterFillBuffer(input->converter, bufferDataProc, input, &count, pointerForIndex_xxx_dmu(buf) + start)) return count / (SqueakFrameSize / 2) / input->channels; } return 0; } success(false); return 0; }
// play (exactly) frameCount of samples (and no less, since the result is // ignored). // static sqInt sound_PlaySamplesFromAtLength(sqInt frameCount, sqInt arrayIndex, sqInt startIndex) { if (output) { int byteCount= frameCount * SqueakFrameSize; if (Buffer_free(output->buffer) >= byteCount) { Buffer_write(output->buffer, pointerForIndex_xxx_dmu(arrayIndex) + (startIndex * SqueakFrameSize), byteCount); return frameCount; } return 0; } success(false); return 8192; }
// insert up to frameCount (and no less than frameCount/2 -- see SoundPlayer // class>>startPlayingImmediately: for the [bogus] reasons why) frames into // the front and back buffers, leaving some number of framesOfLeadTime // intact before starging the insertion. (this last parameter is // meaningless for us and could be reduced to zero, but ignoring it causes // strange things to happen. time to rething the image code, methinks.) // // Note: this is only used when the "sound quick start" preference is // enabled in the image. // static sqInt sound_InsertSamplesFromLeadTime(sqInt frameCount, sqInt srcBufPtr, sqInt framesOfLeadTime) { Stream *s= output; DPRINTF("snd_InsertSamples %d From %p LeadTime %d\n", frameCount, srcBufPtr, framesOfLeadTime); if (s) { // data already sent to the device is lost forever, although latency // is only a few hundred frames (and is certainly much lower than the // standard value of `framesOfLeadTime'). instead of putzing around // why not just mix the samples in right away, leaving one h/w // buffer's worth of lead time in case we're interrupted in the // middle? char *frontData= 0, *backData= 0; int frontFrames= 0, backFrames= 0; int framesDone= 0; int leadBytes; # if (OBEY_LEAD_TIME) { AudioTimeStamp timeStamp; u_int64_t then, now; timeStamp.mFlags= kAudioTimeStampHostTimeValid; checkError(AudioDeviceGetCurrentTime(s->id, &timeStamp), "AudioDeviceGetCurrentTime", ""); now= AudioConvertHostTimeToNanos(timeStamp.mHostTime) / 1000ull; then= s->timestamp; leadBytes= ( ((now - then) * (u_int64_t)s->sampleRate) / 1000000ull + framesOfLeadTime ) * SqueakFrameSize; } # else { leadBytes= s->devBufSize; // quantum shipped to the hardware } # endif { int availBytes; int byteCount= frameCount * SqueakFrameSize; Buffer_getOutputPointers(s->buffer, &frontData, &frontFrames, // bytes! &backData, &backFrames); // bytes! availBytes= frontFrames + backFrames; // don't consume more than frameCount - 1 frames leadBytes= max(leadBytes, availBytes - byteCount + SqueakFrameSize); assert((availBytes - leadBytes) < (byteCount)); if (leadBytes < frontFrames) // skip leadBytes into first fragment { frontData += leadBytes; frontFrames -= leadBytes; } else // omit the first fragment { leadBytes -= frontFrames; // lead in second fragment frontFrames= 0; backData += leadBytes; // skip leadBytes into second fragment backFrames -= leadBytes; } frontFrames /= SqueakFrameSize; backFrames /= SqueakFrameSize; } assert((frontFrames + backFrames) < frameCount); // avoid bug in image if ((frontFrames + backFrames) >= (frameCount / 2)) { mixFrames((short *)frontData, (short *)pointerForIndex_xxx_dmu(srcBufPtr), frontFrames); srcBufPtr += frontFrames * SqueakFrameSize; mixFrames((short *)backData, (short *)pointerForIndex_xxx_dmu(srcBufPtr), backFrames); framesDone= frontFrames + backFrames; } return framesDone; } success(false); return frameCount; }
sqInt getAttributeIntoLength(sqInt id, sqInt byteArrayIndex, sqInt length) { if (length > 0) strncpy((char*)pointerForIndex_xxx_dmu(byteArrayIndex), getAttribute(id), length); return 0; }