gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSound Reimplementation


From: Stefan Bidigaray
Subject: Re: NSSound Reimplementation
Date: Fri, 19 Jun 2009 11:22:58 -0500

On Fri, Jun 19, 2009 at 2:05 AM, Fred Kiefer <address@hidden> wrote:
I don't understand the general concept here, so just a few detail
comments on the code itself.

I'll try to explain this the best I can, it might be a little long, though...

As I explained on my previous e-mails, I'm streaming the data to the sink.  In order to do so without blocking the main thread I'm using a separate thread (spawned using -detachNewThreadSelector:toTarget:withObject:)... this will happen in -play and the selector is -_stream.  The stream uses 2 objects, one conforms to <GSSoundSource> and the other to <GSSoundSink>, the former outputs the data in a standard format so that the latter can send it to the audio device.  To pause and resume the stream I use an NSConditionLock, which is what _private[2] is, if the condition is SOUND_SHOULD_PAUSE the while loop waits until it's SOUND_SHOULD_PLAY.  The hardest part, at least for me, is finding out if the thread is already running in -play and -stop and taking the appropiate action.  The -pause and -resume methods are pretty straight forward.


Hiding the implementation details in the header is a good thing, but it
makes the code in the implementation harder to read. This could be
improved by using local variables (or even Macros). For example

Sounds good!

When releasing the conditional lock, you should rather destroy it, as it
could otherwise just be reused, although it has been freed.

Wouldn't this cause a bit of a problem in -_stream since I keep checking the NSConditionLock's condition?  My plan was to initialize it in -play and free/destroy it in -stop and use it as the way to find out if the audio data is being streamed.

Shouldn't the condition of the while loop read something like this?
 while ((!_shouldExit) && (bytesRead > 0) && success)

Yes!  Oops...

I've attached a copy of GSSoundSource.h and GSSoundSink.h, these two header files define the protocols and give you an idea of what exactly I'm going for.  I've also gone ahead and added documention as well.  I'll also go ahead and attach the first two classes that implement these protocols.  As before, I haven't had time to test them, so I'm sure there are typos everywhere.  I do plan on testing them later today, make sure they actually do what they're supposed to before finishing the NSSound implentation.

Thanks
Stefan
 

Attachment: GSSoundSink.h
Description: Text Data

Attachment: GSSoundSource.h
Description: Text Data

Attachment: AudioOutputSink.m
Description: Text Data

Attachment: SndfileSource.m
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]