POV-Ray : Newsgroups : povray.general : Few tricks : Re: Few tricks Server Time
12 May 2024 17:36:51 EDT (-0400)
  Re: Few tricks  
From: ingo
Date: 27 Nov 2023 07:55:00
Message: <web.65649144c0e3ff7317bac71e8ffb8ce3@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
>
> I hadn't known one can split a returned array like that.  </grin>

The array unpacking works well and it looks clean. I mostly use it within
macro's. As soon I create multiple instances "enumerating a struct" works
better, but is less clean.

---%<------%<------%<--
// PoVRay 3.8 Scene File "goertzel.pov"
// author:  Ingo Janssen
// date:    2023-11-16
//
// Oscillator that uses 'inverse' Goertzel
//--------------------------------------------------------------------------

#version 3.7;

global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}

#declare TAU = 2 * pi;

/*Enumerate elements of Goertzel oscillator data structure*/
#declare _gsoMultiplier = 0;
#declare _gsoCurrent = 1;
#declare _gsoPrevious = 2;
#declare _gsoN = 3;


#macro initGSinOsc(Frequency, Phase, SampleRate)
  #local phaseIncrement = Frequency * TAU / SampleRate;
  #local gsoMultiplier = 2 * cos(phaseIncrement);
  #local gsoCurrent = sin(Phase);
  #local gsoPrevious = sin(Phase - phaseIncrement);
  #local gsoN = 0;
  #local GSO = array {gsoMultiplier, gsoCurrent, gsoPrevious, gsoN};
  GSO
#end

// if 3.7
//#macro initGSinOsc(Frequency, Phase, SampleRate)
//  #local GSO = array[4];
//  #local phaseIncrement = Frequency * TAU / SampleRate;
//  #local GSO[_gsoMultiplier] = 2 * cos(phaseIncrement);
//  #local GSO[_gsoCurrent] = sin(Phase);
//  #local GSO[_gsoPrevious] = sin(Phase - phaseIncrement);
//  #local GSO[_gsoN] = 0;
//  GSO
//#end

#macro Next(GSO)
  #local {gsoMultiplier, gsoCurrent, gsoPrevious, gsoN} = GSO;
  #if (gsoN > 0)
    #local d0 = gsoMultiplier * gsoCurrent - gsoPrevious;
    #local gsoPrevious = gsoCurrent;
    #local gsoCurrent = d0;
  #else
    #local gsoN = gsoN + 1;
  #end
  #local GSO = array {gsoMultiplier, gsoCurrent, gsoPrevious, gsoN};
#end

//if 3.7
//#macro Next(GSO)
//  #if (GSO[_gsoN] > 0)
//    #local d0 = GSO[_gsoMultiplier] * GSO[_gsoCurrent] - GSO[_gsoPrevious];
//    #local GSO[_gsoPrevious] = GSO[_gsoCurrent];
//    #local GSO[_gsoCurrent] = d0;
//  #else
//    #local GSO[_gsoN] = GSO[_gsoN] + 1;
//  #end
//#end



#declare Duration = 1; //sec
#declare SampleRate = 44100;
#declare Ticks = Duration * SampleRate;
#declare Frequency = 440;
#declare Phase = 0;

#declare T0 = datetime(now, "%S")
#declare GSinOsc = initGSinOsc(Frequency, Phase, SampleRate); // here the
unpacking is not usefull.
#declare Garray = array [Ticks];
#for (Tick, 0, Ticks - 1)
  Next(GSinOsc)
  #declare Garray = GSinOsc[_gsoCurrent];
#end
#declare T1 = datetime(now, "%S")

#declare T2 = datetime(now, "%S")
#declare Sarray = array[Ticks];
#declare phaseIncrement = Frequency * TAU / SampleRate;
#for (Tick, 0, Ticks - 1)
  #declare Sarray[Tick] = sin(Tick * phaseIncrement);
#end
#declare T3 = datetime(now, "%S")

#debug T0
#debug "\n"
#debug T1
#debug "\n"
#debug T2
#debug "\n"
#debug T3
#debug "\n"


---%<------%<------%<---


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.