Beispiel #1
0
primitiveOSFileHandle(void)
{
    sqInt fileNo;
    sqInt sqFileOop;

	sqFileOop = stackValue(0);
	if (!((((isBytes(sqFileOop))
		 && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile))))
		 && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop)))))
		 && (isNonNullSQFile(sqFileOop)))) {
		return primitiveFail();
	}
	/* begin fileDescriptorFrom: */
	if (!((((isBytes(sqFileOop))
		 && ((byteSizeOf(sqFileOop)) == (sizeof(SQFile))))
		 && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(sqFileOop)))))
		 && (isNonNullSQFile(sqFileOop)))) {
		fileNo = -1;
		goto l1;
	}
	fileNo = fileno(fileHandleFrom(sqFileOop));
l1:	/* end fileDescriptorFrom: */;
	pop(2);
	pushInteger(fileNo);
	return 0;
}
Beispiel #2
0
primPCREExec(void)
{
	sqInt extraObj;
	sqInt length;
	int *matchSpacePtr;
	sqInt matchSpaceSize;
	sqInt result;
	char *searchBuffer;
	sqInt searchObject;


	/* Load Parameters */
	searchObject = stackObjectValue(0);
	searchBuffer = arrayValueOf(searchObject);
	length = byteSizeOf(searchObject);
	/* begin loadRcvrFromStackAt: */
	rcvr = stackObjectValue(1);
	pcrePtr = ((sqInt) (fetchArrayofObject(2, rcvr)));
	/* begin rcvrExtraPtr */
	extraObj = fetchPointerofObject(3, rcvr);
	extraPtr = ((sqInt) ((!(extraObj == (nilObject()))
	? arrayValueOf(extraObj)
	: 0)));
	matchFlags = fetchIntegerofObject(6, rcvr);
	matchSpacePtr = ((int *) (fetchArrayofObject(7, rcvr)));
	matchSpaceSize = (byteSizeOf(fetchPointerofObject(7, rcvr))) / 4;
	if (failed()) {
		return null;
	}
	result = pcre_exec((pcre *)pcrePtr, (pcre_extra *)extraPtr, 
				searchBuffer, length, 0, matchFlags, matchSpacePtr, matchSpaceSize);
	pop(2);
	pushInteger(result);
		return 0;
}
Beispiel #3
0
primPCREExecfromto(void)
{
	sqInt extraObj;
	sqInt fromInteger;
	sqInt length;
	int *matchSpacePtr;
	sqInt matchSpaceSize;
	sqInt result;
	char *searchBuffer;
	sqInt searchObject;
	sqInt toInteger;


	/* Load Parameters */
	toInteger = stackIntegerValue(0);
	fromInteger = stackIntegerValue(1);
	searchObject = stackObjectValue(2);
	searchBuffer = arrayValueOf(searchObject);
	length = byteSizeOf(searchObject);
	/* begin loadRcvrFromStackAt: */
	rcvr = stackObjectValue(3);
	success(1 <= fromInteger);
	success(toInteger <= length);

	/* Smalltalk offsets are 1-based */
	fromInteger -= 1;
	success(fromInteger <= toInteger);
	length = toInteger - fromInteger;

	/* Load Instance Variables */
	searchBuffer += fromInteger;
	pcrePtr = ((sqInt) (fetchArrayofObject(2, rcvr)));
	/* begin rcvrExtraPtr */
	extraObj = fetchPointerofObject(3, rcvr);
	extraPtr = ((sqInt) ((!(extraObj == (nilObject()))
	? arrayValueOf(extraObj)
	: 0)));
	matchFlags = fetchIntegerofObject(6, rcvr);
	matchSpacePtr = ((int *) (fetchArrayofObject(7, rcvr)));
	matchSpaceSize = (byteSizeOf(fetchPointerofObject(7, rcvr))) / 4;
	if (failed()) {
		return null;
	}
	result = pcre_exec((pcre *)pcrePtr, (pcre_extra *)extraPtr, 
				searchBuffer, length, 0, matchFlags, matchSpacePtr, matchSpaceSize);
	pop(4);
	pushInteger(result);
		return 0;
}
Beispiel #4
0
primitiveErrorAndLog(void)
{
	char *log;
	sqInt logLen;
	sqInt logObj;
	char *logObjData;
	sqInt resultObj;

	logLen = 0;
	log = getlog((&logLen));
	resultObj = instantiateClassindexableSize(classArray(), 2);
	if (resultObj == 0) {
		primitiveFailFor(PrimErrNoMemory);
		return null;
	}
	storePointerofObjectwithValue(0, resultObj, integerObjectOf(errorAcorn()));
	if (logLen > 0) {
		pushRemappableOop(resultObj);
		logObj = instantiateClassindexableSize(classString(), logLen);
		if (failed()) {
			popRemappableOop();
			primitiveFailFor(PrimErrNoMemory);
			return null;
		}
		resultObj = popRemappableOop();
		logObjData = arrayValueOf(logObj);
		memcpy(logObjData, log, logLen);
		storePointerofObjectwithValue(1, resultObj, logObj);
	}
	popthenPush(1, resultObj);
	if (failed()) {
		return null;
	}
	return null;
}
Beispiel #5
0
	/* AioPlugin>>#fileHandleFrom: */
static FILEHANDLETYPE
fileHandleFrom(sqInt sqFileStructByteArray)
{
    SQFile *sqFile;

	sqFile = arrayValueOf(sqFileStructByteArray);
	return sqFile->file;
}
Beispiel #6
0
	/* AioPlugin>>#isSQFileObject: */
static sqInt
isSQFileObject(sqInt objectPointer)
{
	return (((isBytes(objectPointer))
	 && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))
	 && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(objectPointer)))))
	 && (isNonNullSQFile(objectPointer));
}
Beispiel #7
0
primitiveDisassembleAtInMemory(void)
{
	usqIntptr_t address;
	void *cpu;
	sqInt cpuAlien;
	sqInt instrLenOrErr;
	sqInt log;
	sqInt logLen;
	sqInt logObj;
	sqInt logObjData;
	char *memory;
	sqInt resultObj;

	logLen = 0;
	address = (BytesPerOop == 4
		? positive32BitValueOf(stackValue(1))
		: positive64BitValueOf(stackValue(1)));
	success(isWordsOrBytes(stackValue(0)));
	memory = ((char *) (firstIndexableField(stackValue(0))));
	cpuAlien = stackValue(2);
	if (failed()) {
		return null;
	}
	if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0
		? (cpuAlien + BaseHeaderSize) + BytesPerOop
		: longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) {
		primitiveFailFor(PrimErrBadReceiver);
		return null;
	}
	instrLenOrErr = disassembleForAtInSize(cpu, address, memory, byteSizeOf(((sqInt)(sqIntptr_t)(memory) - BaseHeaderSize)));
	if (instrLenOrErr < 0) {
		primitiveFailFor(PrimErrInappropriate);
		return null;
	}
	log = getlog((&logLen));
	resultObj = instantiateClassindexableSize(classArray(), 2);
	if (resultObj == 0) {
		primitiveFailFor(PrimErrNoMemory);
		return null;
	}
	pushRemappableOop(resultObj);
	logObj = instantiateClassindexableSize(classString(), logLen);
	if (failed()) {
		popRemappableOop();
		primitiveFailFor(PrimErrNoMemory);
		return null;
	}
	logObjData = arrayValueOf(logObj);
	memcpy(logObjData, log, logLen);
	resultObj = popRemappableOop();
	storePointerofObjectwithValue(0, resultObj, integerObjectOf(instrLenOrErr));
	storePointerofObjectwithValue(1, resultObj, logObj);
	if (failed()) {
		return null;
	}
	popthenPush(3, resultObj);
	return null;
}
Beispiel #8
0
EXPORT(sqInt) primitiveCompressToByteArray(void) {
    sqInt eqBytes;
    sqInt i;
    sqInt j;
    sqInt k;
    sqInt lowByte;
    sqInt m;
    sqInt size;
    sqInt word;
    sqInt j1;
    sqInt j2;
    sqInt j3;
    sqInt j4;
    sqInt j5;
    sqInt j6;
    sqInt j7;
    sqInt rcvr;
    int *bm;
    unsigned char *ba;

	rcvr = stackValue(2);
	bm = arrayValueOf(stackValue(1));
	bm -= 1;
	if (!(isBytes(stackValue(0)))) {
		return primitiveFail();
	}
	ba = arrayValueOf(stackValue(0));
	ba -= 1;
	if (!(successFlag)) {
		return null;
	}
	size = sizeOfSTArrayFromCPrimitive(bm + 1);
	/* begin encodeInt:in:at: */
	if (size <= 223) {
		ba[1] = size;
		i = 1 + 1;
		goto l5;
	}
	if (size <= 7935) {
		ba[1] = ((((sqInt) size >> 8)) + 224);
		ba[1 + 1] = (size % 256);
		i = 1 + 2;
		goto l5;
	}
Beispiel #9
0
	/* RePlugin>>#rcvrExtraPtr */
static sqInt
rcvrExtraPtr(void)
{
	sqInt extraObj;

	extraObj = fetchPointerofObject(3, rcvr);
	return ((sqInt) ((!(extraObj == (nilObject()))
	? arrayValueOf(extraObj)
	: 0)));
}
Beispiel #10
0
	/* AioPlugin>>#stringFromCString: */
static sqInt
stringFromCString(const char *aCString)
{
    sqInt len;
    sqInt newString;

	len = strlen(aCString);
	newString = instantiateClassindexableSize(classString(), len);
	strncpy(arrayValueOf(newString), aCString, len);
	return newString;
}
Beispiel #11
0
	/* AioPlugin>>#fileDescriptorFrom: */
static sqInt
fileDescriptorFrom(sqInt aSQFileByteArray)
{
	if (!((((isBytes(aSQFileByteArray))
		 && ((byteSizeOf(aSQFileByteArray)) == (sizeof(SQFile))))
		 && ((getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(aSQFileByteArray)))))
		 && (isNonNullSQFile(aSQFileByteArray)))) {
		return -1;
	}
	return fileno(fileHandleFrom(aSQFileByteArray));
}
Beispiel #12
0
	/* AioPlugin>>#socketDescriptorFrom: */
static int
socketDescriptorFrom(sqInt sqSocketOop)
{
    void *privateSocketStruct;
    SQSocket *sqSocket;

	/* begin socketValueOf: */
	sqSocket = arrayValueOf(sqSocketOop);
	privateSocketStruct = sqSocket->privateSocketPtr;
	if (privateSocketStruct == 0) {
		return -1;
	}
	return * (int *) privateSocketStruct;
}
Beispiel #13
0
	/* AioPlugin>>#isNullSQSocket: */
static sqInt
isNullSQSocket(sqInt objectPointer)
{
    sqInt idx;
    unsigned char *sqSocketBytes;

	sqSocketBytes = arrayValueOf(objectPointer);
	idx = 0;
	while (idx < (sizeof(SQSocket))) {
		if ((sqSocketBytes[idx]) != 0) {
			return 0;
		}
		idx += 1;
	}
	return 1;
}
Beispiel #14
0
	/* AioPlugin>>#isNonNullSQFile: */
static sqInt
isNonNullSQFile(sqInt objectPointer)
{
    unsigned idx;
    unsigned char *sqFileBytes;

	sqFileBytes = arrayValueOf(objectPointer);
	idx = 0;
	while (idx < (sizeof(SQFile))) {
		if ((sqFileBytes[idx]) != 0) {
			return 1;
		}
		idx += 1;
	}
	return 0;
}
Beispiel #15
0
	/* RePlugin>>#allocateByteArrayAndSetRcvrPCREPtrFromPCRE: */
static sqInt
allocateByteArrayAndSetRcvrPCREPtrFromPCRE(sqInt aPCREPtr)
{
	void *patByteArrayPtr;
	sqInt patObject;


	/* Allocate a Smalltalk ByteArray -- lastAlloc contains the length */
	patObject = instantiateClassindexableSize(classByteArray(), lastAlloc);
	/* begin loadRcvrFromStackAt: */
	rcvr = stackObjectValue(0);
	patByteArrayPtr = arrayValueOf(patObject);
	memcpy(patByteArrayPtr, (void *) aPCREPtr, lastAlloc);
	/* begin rcvrPCREBufferFrom: */
	storePointerofObjectwithValue(2, rcvr, patObject);
	return patObject;
}
Beispiel #16
0
	/* RePlugin>>#allocateStringAndSetRcvrErrorStrFromCStr: */
static sqInt
allocateStringAndSetRcvrErrorStrFromCStr(const char *aCStrBuffer)
{
	sqInt errorStrObj;
	void *errorStrObjPtr;
	sqInt length;


	/* Allocate errorStrObj */
	length = strlen(aCStrBuffer);
	errorStrObj = instantiateClassindexableSize(classString(), length);
	/* begin loadRcvrFromStackAt: */
	rcvr = stackObjectValue(0);
	errorStrObjPtr = arrayValueOf(errorStrObj);
	memcpy(errorStrObjPtr,aCStrBuffer,length);
	/* begin rcvrErrorStrFrom: */
	storePointerofObjectwithValue(4, rcvr, errorStrObj);
	return errorStrObj;
}
Beispiel #17
0
	/* RePlugin>>#allocateByteArrayAndSetRcvrExtraPtrFrom: */
static sqInt
allocateByteArrayAndSetRcvrExtraPtrFrom(sqInt anExtraPtr)
{
	void *extraByteArrayPtr;
	sqInt extraObject;

	extraByteArrayPtr = 0;
	if (anExtraPtr) {

		/* Allocate a Smalltalk ByteArray -- lastAlloc contains the length */
		extraObject = instantiateClassindexableSize(classByteArray(), sizeof(real_pcre_extra));
		/* begin loadRcvrFromStackAt: */
		rcvr = stackObjectValue(0);
		extraByteArrayPtr = arrayValueOf(extraObject);
		memcpy(extraByteArrayPtr, (void *) anExtraPtr, sizeof(real_pcre_extra));
	}
	else {
		extraObject = nilObject();
	}
	/* begin rcvrExtraPtrFrom: */
	storePointerofObjectwithValue(3, rcvr, extraObject);
	return extraObject;
}
Beispiel #18
0
EXPORT(sqInt) primitiveCompareString(void) {
    sqInt c1;
    sqInt c2;
    sqInt i;
    sqInt len1;
    sqInt len2;
    sqInt rcvr;
    unsigned char *string1;
    unsigned char *string2;
    unsigned char *order;

	rcvr = stackValue(3);
	if (!(isBytes(stackValue(2)))) {
		return primitiveFail();
	}
	string1 = arrayValueOf(stackValue(2));
	string1 -= 1;
	if (!(isBytes(stackValue(1)))) {
		return primitiveFail();
	}
	string2 = arrayValueOf(stackValue(1));
	string2 -= 1;
	if (!(isBytes(stackValue(0)))) {
		return primitiveFail();
	}
	order = arrayValueOf(stackValue(0));
	order -= 1;
	if (!(successFlag)) {
		return null;
	}
	len1 = sizeOfSTArrayFromCPrimitive(string1 + 1);
	len2 = sizeOfSTArrayFromCPrimitive(string2 + 1);
	for (i = 1; i <= (((len1 < len2) ? len1 : len2)); i += 1) {
		c1 = order[(string1[i]) + 1];
		c2 = order[(string2[i]) + 1];
		if (!(c1 == c2)) {
			if (c1 < c2) {
				if (!(successFlag)) {
					return null;
				}
				pop(4);
				pushInteger(1);
				return null;
			} else {
				if (!(successFlag)) {
					return null;
				}
				pop(4);
				pushInteger(3);
				return null;
			}
		}
	}
	if (len1 == len2) {
		if (!(successFlag)) {
			return null;
		}
		pop(4);
		pushInteger(2);
		return null;
	}
	if (len1 < len2) {
		if (!(successFlag)) {
			return null;
		}
		pop(4);
		pushInteger(1);
		return null;
	} else {
		if (!(successFlag)) {
			return null;
		}
		pop(4);
		pushInteger(3);
		return null;
	}
	if (!(successFlag)) {
		return null;
	}
	pop(3);
	return null;
}
Beispiel #19
0
	/* AioPlugin>>#socketValueOf: */
static SQSocket *
socketValueOf(sqInt anSQSocketRecord)
{
	return arrayValueOf(anSQSocketRecord);
}
primitiveExecutableModulesAndOffsets(void)
{
    const struct mach_header *h;
    const struct mach_header_64 *h64;
    sqInt i;
    const char *name;
    char *nameObjData;
    sqInt nimages;
    sqInt resultObj;
    const struct section *s;
    const struct section_64 *s64;
    usqIntptr_t size;
    usqIntptr_t slide;
    usqIntptr_t start;
    sqInt valueObj;

	
#  if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4

	/* _dyld_present was deprecated in 10.5 */
	if (!(_dyld_present())) {
		return primitiveFail();
	}

#  endif /* MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 */

	nimages = _dyld_image_count();
	resultObj = instantiateClassindexableSize(classArray(), nimages * 4);
	if (resultObj == 0) {
		return primitiveFail();
	}
	pushRemappableOop(resultObj);
	for (i = 0; i < nimages; i += 1) {

		/* impossible start & size */
		start = (size = -1);
		name = _dyld_get_image_name(i);
		slide = _dyld_get_image_vmaddr_slide(i);
		
#    if __x86_64__
		h64 = (const struct mach_header_64 *)_dyld_get_image_header(i);
		if (!(h64 == null)) {
			s64 = getsectbynamefromheader_64(h64,SEG_TEXT,SECT_TEXT);
			if (!(s64 == null)) {
				start = s64->addr;
				size = s64->size;
			}
		}

#    else /* __x86_64__ */
		h = _dyld_get_image_header(i);
		if (!(h == null)) {
			s = getsectbynamefromheader(h,SEG_TEXT,SECT_TEXT);
			if (!(s == null)) {
				start = s->addr;
				size = s->size;
			}
		}

#    endif /* __x86_64__ */

		valueObj = instantiateClassindexableSize(classString(), strlen(name));
		if (failed()) {
			popRemappableOop();
			return primitiveFail();
		}
		storePointerofObjectwithValue(i * 4, topRemappableOop(), valueObj);
		nameObjData = arrayValueOf(valueObj);
		memcpy(nameObjData, name, strlen(name));
		valueObj = (BytesPerWord == 8
			? signed64BitIntegerFor(slide)
			: signed32BitIntegerFor(slide));
		if (failed()) {
			popRemappableOop();
			return primitiveFail();
		}
		storePointerofObjectwithValue((i * 4) + 1, topRemappableOop(), valueObj);
		/* begin positiveMachineIntegerFor: */
		valueObj = (BytesPerWord == 8
			? positive64BitIntegerFor(start)
			: positive32BitIntegerFor(start));
		if (failed()) {
			popRemappableOop();
			return primitiveFail();
		}
		storePointerofObjectwithValue((i * 4) + 2, topRemappableOop(), valueObj);
		/* begin positiveMachineIntegerFor: */
		valueObj = (BytesPerWord == 8
			? positive64BitIntegerFor(size)
			: positive32BitIntegerFor(size));
		if (failed()) {
			popRemappableOop();
			return primitiveFail();
		}
		storePointerofObjectwithValue((i * 4) + 3, topRemappableOop(), valueObj);
	}
	resultObj = popRemappableOop();
	return popthenPush(1, resultObj);
}
Beispiel #21
0
	/* AioPlugin>>#isValidFileSession: */
static sqInt
isValidFileSession(sqInt objectPointer)
{
	return (getThisSessionID()) == (sessionIdentifierFromSqFile(arrayValueOf(objectPointer)));
}
Beispiel #22
0
	/* AioPlugin>>#fileValueOf: */
static SQFile *
fileValueOf(sqInt anSQFileRecord)
{
	return arrayValueOf(anSQFileRecord);
}
Beispiel #23
0
int primPluckedSoundmixSampleCountintostartingAtpan(void) {
    int rcvr;
    int n;
    short int *aSoundBuffer;
    int startIndex;
    int pan;
    int lastIndex;
    int channelIndex;
    int i;
    int sample;
    int mySample;
    int thisIndex;
    int nextIndex;
    int count;
    short int *ring;
    int ringSize;
    int ringIndx;

	rcvr = stackValue(4);
	n = checkedIntegerValueOf(stackValue(3));
	aSoundBuffer = arrayValueOf(stackValue(2));
	startIndex = checkedIntegerValueOf(stackValue(1));
	pan = checkedIntegerValueOf(stackValue(0));
	count = fetchIntegerofObject(2, rcvr);
	ring = fetchArrayofObject(4, rcvr);
	ringSize = fetchIntegerofObject(5, rcvr);
	ringIndx = fetchIntegerofObject(6, rcvr);
	if (!(successFlag)) {
		return null;
	}
	lastIndex = (startIndex + n) - 1;
	thisIndex = ringIndx;
	for (i = startIndex; i <= lastIndex; i += 1) {
		nextIndex = (thisIndex % ringSize) + 1;
		mySample = ((ring[thisIndex - 1]) + (ring[nextIndex - 1])) / 2;
		ring[thisIndex - 1] = mySample;
		thisIndex = nextIndex;
		if (pan > 0) {
			channelIndex = 2 * i;
			sample = (aSoundBuffer[channelIndex - 1]) + ((mySample * pan) / 1000);
			if (sample > 32767) {
				sample = 32767;
			}
			if (sample < -32767) {
				sample = -32767;
			}
			aSoundBuffer[channelIndex - 1] = sample;
		}
		if (pan < 1000) {
			channelIndex = (2 * i) - 1;
			sample = (aSoundBuffer[channelIndex - 1]) + ((mySample * (1000 - pan)) / 1000);
			if (sample > 32767) {
				sample = 32767;
			}
			if (sample < -32767) {
				sample = -32767;
			}
			aSoundBuffer[channelIndex - 1] = sample;
		}
	}
	ringIndx = nextIndex;
	count -= n;
	storeIntegerofObjectwithValue(2, rcvr, count);
	storeIntegerofObjectwithValue(6, rcvr, ringIndx);
	pop(4);
}
Beispiel #24
0
int primWaveTableSoundmixSampleCountintostartingAtpan(void) {
    int rcvr;
    int n;
    short int *aSoundBuffer;
    int startIndex;
    int pan;
    int lastIndex;
    int channelIndex;
    int i;
    int mySample;
    int sample;
    short int *waveTable;
    int waveTableSize;
    int count;
    int amplitude;
    int increment;
    int index;

	rcvr = stackValue(4);
	n = checkedIntegerValueOf(stackValue(3));
	aSoundBuffer = arrayValueOf(stackValue(2));
	startIndex = checkedIntegerValueOf(stackValue(1));
	pan = checkedIntegerValueOf(stackValue(0));
	waveTable = fetchArrayofObject(1, rcvr);
	waveTableSize = fetchIntegerofObject(2, rcvr);
	count = fetchIntegerofObject(4, rcvr);
	amplitude = fetchIntegerofObject(6, rcvr);
	increment = fetchIntegerofObject(8, rcvr);
	index = fetchIntegerofObject(9, rcvr);
	if (!(successFlag)) {
		return null;
	}
	lastIndex = (startIndex + n) - 1;
	for (i = startIndex; i <= lastIndex; i += 1) {
		mySample = (amplitude * (waveTable[index - 1])) / 1000;
		if (pan > 0) {
			channelIndex = 2 * i;
			sample = (aSoundBuffer[channelIndex - 1]) + ((mySample * pan) / 1000);
			if (sample > 32767) {
				sample = 32767;
			}
			if (sample < -32767) {
				sample = -32767;
			}
			aSoundBuffer[channelIndex - 1] = sample;
		}
		if (pan < 1000) {
			channelIndex = (2 * i) - 1;
			sample = (aSoundBuffer[channelIndex - 1]) + ((mySample * (1000 - pan)) / 1000);
			if (sample > 32767) {
				sample = 32767;
			}
			if (sample < -32767) {
				sample = -32767;
			}
			aSoundBuffer[channelIndex - 1] = sample;
		}
		index += increment;
		if (index > waveTableSize) {
			index -= waveTableSize;
		}
	}
	count -= n;
	storeIntegerofObjectwithValue(4, rcvr, count);
	storeIntegerofObjectwithValue(9, rcvr, index);
	pop(4);
}
Beispiel #25
0
int primSampledSoundmixSampleCountintostartingAtpan(void) {
    int rcvr;
    int n;
    short int *aSoundBuffer;
    int startIndex;
    int pan;
    int lastIndex;
    int i;
    int channelIndex;
    int sample;
    int sampleIndex;
    int thisSample;
    short int *samples;
    int samplesSize;
    int incrementTimes1000;
    int count;
    int indexTimes1000;

	rcvr = stackValue(4);
	n = checkedIntegerValueOf(stackValue(3));
	aSoundBuffer = arrayValueOf(stackValue(2));
	startIndex = checkedIntegerValueOf(stackValue(1));
	pan = checkedIntegerValueOf(stackValue(0));
	samples = fetchArrayofObject(1, rcvr);
	samplesSize = fetchIntegerofObject(2, rcvr);
	incrementTimes1000 = fetchIntegerofObject(3, rcvr);
	count = fetchIntegerofObject(5, rcvr);
	indexTimes1000 = fetchIntegerofObject(6, rcvr);
	if (!(successFlag)) {
		return null;
	}
	lastIndex = (startIndex + n) - 1;
	i = startIndex;
	sampleIndex = indexTimes1000 / 1000;
	while ((sampleIndex <= samplesSize) && (i <= lastIndex)) {
		thisSample = samples[sampleIndex - 1];
		if (pan > 0) {
			channelIndex = 2 * i;
			sample = (aSoundBuffer[channelIndex - 1]) + ((thisSample * pan) / 1000);
			if (sample > 32767) {
				sample = 32767;
			}
			if (sample < -32767) {
				sample = -32767;
			}
			aSoundBuffer[channelIndex - 1] = sample;
		}
		if (pan < 1000) {
			channelIndex = (2 * i) - 1;
			sample = (aSoundBuffer[channelIndex - 1]) + ((thisSample * (1000 - pan)) / 1000);
			if (sample > 32767) {
				sample = 32767;
			}
			if (sample < -32767) {
				sample = -32767;
			}
			aSoundBuffer[channelIndex - 1] = sample;
		}
		indexTimes1000 += incrementTimes1000;
		sampleIndex = indexTimes1000 / 1000;
		i += 1;
	}
	count -= n;
	storeIntegerofObjectwithValue(5, rcvr, count);
	storeIntegerofObjectwithValue(6, rcvr, indexTimes1000);
	pop(4);
}