• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Getting called by the run loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting called by the run loop


  • Subject: Getting called by the run loop
  • From: Michael Bonnice <email@hidden>
  • Date: Mon, 24 Nov 2003 22:40:41 -0700

I'm not sure how many hours I'm expected to spend looking through
documentation before submitting a question, but I figured I've tried
long and hard.

My application uses CoreAudio to listen to the sound input and
calculate a frequency, all within my ioProc. This works, and I can
print the results using fprintf(stderr, ...) from my ioProc. Now I'm
ready to put the results into my user interface.

There is a text field in my interface window that will display the
result. I store a reference to that field, calculate the result, then
send the message to the field to display the result. To make it work,
within my ioProc I tell the text field to display the result (see code
fragments below); this requires an autorelease pool in the ioProc.

The advice from the experts is to do less processing in the ioProc, as
I could interrupt sound processing. So, what I want is to store the
result I calculate into a global variable, then at the application's
leisure I'll display the result.

Rumor is that I should insert something into the main run loop which is
a piece of my code that will be called by the application, then I can
safely do interface things at that time. I'll check to see if a global
variable has a value that needs to be displayed, and I'll send the
message to the field to display the result.

Here are my questions:
- Where and how do I add something to the main run loop? Please be
specific about which message I send, to which object I send it, and
from where in my program (awakeFromNib? main?) I send it in order to
add something to the main run loop.

- Do I need to be specific and say that I only want to be called when
the application is having idle time?

Mike

Code fragments:

@interface TunerController : NSObject
{
...
IBOutlet id freqField; // the user interface item, a text field
...
}
...
@end

@implementation TunerController

- (void)awakeFromNib
{
[tuner setup]; // this will initialize our CoreAudio data
...
[tuner setLeftFreqField: freqField]; // tell the tuner where to
show the left frequency
}
..

@end

@interface Tuner : NSObject
{

...

IBOutlet id leftFreqField; // field showing the
frequency of the left channel
}

...
- (void)setLeftFreqField:(id)field;

@end

// define a C struct from the Obj-C object so audio callback can access
data
typedef struct {
@defs(Tuner);
} tunerdef;

// this is the audio processing callback

OSStatus inappIOProc (AudioDeviceID inDevice, const AudioTimeStamp*
inNow, const AudioBufferList* inInputData,
const AudioTimeStamp* inInputTime,
AudioBufferList* outOutputData, const AudioTimeStamp* inOutputTime,
void* defptr)
{
tunerdef* def = defptr; // get access to Tuner's data
float leftFreq;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

// calculate the frequency
...
// display the result
[def->leftFreqField setDoubleValue: leftFreq];

[pool release];
}

@implementation Tuner

- (void)setLeftFreqField:(id)field
{
leftFreqField = field; // store the field id in a place where the
ioProc can get it
}

@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Breakpoints Being Ignored
  • Next by Date: How to write background app that intercepts keyboard events
  • Previous by thread: Re: Breakpoints Being Ignored
  • Next by thread: How to write background app that intercepts keyboard events
  • Index(es):
    • Date
    • Thread