Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect frequency value using iPhone

I'm developing an app that should detect a frequency of a certain sound. I based my app on Pitch Detector. I imported the files that are in the Pitch Detector example, then I fixed my code to accept this new classes. I post here my code to explain you my issue:

ViewController.h

#import <UIKit/UIKit.h>

@class RIOInterface;

@interface ViewController : UIViewController {
    BOOL isListening;
    float currentFrequency;
    RIOInterface *rioRef; // HERE I'M GETTING ISSUE
}
- (IBAction)startListenWatermark:(UIButton *)sender;

@property(nonatomic, assign) RIOInterface *rioRef;
@property(nonatomic, assign) float currentFrequency;
@property(assign) BOOL isListening;

#pragma mark Listener Controls
- (void)startListener;
- (void)stopListener;

 - (void)frequencyChangedWithValue:(float)newFrequency;

@end

ViewController.m

@synthesize isListening;
@synthesize rioRef;
@synthesize currentFrequency;

- (IBAction)startListenWatermark:(UIButton *)sender {
    if (isListening) {
        [self stopListener];
    } else {
        [self startListener];
    }
    isListening = !isListening;
}

- (void)startListener {
    [rioRef startListening:self];
}

- (void)stopListener {
    [rioRef stopListening];
}

- (void)frequencyChangedWithValue:(float)newFrequency {
    NSLog(@"FREQUENCY: %f", newFrequency);
}

In the code you can see where's my issue and Xcode says: Existing instance variable 'rioRef' with assign attribute must be __unsafe_unretained. If I delete the row that give this errore the app doesn't calls the method [rioRef startListening:self]; and [rioRef stopListening];.

In the file RIOInterface.mm I'm getting another error in line 97 and Xcode suggested me to change it from:

RIOInterface* THIS = (RIOInterface *)inRefCon; --> RIOInterface* THIS = (RIOInterface *)CFBridgingRelease(inRefCon);

The it gives me this other error on the line 283:

callbackStruct.inputProcRefCon = self;

It says me this: Assigning to 'void' from incompatible type 'RIOInterface *const__strong', so I looked to the web and I found this solution:

callbackStruct.inputProcRefCon = (__bridge void*)self;

I'm not sure if it's right to do so or not, I hope you can help me to solve this issues, thank you in advice.

like image 706
lucgian841 Avatar asked Oct 20 '22 16:10

lucgian841


1 Answers

For the 2nd and the 3rd problem I solved by disabling the ARC for the file in which there are the code I provided above. For the first problem I solved by writing this code:

rioRef = [RIOInterface sharedInstance];

like image 165
lucgian841 Avatar answered Oct 23 '22 17:10

lucgian841