Mercurial > hg > dmlib
comparison jssplr.c @ 188:47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 06 Oct 2012 16:36:39 +0300 |
parents | e59ea366b13d |
children | 06da4e365dc9 |
comparison
equal
deleted
inserted
replaced
187:e59ea366b13d | 188:47c327fb321a |
---|---|
116 | 116 |
117 volume = dmClamp(volume, mpMinVol, mpMaxVol); | 117 volume = dmClamp(volume, mpMinVol, mpMaxVol); |
118 | 118 |
119 //fprintf(stderr, "chn %d: vol=%d, fad=%d, env=%d\n", channel, volume, chn->fadeOutVol, chn->volumeEnv.value); | 119 //fprintf(stderr, "chn %d: vol=%d, fad=%d, env=%d\n", channel, volume, chn->fadeOutVol, chn->volumeEnv.value); |
120 | 120 |
121 if (mp->future == NULL) | 121 jvmSetVolumeRamp(mp->device, channel, |
122 { | 122 init ? 0 : jvmGetVolume(mp->device, channel), |
123 jvmSetVolume(mp->device, channel, | 123 (chn->fadeOutVol * chn->volumeEnv.value * volume) / (16 * 65536), |
124 (chn->fadeOutVol * chn->volumeEnv.value * volume) / (16 * 65536)); | 124 init ? 5 : 0); |
125 } | |
126 else | |
127 if (init) | |
128 { | |
129 jvmSetVolumeRamp(mp->device, channel, | |
130 0, | |
131 jvmGetVolume(mp->future->device, channel), 5); | |
132 } | |
133 else | |
134 { | |
135 jvmSetVolumeRamp(mp->device, channel, | |
136 (chn->fadeOutVol * chn->volumeEnv.value * volume) / (16 * 65536), | |
137 jvmGetVolume(mp->future->device, channel), 0); | |
138 } | |
139 } | 125 } |
140 | 126 |
141 | 127 |
142 static void jmpCSetPanning(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int panning) | 128 static void jmpCSetPanning(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int panning) |
143 { | 129 { |
144 assert(mp != NULL); | 130 assert(mp != NULL); |
145 assert(mp->device != NULL); | 131 assert(mp->device != NULL); |
146 | 132 |
147 if (mp->future == NULL) | 133 jvmSetPanRamp(mp->device, channel, |
148 { | 134 jvmGetPan(mp->device, channel), |
149 jvmSetPan(mp->device, channel, | 135 panning + (((chn->panningEnv.value - 32) * (128 - abs(panning - 128))) / 32), |
150 panning + (((chn->panningEnv.value - 32) * (128 - abs(panning - 128))) / 32)); | 136 0); |
151 } | |
152 else | |
153 { | |
154 jvmSetPanRamp(mp->device, channel, | |
155 panning + (((chn->panningEnv.value - 32) * (128 - abs(panning - 128))) / 32), | |
156 jvmGetPan(mp->future->device, channel), 0); | |
157 } | |
158 } | 137 } |
159 | 138 |
160 | 139 |
161 static BOOL jmpExecEnvelope(JSSEnvelope *env, JSSPlayerEnvelope *pe, BOOL keyOff) | 140 static BOOL jmpExecEnvelope(JSSEnvelope *env, JSSPlayerEnvelope *pe, BOOL keyOff) |
162 { | 141 { |
296 // Allocate a player structure | 275 // Allocate a player structure |
297 mp = dmMalloc0(sizeof(JSSPlayer)); | 276 mp = dmMalloc0(sizeof(JSSPlayer)); |
298 if (mp == NULL) | 277 if (mp == NULL) |
299 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate memory for player structure.\n"); | 278 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate memory for player structure.\n"); |
300 | 279 |
301 mp->future = dmMalloc0(sizeof(JSSPlayer)); | |
302 if (mp->future == NULL) | |
303 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate memory for player structure.\n"); | |
304 | |
305 // Set variables | 280 // Set variables |
306 mp->device = pDevice; | 281 mp->device = pDevice; |
307 mp->future->device = jvmInit(pDevice->outFormat, pDevice->outChannels, pDevice->outFreq, JMIX_AUTO); | |
308 if (mp->future->device == NULL) | |
309 JSSERROR(DMERR_INIT_FAIL, NULL, "Could not initialize shadow mixing device.\n"); | |
310 | 282 |
311 #ifdef JSS_SUP_THREADS | 283 #ifdef JSS_SUP_THREADS |
312 mp->mutex = dmCreateMutex(); | 284 mp->mutex = dmCreateMutex(); |
313 mp->future->mutex = dmCreateMutex(); | |
314 #endif | 285 #endif |
315 | 286 |
316 return mp; | 287 return mp; |
317 } | 288 } |
318 | 289 |
327 | 298 |
328 // Deallocate resources | 299 // Deallocate resources |
329 #ifdef JSS_SUP_THREADS | 300 #ifdef JSS_SUP_THREADS |
330 dmDestroyMutex(mp->mutex); | 301 dmDestroyMutex(mp->mutex); |
331 #endif | 302 #endif |
332 | |
333 if (mp->future != NULL) | |
334 { | |
335 #ifdef JSS_SUP_THREADS | |
336 dmDestroyMutex(mp->future->mutex); | |
337 #endif | |
338 jvmClose(mp->future->device); | |
339 dmFree(mp->future); | |
340 } | |
341 | 303 |
342 // Clear structure | 304 // Clear structure |
343 memset(mp, 0, sizeof(JSSPlayer)); | 305 memset(mp, 0, sizeof(JSSPlayer)); |
344 dmFree(mp); | 306 dmFree(mp); |
345 | 307 |
400 JSS_LOCK(mp); | 362 JSS_LOCK(mp); |
401 | 363 |
402 jmpStop(mp); | 364 jmpStop(mp); |
403 jmpClearPlayer(mp); | 365 jmpClearPlayer(mp); |
404 | 366 |
405 mp->future->module = mp->module = module; | 367 mp->module = module; |
406 | 368 |
407 JSS_UNLOCK(mp); | 369 JSS_UNLOCK(mp); |
408 } | 370 } |
409 | 371 |
410 | 372 |
417 | 379 |
418 if (mp->isPlaying) | 380 if (mp->isPlaying) |
419 { | 381 { |
420 jvmRemoveCallback(mp->device); | 382 jvmRemoveCallback(mp->device); |
421 mp->isPlaying = FALSE; | 383 mp->isPlaying = FALSE; |
422 | |
423 if (mp->future != NULL) | |
424 jmpStop(mp->future); | |
425 } | 384 } |
426 | 385 |
427 JSS_UNLOCK(mp); | 386 JSS_UNLOCK(mp); |
428 } | 387 } |
429 | 388 |
440 int result = jvmSetCallback(mp->device, jmpExec, (void *) mp); | 399 int result = jvmSetCallback(mp->device, jmpExec, (void *) mp); |
441 if (result != DMERR_OK) | 400 if (result != DMERR_OK) |
442 JSSERROR(result,, "Could not initialize callback for player.\n"); | 401 JSSERROR(result,, "Could not initialize callback for player.\n"); |
443 | 402 |
444 mp->isPlaying = TRUE; | 403 mp->isPlaying = TRUE; |
445 if (mp->future != NULL) | |
446 jmpResume(mp->future); | |
447 } | 404 } |
448 | 405 |
449 JSS_UNLOCK(mp); | 406 JSS_UNLOCK(mp); |
450 } | 407 } |
451 | 408 |
565 JSS_UNLOCK(mp); | 522 JSS_UNLOCK(mp); |
566 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, | 523 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
567 "Could not start playing from given order #%i\n", order); | 524 "Could not start playing from given order #%i\n", order); |
568 } | 525 } |
569 | 526 |
570 if (mp->future != NULL) | |
571 { | |
572 jmpChangeOrder(mp->future, order); | |
573 jmpExec(mp->future->device, mp->future); | |
574 } | |
575 | |
576 JSS_UNLOCK(mp); | 527 JSS_UNLOCK(mp); |
577 return DMERR_OK; | 528 return DMERR_OK; |
578 } | 529 } |
579 | 530 |
580 | 531 |
604 { | 555 { |
605 JSS_UNLOCK(mp); | 556 JSS_UNLOCK(mp); |
606 return result; | 557 return result; |
607 } | 558 } |
608 | 559 |
609 if (mp->future != NULL) | |
610 { | |
611 jmpPlayOrder(mp->future, order); | |
612 jmpExec(mp->future->device, mp->future); | |
613 } | |
614 | |
615 JSS_UNLOCK(mp); | 560 JSS_UNLOCK(mp); |
616 return DMERR_OK; | 561 return DMERR_OK; |
617 } | 562 } |
618 | 563 |
619 | 564 |
634 | 579 |
635 if ((result = jmpPlayStart(mp)) != DMERR_OK) | 580 if ((result = jmpPlayStart(mp)) != DMERR_OK) |
636 { | 581 { |
637 JSS_UNLOCK(mp); | 582 JSS_UNLOCK(mp); |
638 return result; | 583 return result; |
639 } | |
640 | |
641 if (mp->future != NULL) | |
642 { | |
643 jmpPlayPattern(mp->future, pattern); | |
644 jmpExec(mp->future->device, mp->future); | |
645 } | 584 } |
646 | 585 |
647 JSS_UNLOCK(mp); | 586 JSS_UNLOCK(mp); |
648 return DMERR_OK; | 587 return DMERR_OK; |
649 } | 588 } |
1197 chn->ninstrument = tmp; | 1136 chn->ninstrument = tmp; |
1198 chn->instrument = inst; | 1137 chn->instrument = inst; |
1199 chn->volume = inst->volume; | 1138 chn->volume = inst->volume; |
1200 chn->panning = inst->EPanning; | 1139 chn->panning = inst->EPanning; |
1201 chn->position = 0; | 1140 chn->position = 0; |
1202 JMPSETNDFLAGS(cdfPlay | cdfNewPos | cdfNewInstr | cdfNewVolume | cdfNewPanPos); | 1141 JMPSETNDFLAGS(cdfPlay | cdfNewPos | cdfNewInstr | cdfNewPanPos); |
1203 } | 1142 } |
1204 } | 1143 } |
1144 | |
1145 // XXX possibly wrong? | |
1146 JMPSETNDFLAGS(cdfNewVolume); | |
1205 } | 1147 } |
1206 | 1148 |
1207 if (newNote && chn->instrument != NULL) | 1149 if (newNote && chn->instrument != NULL) |
1208 { | 1150 { |
1209 JSSInstrument *inst = chn->instrument; | 1151 JSSInstrument *inst = chn->instrument; |
1392 // Check some things via assert() | 1334 // Check some things via assert() |
1393 mp = (JSSPlayer *) pMP; | 1335 mp = (JSSPlayer *) pMP; |
1394 JSS_LOCK(mp); | 1336 JSS_LOCK(mp); |
1395 | 1337 |
1396 dev = (JSSMixer *) pDEV; | 1338 dev = (JSSMixer *) pDEV; |
1397 | |
1398 // Futures | |
1399 if (mp->future != NULL) | |
1400 { | |
1401 jmpExec(mp->future->device, mp->future); | |
1402 } | |
1403 | 1339 |
1404 // Check if we are playing | 1340 // Check if we are playing |
1405 if (!mp->isPlaying) | 1341 if (!mp->isPlaying) |
1406 goto out; | 1342 goto out; |
1407 | 1343 |