long duh_render( DUH_SIGRENDERER *sigrenderer, int bits, int unsign, float volume, float delta, long size, void *sptr ) { long n; sample_t **sampptr; int n_channels; ASSERT(bits == 8 || bits == 16); ASSERT(sptr); if (!sigrenderer) return 0; n_channels = duh_sigrenderer_get_n_channels(sigrenderer); ASSERT(n_channels > 0); /* This restriction will be removed when need be. At the moment, tightly * optimised loops exist for exactly one or two channels. */ ASSERT(n_channels <= 2); sampptr = allocate_sample_buffer(n_channels, size); if (!sampptr) return 0; dumb_silence(sampptr[0], n_channels * size); size = duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size, sampptr); if (bits == 16) { int signconv = unsign ? 0x8000 : 0x0000; for (n = 0; n < size * n_channels; n++) { CONVERT16(sampptr[0][n], n, signconv); } } else { char signconv = unsign ? 0x80 : 0x00; for (n = 0; n < size * n_channels; n++) { CONVERT8(sampptr[0][n], n, signconv); } } destroy_sample_buffer(sampptr); return size; }
JNIEXPORT void JNICALL Java_jpcsp_memory_NativeMemoryUtils_write16(JNIEnv * env, jclass self, jlong memory, jint address, jint value) { CONVERT16(value); unsigned short *p16 = (void *) memory + (address & ~1); *p16 = (unsigned short) value; }
JNIEXPORT jint JNICALL Java_jpcsp_memory_NativeMemoryUtils_read16(JNIEnv * env, jclass self, jlong memory, jint address) { unsigned short *p16 = (void *) memory + (address & ~1); unsigned short value = *p16; CONVERT16(value); return value; }