/[svn]/linuxsampler/trunk/benchmarks/triang.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/benchmarks/triang.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 717 by schoenebeck, Sun Jul 24 10:26:17 2005 UTC revision 720 by senkov, Sun Jul 24 18:22:56 2005 UTC
# Line 12  Line 12 
12  #include <stdio.h>  #include <stdio.h>
13    
14  #include "../src/engines/common/LFOTriangleIntMath.h"  #include "../src/engines/common/LFOTriangleIntMath.h"
15    #include "../src/engines/common/LFOTriangleIntAbsMath.h"
16  #include "../src/engines/common/LFOTriangleDiHarmonic.h"  #include "../src/engines/common/LFOTriangleDiHarmonic.h"
17    
18  // whether we should not show any messages on the console  // whether we should not show any messages on the console
# Line 23  Line 24 
24  // you can e.g. open it as RAW file in Rezound  // you can e.g. open it as RAW file in Rezound
25  // (32 bit SP-FP PCM, mono, little endian, 44100kHz)  // (32 bit SP-FP PCM, mono, little endian, 44100kHz)
26  #ifndef OUTPUT_AS_RAW_WAVE  #ifndef OUTPUT_AS_RAW_WAVE
27  # define OUTPUT_AS_RAW_WAVE     0  # define OUTPUT_AS_RAW_WAVE     1
28  #endif  #endif
29    
30  // how many sample points should we calculate in one sequence  // how many sample points should we calculate in one sequence
# Line 56  Line 57 
57  #define INT_MATH_SOLUTION       2  /* we don't start with 1, as this is reserved for unknown errors */  #define INT_MATH_SOLUTION       2  /* we don't start with 1, as this is reserved for unknown errors */
58  #define DI_HARMONIC_SOLUTION    3  #define DI_HARMONIC_SOLUTION    3
59  #define TABLE_LOOKUP_SOLUTION   4  /* table lookup solution is currently disabled in this benchmark, see below */  #define TABLE_LOOKUP_SOLUTION   4  /* table lookup solution is currently disabled in this benchmark, see below */
60    #define INT_MATH_ABS_SOLUTION   5  /* integer math with abs() */
61  #define INVALID_RESULT          -1  #define INVALID_RESULT          -1
62    
63  // we use 32 bit single precision floating point as sample point format  // we use 32 bit single precision floating point as sample point format
# Line 65  using namespace LinuxSampler; Line 67  using namespace LinuxSampler;
67    
68  #if SIGNED  #if SIGNED
69  LFOTriangleIntMath<range_signed>*    pIntLFO        = NULL;  LFOTriangleIntMath<range_signed>*    pIntLFO        = NULL;
70    LFOTriangleIntAbsMath<range_signed>* pIntAbsLFO     = NULL;
71  LFOTriangleDiHarmonic<range_signed>* pDiHarmonicLFO = NULL;  LFOTriangleDiHarmonic<range_signed>* pDiHarmonicLFO = NULL;
72  #else // unsigned  #else // unsigned
73  LFOTriangleIntMath<range_unsigned>*    pIntLFO        = NULL;  LFOTriangleIntMath<range_unsigned>*    pIntLFO        = NULL;
74    LFOTriangleIntAbsMath<range_unsigned>* pIntAbsLFO     = NULL;
75  LFOTriangleDiHarmonic<range_unsigned>* pDiHarmonicLFO = NULL;  LFOTriangleDiHarmonic<range_unsigned>* pDiHarmonicLFO = NULL;
76  #endif  #endif
77    
# Line 95  float int_math(sample_t* pDestinationBuf Line 99  float int_math(sample_t* pDestinationBuf
99      return elapsed_time;      return elapsed_time;
100  }  }
101    
102    // integer math abs solution
103    float int_math_abs(sample_t* pDestinationBuffer, float* pAmp, const int steps, const float frequency) {
104        // pro forma
105        pIntAbsLFO->trigger(frequency, start_level_max, 1200 /* max. internal depth */, 0, false, (unsigned int) SAMPLING_RATE);
106    
107        clock_t stop_time;
108        clock_t start_time = clock();
109    
110        for (int run = 0; run < RUNS; run++) {
111            pIntAbsLFO->update(0); // pro forma
112            for (int i = 0; i < steps; ++i) {
113                pDestinationBuffer[i] = pIntAbsLFO->render() * pAmp[i]; // * pAmp[i] just to simulate some memory load
114            }
115        }
116    
117        stop_time = clock();
118        float elapsed_time = (stop_time - start_time) / (double(CLOCKS_PER_SEC) / 1000.0);
119        #if ! SILENT
120        printf("int math abs solution elapsed time: %1.0f ms\n", elapsed_time);
121        #endif
122    
123        return elapsed_time;
124    }
125    
126  // table lookup solution (currently disabled)  // table lookup solution (currently disabled)
127  //  //
128  // This solution is not yet implemented in LinuxSampler yet and probably  // This solution is not yet implemented in LinuxSampler yet and probably
# Line 216  int main() { Line 244  int main() {
244    
245      #if SIGNED      #if SIGNED
246      pIntLFO        = new LFOTriangleIntMath<range_signed>(MAX);      pIntLFO        = new LFOTriangleIntMath<range_signed>(MAX);
247        pIntAbsLFO     = new LFOTriangleIntAbsMath<range_signed>(MAX);
248      pDiHarmonicLFO = new LFOTriangleDiHarmonic<range_signed>(MAX);      pDiHarmonicLFO = new LFOTriangleDiHarmonic<range_signed>(MAX);
249      #else // unsigned      #else // unsigned
250      pIntLFO        = new LFOTriangleIntMath<range_unsigned>(MAX);      pIntLFO        = new LFOTriangleIntMath<range_unsigned>(MAX);
251        pIntAbsLFO     = new LFOTriangleIntAbsMath<range_unsigned>(MAX);
252      pDiHarmonicLFO = new LFOTriangleDiHarmonic<range_unsigned>(MAX);      pDiHarmonicLFO = new LFOTriangleDiHarmonic<range_unsigned>(MAX);
253      #endif      #endif
254    
# Line 232  int main() { Line 262  int main() {
262          pAmplitude[i] = (float) i / (float) steps;          pAmplitude[i] = (float) i / (float) steps;
263    
264      // how long each solution took (in seconds)      // how long each solution took (in seconds)
265      float int_math_result, /*table_lookup_result,*/ numeric_di_harmonic_result;      float int_math_result, int_math_abs_result, /*table_lookup_result,*/ numeric_di_harmonic_result;
266    
267      int_math_result = int_math(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);      int_math_result = int_math(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);
268      #if OUTPUT_AS_RAW_WAVE      #if OUTPUT_AS_RAW_WAVE
269        output_as_raw_file("bench_int_math.raw", pOutputBuffer, steps);        output_as_raw_file("bench_int_math.raw", pOutputBuffer, steps);
270      #endif      #endif
271    
272        int_math_abs_result = int_math_abs(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);
273        #if OUTPUT_AS_RAW_WAVE
274          output_as_raw_file("bench_int_math_abs.raw", pOutputBuffer, steps);
275        #endif
276      //table_lookup_result = table_lookup(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);      //table_lookup_result = table_lookup(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);
277      //#if OUTPUT_AS_RAW_WAVE      //#if OUTPUT_AS_RAW_WAVE
278      //  output_as_raw_file("bench_table_lookup.raw", pOutputBuffer, steps);      //  output_as_raw_file("bench_table_lookup.raw", pOutputBuffer, steps);
# Line 252  int main() { Line 287  int main() {
287      #endif      #endif
288    
289      int_math_result            += int_math(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);      int_math_result            += int_math(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);
290        int_math_abs_result = int_math_abs(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);
291      //table_lookup_result        += table_lookup(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);      //table_lookup_result        += table_lookup(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);
292      numeric_di_harmonic_result += numeric_di_harmonic_solution(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);      numeric_di_harmonic_result += numeric_di_harmonic_solution(pOutputBuffer, pAmplitude, steps, sinusoidFrequency);
293    
# Line 261  int main() { Line 297  int main() {
297      if (pIntLFO)        delete pIntLFO;      if (pIntLFO)        delete pIntLFO;
298      if (pDiHarmonicLFO) delete pDiHarmonicLFO;      if (pDiHarmonicLFO) delete pDiHarmonicLFO;
299    
300      if (/*int_math_result <= table_lookup_result &&*/ int_math_result <= numeric_di_harmonic_result) return INT_MATH_SOLUTION;      if (int_math_abs_result <= int_math_result && int_math_abs_result <= numeric_di_harmonic_result) return INT_MATH_ABS_SOLUTION;
301      if (/*numeric_di_harmonic_result <= table_lookup_result &&*/ numeric_di_harmonic_result <= int_math_result) return DI_HARMONIC_SOLUTION;      if (int_math_result <= int_math_abs_result && int_math_result <= numeric_di_harmonic_result) return INT_MATH_SOLUTION;
302      //if (table_lookup_result <= int_math_result && table_lookup_result <= numeric_di_harmonic_result) return TABLE_LOOKUP_SOLUTION;      if (numeric_di_harmonic_result <= int_math_abs_result && numeric_di_harmonic_result <= int_math_result) return DI_HARMONIC_SOLUTION;
303    
304      return INVALID_RESULT; // error      return INVALID_RESULT; // error
305  }  }

Legend:
Removed from v.717  
changed lines
  Added in v.720

  ViewVC Help
Powered by ViewVC