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