os/graphics/graphicstest/uibench/s60/src/tests_fonts/wavegenerator.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 
    17 #include "wavegenerator.h"
    18 
    19 #include <e32math.h>
    20 
    21 
    22 /**
    23 Generates a set of values that resembles a sine wave that has no negative 
    24 values.
    25 */
    26 void WaveGenerator::GenerateSineWave(TValueList& aResults, TInt aNumSamples,
    27         TReal aAmplitude, TReal aFrequency, TBool aPositiveValues)
    28     {
    29     TReal prefix = -1;
    30     TReal part = 1.0 / aNumSamples;
    31     TReal time = 0;
    32     TReal preCalculation = 3.14159265358979323846 * aFrequency;
    33     if (aPositiveValues)
    34         {
    35         prefix = 1;
    36         }
    37     TReal sinResult;
    38     for (TInt i = aNumSamples; i > 0; --i)
    39         {
    40         time += part;
    41         Math::Sin(sinResult, preCalculation * time);
    42         aResults.Append(prefix * Abs(aAmplitude * sinResult));
    43         }
    44     }