postfish.h 4.09 KB
Newer Older
1 2 3 4
/*
 *
 *  postfish
 *    
Monty Montgomery's avatar
Monty Montgomery committed
5
 *      Copyright (C) 2002-2005 Monty
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 *  Postfish is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  Postfish is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with Postfish; see the file COPYING.  If not, write to the
 *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * 
 */

/* This project is a small, tightly tailored application.  it is not
   designed to be nigh-infinitely extensible, nor is it designed to be
   reusable code.  It's monolithic, inflexible, and designed that way
   on purpose. */

29 30 31
#ifndef _POSTFISH_H_
#define _POSTFISH_H_

32
#define _GNU_SOURCE
33
#define _ISOC99_SOURCE
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#define _FILE_OFFSET_BITS 64
#define _REENTRANT 1
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#define __USE_GNU 1
#include <pthread.h>
#include <string.h>
#include <math.h>
#include <signal.h>
#include <fcntl.h>

53 54 55 56 57 58 59 60 61 62 63 64 65 66
#if 0
extern void ef_free(void * address);
extern void *ef_realloc(void * oldBuffer, size_t newSize);
extern void *ef_malloc(size_t size);
extern void *ef_calloc(size_t nelem, size_t elsize);
extern void *ef_valloc (size_t size);

#define free ef_free
#define realloc ef_realloc
#define malloc ef_malloc
#define calloc ef_calloc
#define valloc ef_valloc
#endif 

67 68
#define OUTPUT_CHANNELS 8     // UI code assumes this is <=8
#define MAX_INPUT_CHANNELS 32 // engine code requires <= 32 
69

70 71 72 73
static inline float todB(float x){
  return logf((x)*(x)+1e-30f)*4.34294480f;
}

74 75 76 77
static inline double todBd(double x){
  return log((x)*(x)+1e-30)*4.34294480;
}

78 79 80 81
static inline float fromdB(float x){
  return expf((x)*.11512925f);
}

82 83 84 85
static inline int zerome(double x){
  return (x*x < 1.e-30);
}

86 87
#ifdef UGLY_IEEE754_FLOAT32_HACK

88 89 90 91 92 93 94 95
static inline float todB_a(const float x){
  union {
    u_int32_t i;
    float f;
  } ix;
  ix.f = x;
  ix.i = ix.i&0x7fffffff;
  return (float)(ix.i * 7.17711438e-7f -764.6161886f);
96 97 98
}

// eliminate a *.5 in ops on sq magnitudes
99 100 101 102 103 104 105 106
static inline float todB_a2(const float x){
  union {
    u_int32_t i;
    float f;
  } ix;
  ix.f = x;
  ix.i = ix.i&0x7fffffff;
  return (float)(ix.i * 3.58855719e-7f -382.3080943f);
107 108
}

109 110 111 112 113 114 115
static inline float fromdB_a(const float x){
  union {
    u_int32_t i;
    float f;
  } ix;
  ix.i = (x < -300.f ? 0 : 1.39331762961e+06f*(x+764.6161886f));
  return ix.f;
116 117
}

Monty Montgomery's avatar
Monty Montgomery committed
118
static inline void underguard(float *x){
119 120 121 122 123 124
  union {
    u_int32_t i;
    float f;
  } ix;
  ix.f = *x;
  if((ix.i & 0x7f800000)==0) *x=0.0f;
Monty Montgomery's avatar
Monty Montgomery committed
125 126
}

127 128 129 130 131 132 133 134 135 136
#else

static inline float todB_a(const float *x){
  return todB(*x);
}

static inline float fromdB_a(float x){
  return fromdB(x);
}

Monty Montgomery's avatar
Monty Montgomery committed
137 138 139 140
static inline void underguard(float *x){
  if(*x<1e-30f && *x>-1e-30f) x=0.0f;
}

141 142
#endif

143 144 145 146 147
#ifndef max
#define max(x,y) ((x)>(y)?(x):(y))
#endif


148
#define toOC(n)     (log(n)*1.442695f-5.965784f)
149
#define fromOC(o)   (exp(((o)+5.965784f)*.693147f))
150 151
#define toBark(n)   (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
#define fromBark(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
152

153
typedef struct time_linkage {
Monty Montgomery's avatar
Monty Montgomery committed
154
  int alias;
Monty Montgomery's avatar
Monty Montgomery committed
155
  int samples;  /* normally same as size; exception is EOF */
156
  int channels;
157
  float **data;
158
  u_int32_t active; /* active channel bitmask */
159 160
} time_linkage;

Monty Montgomery's avatar
Monty Montgomery committed
161

162 163 164
extern sig_atomic_t loop_active;
extern sig_atomic_t playback_active;
extern sig_atomic_t playback_exit;
165
extern sig_atomic_t playback_seeking;
166
extern sig_atomic_t master_att;
167
extern int outfileno;
168
extern int input_seekable;
169 170
extern int eventpipe[2];
extern int input_ch;
171 172
extern int input_size;
extern int input_rate;
173

174
extern int mute_channel_muted(u_int32_t bitmap,int i);
175
extern void clean_exit(int sig);
176
#endif
177