[Stk] Problem with the Stk reverbs

edpa06 at imi.aau.dk edpa06 at imi.aau.dk
Mon Mar 8 02:18:51 PST 2010


Hi, thanks for your answer!
It also seems to work for me... Meanwhile I tried to use the reverb's tick() function doing sample by sample calculations, and it works fine; the problem was apparently just with the vectorized function. 
Thanks again for the help!



----- Original meddelelse -----
Fra: "Stephen Sinclair" <sinclair at music.mcgill.ca>
Til: edpa06 at imi.aau.dk
Cc: stk at ccrma.stanford.edu
Sendt: fredag, 5. marts 2010 14:48:26 GMT +01:00 Amsterdam / Berlin / Bern / Rom / Stockholm / Wien
Emne: Re: [Stk] Problem with the Stk reverbs

Not sure if it's correct, but this patch fixed it for me.

It seems oSamples is incremented both inside the loop as well as in
the for() statement, which I don't think is what was intended here.

diff --git a/src/NRev.cpp b/src/NRev.cpp
index 09e4de3..5457066 100644
--- a/src/NRev.cpp
+++ b/src/NRev.cpp
@@ -100,8 +100,8 @@ StkFrames& NRev :: tick( StkFrames& iFrames,
StkFrames& oFrames, unsigned int iC
   StkFloat *oSamples = &oFrames[oChannel];
   unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
   for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop,
oSamples += oHop ) {
-    *oSamples++ = tick( *iSamples );
-    *oSamples = lastFrame_[1];
+    *oSamples = tick( *iSamples );
+    *(oSamples+1) = lastFrame_[1];
   }

   return iFrames;

Steve


On Wed, Mar 3, 2010 at 11:17 AM,  <edpa06 at imi.aau.dk> wrote:
> Hi,
> I am currently trying to write a program implementing the binaural sound algorithm of Brown and Duda ("An efficient HRTF model for 3d sound", 1997). My objective is to make it take a non-spatialized sound file as input, and "make it" 3d by specifying an azimuth and a distance (no elevation for the moment). So basically, i am not dealing with real-time, only reading from a file and writing in another one.
>
> Everything goes fine in my program, except when I reach the point where I try to implement a room-effect: all three of the reverb classes in the stk are making my program crash.
>
> It's compiling fine, but when I run the thing I get a Visual C++ error "Unhandled exception at 0x004247a6 in binaural.exe: 0xC0000005: Access violation writing location 0x00814000",
> and the debugger tells me that the problem comes from the tick function of the reverb, at that point (second line):
>
>  for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
>    *oSamples++ = tick( *iSamples );
>    *oSamples = lastFrame_[1];
>  }
>
> I tried all three of the reverbs, and for each I tried the two tick functions (the ones taking StkFrames as argument): all gave me the same error. The funny thing is that when I try to use an effect other than a reverb, for example the echo, everything works fine; it's just concerning the 3 reverb objects. I copy-pasted my code right under this mail...
>
> I hope someone can help!
> Thanks in advance!
>
> Emmanuel Parzy
>
>
>
> #define __LITTLE_ENDIAN__
> #define __WINDOWS_MM__
> #define __WINDOWS_DS__
>
> #include "FileLoop.h"
> #include "FileWvOut.h"
> #include "BiQuad.h"
> #include "NRev.h"
> #include "Delay.h"
> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h>
>
>
> #define BETA 7778.0
> #define FREQ 44100.0
>
> #define ANGLE 60.0
> #define TSIXTY 0.2
>
> using namespace stk;
>
>
> long getDelay1 (float *angle)
> {
>        //LEFT delay if positive angle; RIGHT delay if negative angle
>        long delay = (((0.0875 + 0.0875*(*angle))/340.29) * FREQ) +2000;
>        std::cout<<"Delay 1: "<<delay<<"\n";
>        return delay;
> }
>
>
>
>
>
>
> long getDelay2 (float *angle)
> {
>        //RIGHT delay if positive angle; LEFT delay if negative angle
>        long delay = (((0.0875 - 0.0875* sin(*angle)) / 340.29) * FREQ) +2000;
>        std::cout<<"Delay 2: "<<delay<<"\n";
>        return delay;
> }
>
>
>
>
>
> void getLeftBiQuadCoef (float *angle, StkFloat *biQuadCoef)
> {
>        //Variable Alpha (varies from 2 to 0 with angle from -90 to 90
>        float a = (-2.0/180.0)*(*angle) + 1.0;
>
>        //Coefficient b0
>        *biQuadCoef = (2.0*a + BETA*(1.0/FREQ)) / (2.0 + BETA*(1.0/FREQ));
>
>        //Coefficient b1
>        *(biQuadCoef +1) = ((-2.0*a) + BETA*(1.0/FREQ)) / (2.0 + BETA*(1.0/FREQ));
>
>        //Coefficient a1
>        *(biQuadCoef +2) = (-2.0 + BETA*(1.0/FREQ)) / (2.0 + BETA*(1.0/FREQ));
>
>        std::cout<<"Angle: "<<*angle<<"\n";
>        std::cout<<"Left Alpha: "<<a<<"\n";
>        std::cout<<"Left filter coefficients: "<<*biQuadCoef<<"  "<<*(biQuadCoef +1)<<"  "<<*(biQuadCoef +2)<<"  "<<"\n";
> }
>
>
>
>
>
>
> void getRightBiQuadCoef (float *angle, StkFloat *biQuadCoef)
> {
>        //Variable Alpha (varies from 2 to 0 with angle from 90 to -90
>        float a = (2.0/180.0)*(*angle) + 1.0;
>
>        //Coefficient a0
>        *biQuadCoef = (2.0*a + BETA*(1.0/FREQ)) / (2.0 + BETA*(1.0/FREQ));
>
>        //Coefficient a1
>        *(biQuadCoef +1) = ((-2.0*a) + BETA*(1.0/FREQ)) / (2.0 + BETA*(1.0/FREQ));
>
>        //Coefficient b1
>        *(biQuadCoef +2) = (-2.0 + BETA*(1.0/FREQ)) / (2.0 + BETA*(1.0/FREQ));
>
>        std::cout<<"Angle: "<<*angle<<"\n";
>        std::cout<<"Right Alpha: "<<a<<"\n";
>        std::cout<<"Right filter coefficients: "<<*biQuadCoef<<"  "<<*(biQuadCoef +1)<<"  "<<*(biQuadCoef +2)<<"  "<<"\n";
> }
>
>
>
>
>
>
> int main()
> {
>  // Set the global sample rate before creating class instances.
>  Stk::setSampleRate( 44100.0 );
>
>  int nFrames = 50000;
>  FileWvIn input;
>  FileWvIn input2;
>  FileWvOut output;
>
>  //Angle of incidence of the sound source
>  float angle = ANGLE;
>
>
>
>  // LOAD A FILE
>    try {
>    input.openFile( "soundfiles/Hello.wav", false );
>    // Open a 16-bit, two-channels WAV formatted output file
>    output.openFile( "output.wav", 2, FileWrite::FILE_WAV, Stk::STK_SINT16 );
>  }
>  catch ( StkError & ) {
>    exit( 1 );
>  }
>
>
>
>  //FILTERS
>  BiQuad leftBiQuad;
>  BiQuad rightBiQuad;
>  StkFloat leftBiQuadCoef [3];
>  StkFloat rightBiQuadCoef [3];
>  //Calculation and setting of the filters coefficients
>  getLeftBiQuadCoef (&angle, &leftBiQuadCoef[0]);
>  getRightBiQuadCoef (&angle, &rightBiQuadCoef[0]);
>  leftBiQuad.setCoefficients(leftBiQuadCoef[0], leftBiQuadCoef[1], 0, leftBiQuadCoef[2], 0);
>  rightBiQuad.setCoefficients(rightBiQuadCoef[0], rightBiQuadCoef[1], 0, rightBiQuadCoef[2], 0);
>
>
>  //DELAYS
>  Delay leftDelay;
>  Delay rightDelay;
>  //Calculation and setting of the delays
>  if (angle>0)
>  {
>          leftDelay.setDelay(getDelay1(&angle));
>          rightDelay.setDelay(getDelay2(&angle));
>  }else
>  {
>          leftDelay.setDelay(getDelay2(&angle));
>          rightDelay.setDelay(getDelay1(&angle));
>  }
>
>  //REVERB
>  NRev rev;
>  float t60 = TSIXTY;
>  rev.setT60(t60);
>
>
>  // StkFrames computations and output
>  StkFrames revFrames( nFrames, 2);
>  StkFrames frames( nFrames, 2 );
>
>  try {
>          input.tick(frames);
>
>          rev.tick(frames, revFrames);
>
>          leftBiQuad.tick(frames, 0);
>          rightBiQuad.tick(frames, 1);
>
>          leftDelay.tick(frames, 0);
>          rightDelay.tick(frames, 1);
>
>          output.tick(revFrames);
>  }
>  catch ( StkError & ) {
>    exit( 1 );
>  }
>
>  //while(1){}
>
>
>
>  return 0;
> }
>
>
> _______________________________________________
> Stk mailing list
> Stk at ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/stk
>
>
>



More information about the Stk mailing list