<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: buffer~ questions</title>
		<atom:link href="http://cycling74.com/forums/topic/buffer-questions/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/buffer-questions/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 08:13:14 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/buffer-questions/#post-33008</guid>
					<title><![CDATA[buffer~ questions]]></title>
					<link>http://cycling74.com/forums/topic/buffer-questions/#post-33008</link>
					<pubDate>Tue, 24 Jul 2007 00:07:06 +0000</pubDate>
					<dc:creator>Luigi Castelli</dc:creator>

					<description>
						<![CDATA[
						<p>hi folks,</p>
<p>so I spent the last 4-5 hours reading every single thread in the<br />
archives related to buffer~.</p>
<p>I have been keeping into consideration threads priority and buffer~&#8217;s<br />
lightweight locking mechanism (b_valid and b_inuse flags).</p>
<p>I am writing a normalization routine to be used inside a more complex<br />
object and here is what I came up with:</p>
<p>
void myobj_normalize(t_myobj *x)<br />
{<br />
    t_buffer *b = x->buf;</p>
<p>    if (b &#038;&#038; b->b_valid) {</p>
<p>        float *table = b->b_samples;<br />
        long chan = x->chan;<br />
        long frames = b->b_frames;<br />
        long nc = b->b_nchans;<br />
        int i;</p>
<p>        // don&#8217;t need to worry about threads priority<br />
        // when reading from a buffer~</p>
<p>        float maxval = 0.;<br />
        for (i = 0; i < frames; ++i) {<br />
            float val = table[i * nc + chan];<br />
            float absval = fabsf(val);<br />
            if (absval > maxval) {<br />
                maxval = absval;<br />
            }<br />
        }</p>
<p>        if (maxval > 0.) {</p>
<p>            // now I need to write to buffer<br />
            // so threads priority become an issue</p>
<p>            // defer to low priority</p>
<p>            float scale = 1. / maxval;<br />
            defer_low(x, (method)myobj_doscale,0L,0,0L);	 <br />
        }<br />
    }<br />
}</p>
<p>
void myobj_doscale(t_myobj *x, double scale)<br />
{<br />
    t_buffer *b = x->buf;<br />
    float *table = b->b_samples;<br />
    long chan = x->chan;<br />
    frames = b->b_frames;<br />
    long nc = b->b_nchans;<br />
    int i;</p>
<p>    while (buf->b_inuse) ;    // spin until buffer is no longer<br />
                              // in use by the audio thread</p>
<p>    buf->b_valid = 0;	      // set b_valid to false to prevent<br />
                              // buffer~ access while editing</p>
<p>    for (i = 0; i < frames; ++i) {<br />
        table[i * nc + chan] *= scale;<br />
    }</p>
<p>    b->b_valid = 1;	      // restore buffer~ access</p>
<p>    b->b_modtime = gettime(); // set new modification time<br />
                              // so that any object referencing<br />
                              // this buffer~ can update<br />
}</p>
<p>
So far the code seems to be working correctly but I am not sure it IS<br />
correct.</p>
<p>1. Is it strictly necessary to defer methods that alter the buffer~<br />
content in any way to low priority ?</p>
<p>2. Am I supposed to be using deferlow as above or is defer more<br />
appropriate in this situation ?</p>
<p>3. Am I correctly understanding and using buffer~&#8217;s locking mechanism ?</p>
<p>
Any comments highly appreciated.</p>
<p>Thank you.</p>
<p>- Luigi</p>
<p>
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
THIS E-MAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION.  ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED.  IF YOU ARE NOT THE INTENDED RECIPIENT, CONTACT THE SENDER BY E-MAIL AT <a href="mailto:SUPERBIGIO@YAHOO.COM">SUPERBIGIO@YAHOO.COM</a> AND DESTROY ALL COPIES OF THE ORIGINAL MESSAGE. WITHOUT PREJUDICE UCC1-207.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>
Moody friends. Drama queens. Your life? Nope! &#8211; their life, your story. Play Sims Stories at Yahoo! Games.</p>
<p><a href="http://sims.yahoo.com/" rel="nofollow">http://sims.yahoo.com/</a></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/buffer-questions/#post-109397</guid>
					<title><![CDATA[Re: buffer~ questions]]></title>
					<link>http://cycling74.com/forums/topic/buffer-questions/#post-109397</link>
					<pubDate>Wed, 25 Mar 2009 10:46:32 +0000</pubDate>
					<dc:creator>Pierre Alexandre Tremblay</dc:creator>

					<description>
						<![CDATA[
						<p>Dear all</p>
<p>I am reviving this thread because my hopes in the new SDK have been disappointed.  I wish there was the code of poke~ so I could see Cycling74 approved buffer writing etiquette.</p>
<p>Can someone give me the real practice of the inuse, valid and dirty flags?</p>
<p>thanks</p>
<p>pa</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/buffer-questions/#post-109398</guid>
					<title><![CDATA[Re: buffer~ questions]]></title>
					<link>http://cycling74.com/forums/topic/buffer-questions/#post-109398</link>
					<pubDate>Thu, 26 Mar 2009 16:20:14 +0000</pubDate>
					<dc:creator>oli larkin</dc:creator>

					<description>
						<![CDATA[
						<p>hi pa, </p>
<p>did you see this, posted the other day by tim place?</p>
<p><a href="http://blog.74objects.com/2009/03/22/accessing-buffers/">http://blog.74objects.com/2009/03/22/accessing-buffers/</a></p>
<p>oli</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

