<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - Please help, with buffers and/or arrays. - Comments</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays</link>
 <description>Comments for &quot;Please help, with buffers and/or arrays.&quot;</description>
 <language>en</language>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46560</link>
 <description>&lt;p&gt;Perfect man,...&lt;br /&gt;
Instead of&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;iAudioBuffer.CreateL(16*4096);&lt;br /&gt;iAudioBuffer.Create&lt;span style=&quot;font-weight:bold&quot;&gt;Max&lt;/span&gt;L(16*4096);&lt;/code&gt;&lt;/div&gt;Do the work &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;br /&gt;
Alternatively,&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;iAudioBuffer.CreateL(16*4096);&lt;br /&gt;iAudioBuffer.SetMax();&lt;/code&gt;&lt;/div&gt;Should work (I didnt tested it yet).&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt; Append of course also works, but only if you add the buffers in order, and I thought a requirement was that they could come out-of-order.&lt;/blockquote&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Yep, trying to solve my problem, I create a method to sort them, losing some time, but doing it right...&lt;/p&gt;

&lt;p&gt;Now I have more &quot;tools&quot; to do the reconstruction... I&#039;ll do it all over again, and in a few (7 &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;) days I&#039;ll let you know how did it go.&lt;br /&gt;
&lt;img src=&quot;/sites/all/modules/smileys/packs/example/lol.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; /&gt;&lt;/p&gt;

&lt;p&gt;PD: For other people reading this thread this link may help a lot &lt;img src=&quot;/sites/all/modules/smileys/packs/example/wink.png&quot; title=&quot;Eye-wink&quot; alt=&quot;Eye-wink&quot; /&gt; &lt;a href=&quot;http://descriptors.blogspot.com/2005/06/33-can-you-give-example-of-how-to-use.html&quot;&gt;http://descriptors.blogspot.com/2005/06/33-can-you-give-example-of-how-to-use.html&lt;/a&gt;&lt;/p&gt;</description>
 <pubDate>Tue, 27 May 2008 10:05:49 +0200</pubDate>
 <dc:creator>Sikkimes</dc:creator>
 <guid isPermaLink="false">comment 46560 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46559</link>
 <description>&lt;p&gt;We were posting at the same time, LOL.&lt;/p&gt;

&lt;p&gt;Thanks for the explanation, I got it perfectly... I just wanted to use my -already created- structure to store my buffers, because when I receive packets I stored them in an array, and the reconstruction is made after in other method that I thought that could use the same array.&lt;br /&gt;
Graphically, it would be like this:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;iAudioBuffer[0] = XXXXXXXXXX // buffer of 10 samples received OK&lt;br /&gt;iAudioBuffer[1] = XXXXXXXXXX // buffer of 10 samples received OK&lt;br /&gt;iAudioBuffer[2] = __________ // buffer lost &amp;lt;- this one I wanted to be able to reconstruct it sample by sample.&lt;br /&gt;iAudioBuffer[3] = XXXXXXXXXX // buffer of 10 samples received OK&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
But its ok now, as my last post say, the method do what I wanted (although it sounds really bad &lt;img src=&quot;/sites/all/modules/smileys/packs/example/tongue.png&quot; title=&quot;Sticking out tongue&quot; alt=&quot;Sticking out tongue&quot; /&gt;)&lt;br /&gt;
Thanks. Bye.&lt;/p&gt;</description>
 <pubDate>Tue, 27 May 2008 09:50:02 +0200</pubDate>
 <dc:creator>Sikkimes</dc:creator>
 <guid isPermaLink="false">comment 46559 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46558</link>
 <description>&lt;p&gt;Ah.. I think I know what the problem is now.&lt;/p&gt;

&lt;p&gt;When you &quot;Create&quot; the buffer, you get a buffer with the maxlength of what you specify.&lt;br /&gt;
but Length is still set to 0, even though the memory for the whole array is allocated.&lt;br /&gt;
So before you can use =  you have to do do:&lt;br /&gt;
&lt;pre class=&quot;bb-code-block&quot;&gt;
iAudioBuffer.SetMax();
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;The out-of-bounds check on [] is on the Length and not on the MaxLength....&lt;/p&gt;

&lt;p&gt;Append ofcourse also works, but only if you add the buffers in order, and I thought a requirement was that they could come out-of-order.&lt;/p&gt;

&lt;p&gt;Append is also a bit slower since each assignment also has to update the length of the descriptor.&lt;/p&gt;</description>
 <pubDate>Tue, 27 May 2008 09:47:39 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46558 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46556</link>
 <description>&lt;p&gt;Ive already &quot;found&quot; (just by following alh indications) a solution, replacing the assignment ( = ) by Append().&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;RBuf8 iAudioBuffer; //.h&lt;br /&gt;iAudioBuffer.CreateL(4096);&lt;br /&gt;for(TInt i = 0; i &amp;lt; 4096; i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; iAudioBuffer.Append(aBuffer[i]);&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;because:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; iAudioBuffer[i] = aBuffer[i]; // crashes &lt;img src=&quot;/sites/all/modules/smileys/packs/example/sad.png&quot; title=&quot;Sad&quot; alt=&quot;Sad&quot; /&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;It doesnt sound like I expected, but at least do what I wanted to do &lt;img src=&quot;/sites/all/modules/smileys/packs/example/lol.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; /&gt;&lt;br /&gt;
Thank you so much.&lt;/p&gt;

&lt;p&gt;PD: Definitely I&#039;ll replace my TBufs with RBufs,... to create objects dynamically, makes my life easier &lt;img src=&quot;/sites/all/modules/smileys/packs/example/lol.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; /&gt;&lt;/p&gt;</description>
 <pubDate>Tue, 27 May 2008 09:24:25 +0200</pubDate>
 <dc:creator>Sikkimes</dc:creator>
 <guid isPermaLink="false">comment 46556 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46555</link>
 <description>&lt;p&gt;I think the problem is that this:&lt;br /&gt;
&lt;pre class=&quot;bb-code-block&quot;&gt;
iAudioBuffer[0][startindex + i] = aBuffer[i]; // here it crashes.
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;should be:&lt;br /&gt;
&lt;pre class=&quot;bb-code-block&quot;&gt;
iAudioBuffer[0][i] = aBuffer[i]; // here it crashes.
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;in your case.&lt;/p&gt;

&lt;p&gt;My example used one single flat buffer, a single array, to store all audiodata. &lt;br /&gt;
Like this, here is place for 10 audiobuffers of 4096 bytes each:&lt;/p&gt;

&lt;p&gt;__________&lt;/p&gt;

&lt;p&gt;I called each of the logical buffers within the buffer for &quot;subbuffers&quot;&lt;br /&gt;
Then I used &quot;startindex&quot; to jump into the buffer, to write a part of it, lets say I want to write the 3rd audiobuffer.&lt;br /&gt;
I used startindex to step into it and after writing my buffer would look like&lt;br /&gt;
__X_______&lt;/p&gt;

&lt;p&gt;Then I write the 5th buffer too and my buffer would look like&lt;/p&gt;

&lt;p&gt;__X_X_____ &lt;/p&gt;

&lt;p&gt;Then write the 4th buffer and it would look like&lt;/p&gt;

&lt;p&gt;__XXX_____&lt;/p&gt;

&lt;p&gt;etc...&lt;/p&gt;

&lt;p&gt;In your example code on the other hand, you do not use a flat buffer, you are using a 2-dimensional buffer, or as its also called &quot;and array of arrays&quot;&lt;/p&gt;

&lt;p&gt;which could be diagrammed like this:&lt;/p&gt;

&lt;p&gt;_&lt;br /&gt;
_&lt;br /&gt;
_&lt;br /&gt;
_&lt;br /&gt;
_&lt;br /&gt;
_&lt;/p&gt;

&lt;p&gt;Then you use the first parantesis to select which &quot;sub buffer&quot;, and you must use 0-based index to index into that sub-buffer.&lt;/p&gt;

&lt;p&gt;I prefer the flat buffer approach, feels like I have more control, and I don&#039;t have to keep track of two indexes when using it.&lt;br /&gt;
And easier when scanning through all samples, since they all are guaranteed to be just after the previous sample in memory.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Tue, 27 May 2008 08:53:00 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46555 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46547</link>
 <description>&lt;p&gt;Mmmmm...  Im a bit confused.&lt;br /&gt;
I can select what subbuffer to use by the first [], what I cant do is to write some bytes inside that buffer.&lt;/p&gt;

&lt;p&gt;Let try in other words... I have an array of 16 TBuf8 objects, and I can access to them with iAudioBuffer[0], iAudioBuffer[1], ... iAudioBuffer[15], right?&lt;br /&gt;
Then what I need is to write the first, say, 5 bytes (==subbufers?) of one of this objects.&lt;br /&gt;
I thought that it has to be something like this:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;( (iAudioBuffer[2]) [startindex] ) = myBlah;&lt;br /&gt;(&amp;nbsp;&amp;nbsp; (the Object)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; theOffset&amp;nbsp;&amp;nbsp; ) = myBlah;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
But as I say it didnt work &lt;img src=&quot;/sites/all/modules/smileys/packs/example/sad.png&quot; title=&quot;Sad&quot; alt=&quot;Sad&quot; /&gt; (I use parenthesis to prioritize)&lt;/p&gt;

&lt;p&gt;Could you explain me how to do that?&lt;br /&gt;
Thanks a lot for ur time.&lt;/p&gt;</description>
 <pubDate>Mon, 26 May 2008 23:44:27 +0200</pubDate>
 <dc:creator>Sikkimes</dc:creator>
 <guid isPermaLink="false">comment 46547 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46532</link>
 <description>&lt;p&gt;If you use a 2d-buffer, you don&#039;t have to offset with the &quot;startindex&quot;, then you select what subbuffer to use by the first []&lt;/p&gt;

&lt;p&gt;My example used a simple 1dimensional buffer, and then you need the &quot;startindex&quot; offset to jump to the next &quot;subbuffer&quot; within the buffer.&lt;/p&gt;

&lt;p&gt;Similar to how you step between scanlines when accessing raw images... &lt;/p&gt;</description>
 <pubDate>Mon, 26 May 2008 14:33:08 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46532 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46520</link>
 <description>&lt;p&gt;Thanks to all of you guys.&lt;br /&gt;
The info provided by you give me good indications, and also helped me to understand more about this language.&lt;/p&gt;

&lt;p&gt;But I have another problem/question  &lt;img src=&quot;/sites/all/modules/smileys/packs/example/puzzled.png&quot; title=&quot;Puzzled&quot; alt=&quot;Puzzled&quot; /&gt;: I have an array of buffers (still working with TBuf8 to make sure the functionality is working, once functionality is ok I&#039;ll move all my buffers to Rbuf8 I promess &lt;img src=&quot;/sites/all/modules/smileys/packs/example/wink.png&quot; title=&quot;Eye-wink&quot; alt=&quot;Eye-wink&quot; /&gt;) and I want to do the assignment suggested by alh, so how can I do that?&lt;/p&gt;

&lt;p&gt;I supposed that &lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;TBuf8&amp;lt;4096&amp;gt; iAudioBuffer[16]; // the array in my .h&lt;br /&gt;iAudioBuffer[0-15][startindex + i] = aBuffer[i]; // here it crashes.&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;will do it, but it crashes with User -21 panic, telling me that some index is out of bounds.&lt;br /&gt;
[startindex + i] is 0 when it crashes, and the cause its not the arithmetic operation in the index of the array, because [0] (as a number) fails as well.&lt;/p&gt;

&lt;p&gt;Im &quot;completely&quot; sure that &lt;code&gt;aBuffer[i]&lt;/code&gt; has info and its not the cause of the problem (I write to a console its value and aBuffer[0] is 0).&lt;br /&gt;
I also know that iAudioBuffer[some sample between 1 to 16] has no data, because it hasn&#039;t been written by any method or function.&lt;br /&gt;
I thought that RBuf8 and TBuf8 could be distinct, but in this case, both has TUint8&amp; operator[](TInt anIndex); inherited from TDes8.&lt;/p&gt;

&lt;p&gt;Please help me...&lt;br /&gt;
Thanks once again &lt;img src=&quot;/sites/all/modules/smileys/packs/example/lol.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; /&gt;&lt;/p&gt;</description>
 <pubDate>Mon, 26 May 2008 09:06:42 +0200</pubDate>
 <dc:creator>Sikkimes</dc:creator>
 <guid isPermaLink="false">comment 46520 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46457</link>
 <description>&lt;p&gt;It&#039;s better to use RBuf8 or HBufC8 as alh suggested, and allocate your buffers dynamically. You can also use TDes::Insert to insert data in between existing data.&lt;/p&gt;</description>
 <pubDate>Wed, 21 May 2008 10:14:21 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 46457 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46439</link>
 <description>&lt;p&gt;You can try increasing your stacksize by a significant amount using EPOCSTACKSIZE  directive in your mmp file too.&lt;/p&gt;</description>
 <pubDate>Tue, 20 May 2008 19:34:10 +0200</pubDate>
 <dc:creator>jupitar</dc:creator>
 <guid isPermaLink="false">comment 46439 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comment-46434</link>
 <description>&lt;p&gt;You can write at any position in a TBuf, not only at the end.&lt;br /&gt;
just use operator[] to index into it.&lt;/p&gt;

&lt;p&gt;You shouldn&#039;t use TBuf:s though for this, a better idea is RBufs, that always keep its storage on the heap.&lt;br /&gt;
TBuf:s this big, if declared as automatic stack variables will bust your stack very quickly.&lt;/p&gt;

&lt;p&gt;&lt;pre class=&quot;bb-code-block&quot;&gt;
RBuf8 iAudioBuffer; //a member in some class somewhere
TBool iHasContent[16]; //flag field would be more efficient, but bools are easy....

[...]
iAudioBuffer.CreateL(16*4096); // space for 16 samples;

[...]
void CMyClass::AddSample(TInt aSampleNo, const TDesC8&amp; aBuffer) {
   TInt startindex = aSampleNo*4096;
   for(TInt i = 0; i &amp;lt; 4096; i++) {
     iAudioBuffer[startindex + i] = aBuffer[i];
  }
  iHasContent[aSampleNo] = ETrue;
}

&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;(Its possible to make a little bit more efficient using Mem::Copy instead of a for-loop)&lt;/p&gt;</description>
 <pubDate>Tue, 20 May 2008 11:19:52 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46434 at http://www.newlc.com</guid>
</item>
<item>
 <title>Please help, with buffers and/or arrays.</title>
 <link>http://www.newlc.com/forum/please-help-buffers-andor-arrays</link>
 <description>&lt;p&gt;Hi everybody,&lt;/p&gt;

&lt;p&gt;Im trying to measure some technics about audio reconstruction in symbian, and to do that Im sending 4 mixed packets of 4 samples of audio to a receiver to do the reconstruction. I mean, the sequence is:&lt;br /&gt;
- to record 16 samples of audio&lt;br /&gt;
- to add a header to each one to indicate his original position&lt;br /&gt;
- to pack groups of 4 samples of audio&lt;br /&gt;
- and send it to receiver&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/forum/please-help-buffers-andor-arrays&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/forum/please-help-buffers-andor-arrays#comments</comments>
 <category domain="http://www.newlc.com/forums/symbian-c">Symbian C++</category>
 <pubDate>Tue, 20 May 2008 11:02:59 +0200</pubDate>
 <dc:creator>Sikkimes</dc:creator>
 <guid isPermaLink="false">20975 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
