K-rate and S-rate code


#1

Hi,

I just made this sample code based on a thread here to test to convert to and back from float and while it works in S-rate, it does not work in k-rate.

// Capture the first input, it is encoded as a signed 
  // 32bit integer of which 27 bits are used. 
  // so to convert it to an interval [-1.0f , 1.0f] 
  // the following can be done:
  float input_one = (inlet_in1 / (float) (1<<27));

  // The following transforms the [-1.0f ; 1.0f] interval
  // to the axoloti convention interval of [-(1<<27) ; (1<<27)-1]
  outlet_out1 = (int32_t) (input_one * (1<<27));

Error is:

/Users/afonsob/Local_App_Dev/axoloti/build/xpatch.cpp: In member function 'void rootc::instanceobject__1::dsp(const int32_t*, int32_t (&)[16], int32_t&, int32_t&, int, int)':
/Users/afonsob/Local_App_Dev/axoloti/build/xpatch.cpp:182:48: error: invalid operands of types 'const int32_t* {aka const long int*}' and 'float' to binary 'operator/'
float input_one = (inlet_in1 / (float) (1<<27));
^
/Users/afonsob/Local_App_Dev/axoloti/build/xpatch.cpp:186:15: error: incompatible types in assignment of 'int32_t {aka long int}' to 'int32buffer {aka long int [16]}'
outlet_out1 = (int32_t) (input_one * (1<<27));
^
make: *** [/Users/afonsob/Local_App_Dev/axoloti/build/xpatch.bin] Error 1
shell task failed, exit value: 2
Compiling patch failed ( /Users/afonsob/Local_App_Dev/axoloti/patches/ZDF experiment.axp )


#2

Audio inlets/outlets are arrays of int32_t's with BUFSIZE elements in k-rate code.


#3

Thanks! Could you provide the converted sample code following the desired guidelines for this k-rate example?


#4

Here it is:

int i;
for(i=0;i<BUFSIZE;i++) {
  // Capture the first input, it is encoded as a signed 
  // 32bit integer of which 27 bits are used. 
  // so to convert it to an interval [-1.0f , 1.0f] 
  // the following can be done:
  float input_one = (inlet_in1[i] / (float) (1<<27));

  // The following transforms the [-1.0f ; 1.0f] interval
  // to the axoloti convention interval of [-(1<<27) ; (1<<27)-1]
  outlet_out1[i] = (int32_t) (input_one * (1<<27));
}

#5

Thank you so much! I actually thought the code was expanded to iterate the arrays but this way is better, we can optimize the loops however we want! :slight_smile:

Is there a wiki we can add these little but useful tidbits of information?


#6

Here's a wiki post:


feel free to edit!