effect_position.c
changeset 718 fb0562cc1559
parent 711 f40c5ac95b12
child 725 bdf7b8d20566
equal deleted inserted replaced
717:27eb690edafc 718:fb0562cc1559
    29 #include <stdio.h>
    29 #include <stdio.h>
    30 #include <stdlib.h>
    30 #include <stdlib.h>
    31 #include <string.h>
    31 #include <string.h>
    32 
    32 
    33 #include "SDL.h"
    33 #include "SDL.h"
       
    34 #include "SDL_endian.h"
    34 #include "SDL_mixer.h"
    35 #include "SDL_mixer.h"
    35 #include "SDL_endian.h"
    36 #include "mixer.h"
    36 
    37 
    37 #define __MIX_INTERNAL_EFFECT__
    38 #define __MIX_INTERNAL_EFFECT__
    38 #include "effects_internal.h"
    39 #include "effects_internal.h"
    39 
    40 
    40 /* profile code:
    41 /* profile code:
  1451 
  1452 
  1452     f = get_position_effect_func(format, channels);
  1453     f = get_position_effect_func(format, channels);
  1453     if (f == NULL)
  1454     if (f == NULL)
  1454         return(0);
  1455         return(0);
  1455 
  1456 
  1456     SDL_LockAudio();
  1457     Mix_LockAudio();
  1457     args = get_position_arg(channel);
  1458     args = get_position_arg(channel);
  1458     if (!args) {
  1459     if (!args) {
  1459         SDL_UnlockAudio();
  1460         Mix_UnlockAudio();
  1460         return(0);
  1461         return(0);
  1461     }
  1462     }
  1462 
  1463 
  1463         /* it's a no-op; unregister the effect, if it's registered. */
  1464         /* it's a no-op; unregister the effect, if it's registered. */
  1464     if ((args->distance_u8 == 255) && (left == 255) && (right == 255)) {
  1465     if ((args->distance_u8 == 255) && (left == 255) && (right == 255)) {
  1465         if (args->in_use) {
  1466         if (args->in_use) {
  1466             retval = _Mix_UnregisterEffect_locked(channel, f);
  1467             retval = _Mix_UnregisterEffect_locked(channel, f);
  1467             SDL_UnlockAudio();
  1468             Mix_UnlockAudio();
  1468             return(retval);
  1469             return(retval);
  1469         } else {
  1470         } else {
  1470             SDL_UnlockAudio();
  1471             Mix_UnlockAudio();
  1471             return(1);
  1472             return(1);
  1472         }
  1473         }
  1473     }
  1474     }
  1474 
  1475 
  1475     args->left_u8 = left;
  1476     args->left_u8 = left;
  1481     if (!args->in_use) {
  1482     if (!args->in_use) {
  1482         args->in_use = 1;
  1483         args->in_use = 1;
  1483         retval=_Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void*)args);
  1484         retval=_Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void*)args);
  1484     }
  1485     }
  1485 
  1486 
  1486     SDL_UnlockAudio();
  1487     Mix_UnlockAudio();
  1487     return(retval);
  1488     return(retval);
  1488 }
  1489 }
  1489 
  1490 
  1490 
  1491 
  1491 int Mix_SetDistance(int channel, Uint8 distance)
  1492 int Mix_SetDistance(int channel, Uint8 distance)
  1499     Mix_QuerySpec(NULL, &format, &channels);
  1500     Mix_QuerySpec(NULL, &format, &channels);
  1500     f = get_position_effect_func(format, channels);
  1501     f = get_position_effect_func(format, channels);
  1501     if (f == NULL)
  1502     if (f == NULL)
  1502         return(0);
  1503         return(0);
  1503 
  1504 
  1504     SDL_LockAudio();
  1505     Mix_LockAudio();
  1505     args = get_position_arg(channel);
  1506     args = get_position_arg(channel);
  1506     if (!args) {
  1507     if (!args) {
  1507         SDL_UnlockAudio();
  1508         Mix_UnlockAudio();
  1508         return(0);
  1509         return(0);
  1509     }
  1510     }
  1510 
  1511 
  1511     distance = 255 - distance;  /* flip it to our scale. */
  1512     distance = 255 - distance;  /* flip it to our scale. */
  1512 
  1513 
  1513         /* it's a no-op; unregister the effect, if it's registered. */
  1514         /* it's a no-op; unregister the effect, if it's registered. */
  1514     if ((distance == 255) && (args->left_u8 == 255) && (args->right_u8 == 255)) {
  1515     if ((distance == 255) && (args->left_u8 == 255) && (args->right_u8 == 255)) {
  1515         if (args->in_use) {
  1516         if (args->in_use) {
  1516             retval = _Mix_UnregisterEffect_locked(channel, f);
  1517             retval = _Mix_UnregisterEffect_locked(channel, f);
  1517             SDL_UnlockAudio();
  1518             Mix_UnlockAudio();
  1518             return(retval);
  1519             return(retval);
  1519         } else {
  1520         } else {
  1520             SDL_UnlockAudio();
  1521             Mix_UnlockAudio();
  1521             return(1);
  1522             return(1);
  1522         }
  1523         }
  1523     }
  1524     }
  1524 
  1525 
  1525     args->distance_u8 = distance;
  1526     args->distance_u8 = distance;
  1527     if (!args->in_use) {
  1528     if (!args->in_use) {
  1528         args->in_use = 1;
  1529         args->in_use = 1;
  1529         retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args);
  1530         retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args);
  1530     }
  1531     }
  1531 
  1532 
  1532     SDL_UnlockAudio();
  1533     Mix_UnlockAudio();
  1533     return(retval);
  1534     return(retval);
  1534 }
  1535 }
  1535 
  1536 
  1536 
  1537 
  1537 int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance)
  1538 int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance)
  1548     if (f == NULL)
  1549     if (f == NULL)
  1549         return(0);
  1550         return(0);
  1550 
  1551 
  1551     angle = SDL_abs(angle) % 360;  /* make angle between 0 and 359. */
  1552     angle = SDL_abs(angle) % 360;  /* make angle between 0 and 359. */
  1552 
  1553 
  1553     SDL_LockAudio();
  1554     Mix_LockAudio();
  1554     args = get_position_arg(channel);
  1555     args = get_position_arg(channel);
  1555     if (!args) {
  1556     if (!args) {
  1556         SDL_UnlockAudio();
  1557         Mix_UnlockAudio();
  1557         return(0);
  1558         return(0);
  1558     }
  1559     }
  1559 
  1560 
  1560         /* it's a no-op; unregister the effect, if it's registered. */
  1561         /* it's a no-op; unregister the effect, if it's registered. */
  1561     if ((!distance) && (!angle)) {
  1562     if ((!distance) && (!angle)) {
  1562         if (args->in_use) {
  1563         if (args->in_use) {
  1563             retval = _Mix_UnregisterEffect_locked(channel, f);
  1564             retval = _Mix_UnregisterEffect_locked(channel, f);
  1564             SDL_UnlockAudio();
  1565             Mix_UnlockAudio();
  1565             return(retval);
  1566             return(retval);
  1566         } else {
  1567         } else {
  1567             SDL_UnlockAudio();
  1568             Mix_UnlockAudio();
  1568             return(1);
  1569             return(1);
  1569         }
  1570         }
  1570     }
  1571     }
  1571 
  1572 
  1572     if (channels == 2)
  1573     if (channels == 2)
  1608     if (!args->in_use) {
  1609     if (!args->in_use) {
  1609         args->in_use = 1;
  1610         args->in_use = 1;
  1610         retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args);
  1611         retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args);
  1611     }
  1612     }
  1612 
  1613 
  1613     SDL_UnlockAudio();
  1614     Mix_UnlockAudio();
  1614     return(retval);
  1615     return(retval);
  1615 }
  1616 }
  1616 
  1617 
  1617 
  1618 
  1618 /* end of effects_position.c ... */
  1619 /* end of effects_position.c ... */