Re: Threading Question
Re: Threading Question
- Subject: Re: Threading Question
- From: ben kamen <email@hidden>
- Date: Tue, 31 Jan 2012 15:24:08 -0800
Thanks, this has all been extremely helpful.
Ben
On Jan 31, 2012, at 12:00 PM, email@hidden wrote:
> Send Coreaudio-api mailing list submissions to
> email@hidden
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.apple.com/mailman/listinfo/coreaudio-api
> or, via email, send a message with subject or body 'help' to
> email@hidden
>
> You can reach the person managing the list at
> email@hidden
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Coreaudio-api digest..."
>
>
> Today's Topics:
>
> 1. Re: Threading Question (Robert Bielik)
> 2. Re: Threading Question (Richard Dobson)
> 3. Re: Threading Question (Morgan Packard)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 31 Jan 2012 10:05:45 +0100
> From: Robert Bielik <email@hidden>
> To: email@hidden
> Subject: Re: Threading Question
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> ben kamen skrev 2012-01-31 03:09:
>> Morgan, if you are willing to share a simple example of what that looks like, I would be grateful. What exactly goes into the queue? Function pointers?
>
> One simple SWSR implementation (single writer-single reader) would be to have a Message class:
>
> class Message {
> public:
> Message() {;}
> enum Type {
> Type_kAttack,
> ...
> } type;
>
> int param1;
> int param2;
> ...
> };
>
> unsigned char fifoQueue[256 * sizeof(Message)] = {0};
> unsigned fifoWritePtr = 0;
> unsigned fifoReadPtr = 0;
>
> Message* getMessageToWrite()
> {
> Message* base = (Message*)fifoQueue;
> return new(base + (fifoWritePtr & 255)) Message();
> }
>
> void postMessageToFifo()
> {
> ++fifoWritePtr;
> }
>
> bool fifoHasMessages() {
> return (fifoWritePtr != fifoReadPtr);
> }
>
> const Message* getMessageFromFifo()
> {
> const Message* base = (const Message*)fifoQueue;
> return base + (fifoReadPtr & 255);
> }
>
> void fifoAdvanceRead() {
> ++fifoReadPtr;
> }
>
> To post messages to the fifo:
>
> Message* pMessage = getMessageToWrite();
> pMessage->type = Message::Type_kAttack;
> pMessage->param1 = 42;
> postMessageToFifo();
>
> Reading/processing messages in render callback:
>
> while(fifoHasMessages()) {
> const Message *pMessage = getMessageFromFifo();
> // TODO: Process the message
>
> // Next message...
> fifoAdvanceRead();
> }
>
> That should roughly get you started.
>
> Regards,
> /Rob
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 31 Jan 2012 09:42:43 +0000
> From: Richard Dobson <email@hidden>
> To: undisclosed-recipients: ;
> Cc: email@hidden
> Subject: Re: Threading Question
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 31/01/2012 02:09, ben kamen wrote:
>> Thanks for all the responses!
>>
>> Gregory - the setup you describe is somewhat similar to how my envelope
>> is set up - all I am really doing with my "decay()", etc. functions is
>> changing the increment/direction of the amplitude and reseting a
>> counter....but I can see how putting it all in one function might clear
>> up the problem. Though part of the problem is what happens when
>> "release()" is called while the envelope is still in the "attack" phase.
>>
>
> No different from calling release when it is in the decay or sustain
> stage. You just jump internally on receipt of the message to the release
> code, computing from whatever level the system was in at that point.
> A/D/S makes no difference, the procedure is the same. Of course if the
> attack is set to be slow, and someone just flicks the key on off really
> fast as if playing a drum, they can't expect to hear anything very much.
>
> Richard Dobson
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 31 Jan 2012 09:00:28 -0500
> From: Morgan Packard <email@hidden>
> To: Robert Bielik <email@hidden>
> Cc: email@hidden
> Subject: Re: Threading Question
> Message-ID:
> <email@hidden>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Yeah, this is more or less what I do. Thanks Robert.
> -Morgan
>
> On Tue, Jan 31, 2012 at 4:05 AM, Robert Bielik <email@hidden> wrote:
>
>> ben kamen skrev 2012-01-31 03:09:
>>
>> Morgan, if you are willing to share a simple example of what that looks
>>> like, I would be grateful. What exactly goes into the queue? Function
>>> pointers?
>>>
>>
>> One simple SWSR implementation (single writer-single reader) would be to
>> have a Message class:
>>
>> class Message {
>> public:
>> Message() {;}
>> enum Type {
>> Type_kAttack,
>> ...
>> } type;
>>
>> int param1;
>> int param2;
>> ...
>> };
>>
>> unsigned char fifoQueue[256 * sizeof(Message)] = {0};
>> unsigned fifoWritePtr = 0;
>> unsigned fifoReadPtr = 0;
>>
>> Message* getMessageToWrite()
>> {
>> Message* base = (Message*)fifoQueue;
>> return new(base + (fifoWritePtr & 255)) Message();
>> }
>>
>> void postMessageToFifo()
>> {
>> ++fifoWritePtr;
>> }
>>
>> bool fifoHasMessages() {
>> return (fifoWritePtr != fifoReadPtr);
>> }
>>
>> const Message* getMessageFromFifo()
>> {
>> const Message* base = (const Message*)fifoQueue;
>> return base + (fifoReadPtr & 255);
>> }
>>
>> void fifoAdvanceRead() {
>> ++fifoReadPtr;
>> }
>>
>> To post messages to the fifo:
>>
>> Message* pMessage = getMessageToWrite();
>> pMessage->type = Message::Type_kAttack;
>> pMessage->param1 = 42;
>> postMessageToFifo();
>>
>> Reading/processing messages in render callback:
>>
>> while(fifoHasMessages()) {
>> const Message *pMessage = getMessageFromFifo();
>> // TODO: Process the message
>>
>> // Next message...
>> fifoAdvanceRead();
>> }
>>
>> That should roughly get you started.
>>
>> Regards,
>> /Rob
>>
>> ______________________________**_________________
>> Do not post admin requests to the list. They will be ignored.
>> Coreaudio-api mailing list (email@hidden**)
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/**mailman/options/coreaudio-api/**
>>
>> This email sent to email@hidden
>>
>
>
>
> --
> ===============
> Morgan Packard
> cell: (720) 891-0122
> aim: mpackardatwork
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <https://lists.apple.com/mailman/private/coreaudio-api/attachments/20120131/732184cf/attachment.html>
>
> ------------------------------
>
> _______________________________________________
> Coreaudio-api mailing list
> email@hidden
> https://lists.apple.com/mailman/listinfo/coreaudio-api
>
> End of Coreaudio-api Digest, Vol 9, Issue 28
> ********************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden