Hello all,

So I have been continuing on my quest to use C primatives in my DSP
project, and have been stumped with what to me feels like total
nonsense.

I am hoping someone can shed some light on the subject.  So basically I
have this (relevant code):


--- Processor.m

   Reflector *reflector = [Reflector translateCoefficients:coefficients 
numberOfSamples:buffer.size];

   FrameData *frameData = [[FrameData alloc] initWithReflector:reflector 
pitch:0 repeat:NO translate:YES];

--- Reflector.m

  @interface Reflector ()
  @property (nonatomic) double *ks;
  @end

  +(void)translatCoefficients... {
    ... stuff that calculates k[1] through k[10] and rms
    double k[11] = {0};

    NSLog(@"%f", k[1]);  // this outputs ==>  -0.941884

    return [[Reflector alloc] initWithKs:k rms:rms];
  }

  -(instancetype)initWithKs:(double *)ks rms:(NSUInteger)rms {
      if (self = [super init]) {
          self.ks  = ks;
          self.rms = rms;

          NSLog(@"%f", self.ks[1]); // this outputs ==> 0.941884
      }
      return self;
  }

--- FrameData.m

  -(NSNumber *)parameterizedValueForK:(NSUInteger)k {
      NSUInteger index = [ClosestValueFinder indexFor:self.reflector.ks[k]
                                               floats:[CodingTable kBinFor:k]
                                                 size:[CodingTable kSizeFor:k]];

      NSLog(@"%f", self.reflector.ks[1]); //  this outputs ==> 0.000000  
?!?!?!?!?!?!
  }

Why in the world am I losing the ks property?  Reflector is the correct object
in the context of the FrameData instance.. So, it's like somehow reflector.ks 
property
is getting garbage collected and I do not understand how or why!

Anyway, I changed the Reflector.m code to do:

  -(instancetype)initWithKs:(double *)ks rms:(NSUInteger)rms {
      if (self = [super init]) {
          double *k = malloc(sizeof(double) * 11);
          for (int i = 0; i <= 10; i++) {
              k[i] = ks[i];
          }
          self.ks  = k;
          self.rms = rms;
      }
      return self;
  }

  -(void)dealloc {
      free(self.ks);
  }

Is that really what I have to do?


Patrick J. Collins
http://collinatorstudios.com

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/objc-language/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to