timidity/output.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 01 Jun 2013 22:30:04 -0700
changeset 627 438fb12df34f
parent 518 8bc9b5fd2aae
child 782 e7d3a8f73e88
permissions -rw-r--r--
Updated iOS project to include OGG support directly
slouken@518
     1
/*
slouken@0
     2
    TiMidity -- Experimental MIDI to WAVE converter
slouken@0
     3
    Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
slouken@0
     4
slouken@0
     5
    This program is free software; you can redistribute it and/or modify
slouken@518
     6
    it under the terms of the Perl Artistic License, available in COPYING.
slouken@518
     7
 */
slouken@0
     8
slouken@0
     9
#include "config.h"
slouken@0
    10
#include "output.h"
slouken@0
    11
#include "tables.h"
slouken@0
    12
slouken@0
    13
slouken@0
    14
#ifdef SDL
slouken@0
    15
extern PlayMode sdl_play_mode;
slouken@0
    16
#define DEFAULT_PLAY_MODE &sdl_play_mode
slouken@0
    17
#endif
slouken@0
    18
slouken@0
    19
PlayMode *play_mode_list[] = {
slouken@0
    20
#ifdef DEFAULT_PLAY_MODE
slouken@0
    21
  DEFAULT_PLAY_MODE,
slouken@0
    22
#endif
slouken@0
    23
  0
slouken@0
    24
};
slouken@0
    25
slouken@0
    26
#ifdef DEFAULT_PLAY_MODE
slouken@0
    27
  PlayMode *play_mode=DEFAULT_PLAY_MODE;
slouken@0
    28
#endif
slouken@0
    29
slouken@0
    30
/*****************************************************************/
slouken@0
    31
/* Some functions to convert signed 32-bit data to other formats */
slouken@0
    32
slouken@0
    33
void s32tos8(void *dp, int32 *lp, int32 c)
slouken@0
    34
{
slouken@0
    35
  int8 *cp=(int8 *)(dp);
slouken@0
    36
  int32 l;
slouken@0
    37
  while (c--)
slouken@0
    38
    {
slouken@0
    39
      l=(*lp++)>>(32-8-GUARD_BITS);
slouken@0
    40
      if (l>127) l=127;
slouken@0
    41
      else if (l<-128) l=-128;
slouken@0
    42
      *cp++ = (int8) (l);
slouken@0
    43
    }
slouken@0
    44
}
slouken@0
    45
slouken@0
    46
void s32tou8(void *dp, int32 *lp, int32 c)
slouken@0
    47
{
slouken@0
    48
  uint8 *cp=(uint8 *)(dp);
slouken@0
    49
  int32 l;
slouken@0
    50
  while (c--)
slouken@0
    51
    {
slouken@0
    52
      l=(*lp++)>>(32-8-GUARD_BITS);
slouken@0
    53
      if (l>127) l=127;
slouken@0
    54
      else if (l<-128) l=-128;
slouken@0
    55
      *cp++ = 0x80 ^ ((uint8) l);
slouken@0
    56
    }
slouken@0
    57
}
slouken@0
    58
slouken@0
    59
void s32tos16(void *dp, int32 *lp, int32 c)
slouken@0
    60
{
slouken@0
    61
  int16 *sp=(int16 *)(dp);
slouken@0
    62
  int32 l;
slouken@0
    63
  while (c--)
slouken@0
    64
    {
slouken@0
    65
      l=(*lp++)>>(32-16-GUARD_BITS);
slouken@0
    66
      if (l > 32767) l=32767;
slouken@0
    67
      else if (l<-32768) l=-32768;
slouken@0
    68
      *sp++ = (int16)(l);
slouken@0
    69
    }
slouken@0
    70
}
slouken@0
    71
slouken@0
    72
void s32tou16(void *dp, int32 *lp, int32 c)
slouken@0
    73
{
slouken@0
    74
  uint16 *sp=(uint16 *)(dp);
slouken@0
    75
  int32 l;
slouken@0
    76
  while (c--)
slouken@0
    77
    {
slouken@0
    78
      l=(*lp++)>>(32-16-GUARD_BITS);
slouken@0
    79
      if (l > 32767) l=32767;
slouken@0
    80
      else if (l<-32768) l=-32768;
slouken@0
    81
      *sp++ = 0x8000 ^ (uint16)(l);
slouken@0
    82
    }
slouken@0
    83
}
slouken@0
    84
slouken@0
    85
void s32tos16x(void *dp, int32 *lp, int32 c)
slouken@0
    86
{
slouken@0
    87
  int16 *sp=(int16 *)(dp);
slouken@0
    88
  int32 l;
slouken@0
    89
  while (c--)
slouken@0
    90
    {
slouken@0
    91
      l=(*lp++)>>(32-16-GUARD_BITS);
slouken@0
    92
      if (l > 32767) l=32767;
slouken@0
    93
      else if (l<-32768) l=-32768;
slouken@0
    94
      *sp++ = XCHG_SHORT((int16)(l));
slouken@0
    95
    }
slouken@0
    96
}
slouken@0
    97
slouken@0
    98
void s32tou16x(void *dp, int32 *lp, int32 c)
slouken@0
    99
{
slouken@0
   100
  uint16 *sp=(uint16 *)(dp);
slouken@0
   101
  int32 l;
slouken@0
   102
  while (c--)
slouken@0
   103
    {
slouken@0
   104
      l=(*lp++)>>(32-16-GUARD_BITS);
slouken@0
   105
      if (l > 32767) l=32767;
slouken@0
   106
      else if (l<-32768) l=-32768;
slouken@0
   107
      *sp++ = XCHG_SHORT(0x8000 ^ (uint16)(l));
slouken@0
   108
    }
slouken@0
   109
}
slouken@0
   110
slouken@0
   111
void s32toulaw(void *dp, int32 *lp, int32 c)
slouken@0
   112
{
slouken@0
   113
  uint8 *up=(uint8 *)(dp);
slouken@0
   114
  int32 l;
slouken@0
   115
  while (c--)
slouken@0
   116
    {
slouken@0
   117
      l=(*lp++)>>(32-13-GUARD_BITS);
slouken@0
   118
      if (l > 4095) l=4095;
slouken@0
   119
      else if (l<-4096) l=-4096;
slouken@0
   120
      *up++ = _l2u[l];
slouken@0
   121
    }
slouken@0
   122
}