MuseScore  3.4
Music composition and notation
dsp.h
Go to the documentation of this file.
1 //=============================================================================
2 // Audio Utility Library
3 //
4 // Copyright (C) 2002-2006 by Werner Schweer and others
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License version 2.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 //=============================================================================
18 
19 #ifndef __DSP_H__
20 #define __DSP_H__
21 
22 namespace Ms {
23 
24 //---------------------------------------------------------
25 // f_max
26 //---------------------------------------------------------
27 
28 static inline float f_max(float x, float a)
29  {
30  x -= a;
31  x += fabsf(x);
32  x *= 0.5f;
33  x += a;
34  return x;
35  }
36 
37 //---------------------------------------------------------
38 // Dsp
39 // standard version of all dsp routines without any
40 // hw acceleration
41 //---------------------------------------------------------
42 
43 class Dsp {
44  public:
45  Dsp() {}
46  virtual ~Dsp() {}
47 
48  virtual float peak(float* buf, unsigned n, float current) {
49  for (unsigned i = 0; i < n; ++i)
50  current = f_max(current, fabsf(buf[i]));
51  return current;
52  }
53  virtual void applyGainToBuffer(float* buf, unsigned n, float gain) {
54  for (unsigned i = 0; i < n; ++i)
55  buf[i] *= gain;
56  }
57  virtual void mixWithGain(float* dst, float* src, unsigned n, float gain) {
58  for (unsigned i = 0; i < n; ++i)
59  dst[i] += src[i] * gain;
60  }
61  virtual void mix(float* dst, float* src, unsigned n) {
62  for (unsigned i = 0; i < n; ++i)
63  dst[i] += src[i];
64  }
65  virtual void cpy(float* dst, float* src, unsigned n) {
66 #if defined(ARCH_X86) || defined(ARCH_X86_64)
67  register unsigned long int dummy;
68  __asm__ __volatile__ ("rep; movsl" :"=&D"(dst), "=&S"(src), "=&c"(dummy) :"0" (to), "1" (from),"2" (n) : "memory");
69 #else
70  memcpy(dst, src, sizeof(float) * n);
71 #endif
72  }
73  };
74 
75 extern void initDsp();
76 extern Dsp* dsp;
77 
78 
79 } // namespace Ms
80 #endif
81 
virtual void cpy(float *dst, float *src, unsigned n)
Definition: dsp.h:65
virtual ~Dsp()
Definition: dsp.h:46
Dsp * dsp
Definition: dsp.cpp:15
virtual float peak(float *buf, unsigned n, float current)
Definition: dsp.h:48
virtual void mixWithGain(float *dst, float *src, unsigned n, float gain)
Definition: dsp.h:57
Definition: aeolus.cpp:26
virtual void mix(float *dst, float *src, unsigned n)
Definition: dsp.h:61
Definition: dsp.h:43
virtual void applyGainToBuffer(float *buf, unsigned n, float gain)
Definition: dsp.h:53
void initDsp()
Definition: dsp.cpp:79
Dsp()
Definition: dsp.h:45