🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.multimedia
9 messages
9 total messages Started by Jonathan Benedicto Fri, 13 May 2005 20:42
memory fragmentation
#137
Author: Jonathan Benedicto
Date: Fri, 13 May 2005 20:42
6 lines
1102 bytes
Would allocating new 8192 byte wave buffers every 1/4 second affect a 
computer's performance significantly ? I mean, if I kept allocating 
and freeing those buffers, would excessive RAM fragmentation result ?

Jonathan
 
Re: memory fragmentation
#139
Author: Mark Jacobs
Date: Mon, 16 May 2005 09:03
24 lines
1723 bytes
Jonathan Benedicto wrote:
> Would allocating new 8192 byte wave buffers every 1/4 second affect a 
> computer's performance significantly ? I mean, if I kept allocating 
> and freeing those buffers, would excessive RAM fragmentation result ?
> 
> Jonathan
>  
> 
> 
I suspect this is what is causing your clicks. I statically allocate 
everything on the heap, by defining vast 10 MByte structures like this :-

#define BFLIM 100001
#define NBFS 100
char wvbfr[NBFS][BFLIM];
WAVEHDR wvhd[NBFS];

Also, are you using the correct lengths?  If you are using OGG format, every 
1/4 second buffer will be a different length to the next. The member 
wvhd[nxtbf].dwBufferLength must be set correctly each time.

-- 
Mark Jacobs
http://www.dkcomputing.co.uk
Re: memory fragmentation
#140
Author: Jonathan Benedicto
Date: Mon, 16 May 2005 11:53
19 lines
1748 bytes
"Mark Jacobs" <http://www.jacobsm.com/mjmsg.htm?mj@critical> wrote in 
message news:428861c0@newsgroups.borland.com...
>
> I suspect this is what is causing your clicks. I statically allocate 
> everything on the heap, by defining vast 10 MByte structures like 
> this :-

Actually, if I do create a new buffer every time I need it, then the 
clicks disappear. It's just when I re-use one of those buffers that 
they come.

> Also, are you using the correct lengths?  If you are using OGG 
> format, every 1/4 second buffer will be a different length to the 
> next. The member wvhd[nxtbf].dwBufferLength must be set correctly 
> each time.

I set the dwBufferLength every time I fill the buffer.

Jonathan 
Re: memory fragmentation
#143
Author: Mark Jacobs
Date: Mon, 16 May 2005 15:19
11 lines
1550 bytes
Jonathan Benedicto wrote:
> Actually, if I do create a new buffer every time I need it, then the 
> clicks disappear. It's just when I re-use one of those buffers that 
> they come.

So, why not do that, and free the buffer after use. If allocating a new one 
every time and freeing it afterwards, means you get clickless playback, then 
use that. But I must admit, I am mystified by your problem.
-- 
Mark Jacobs
http://www.dkcomputing.co.uk
Re: memory fragmentation
#144
Author: Jonathan Benedicto
Date: Mon, 16 May 2005 15:25
12 lines
1549 bytes
"Mark Jacobs" <http://www.jacobsm.com/mjmsg.htm?mj@critical> wrote in 
message news:4288b9ba@newsgroups.borland.com...
>
> So, why not do that, and free the buffer after use. If allocating a 
> new one every time and freeing it afterwards, means you get 
> clickless playback, then use that. But I must admit, I am mystified 
> by your problem.

I didn't want to do that, because I thought that it might cause RAM 
fragmentation, especially if the system worked for a couple of hours.

Jonathan 
Re: memory fragmentation
#145
Author: Bruce Salzman
Date: Mon, 16 May 2005 15:46
23 lines
2071 bytes
>> I suspect this is what is causing your clicks. I statically 
>> allocate everything on the heap, by defining vast 10 MByte 
>> structures like this :-
>
> Actually, if I do create a new buffer every time I need it, then the 
> clicks disappear. It's just when I re-use one of those buffers that 
> they come.
>
>> Also, are you using the correct lengths?  If you are using OGG 
>> format, every 1/4 second buffer will be a different length to the 
>> next. The member wvhd[nxtbf].dwBufferLength must be set correctly 
>> each time.
>
> I set the dwBufferLength every time I fill the buffer.

Do you "new"/"delete" your buffers? I have found situations where 
Borland's memory manager returns memory blocks that are improperly 
aligned (as far as some WinAPI functions are concerned). You might try 
using GlobalAlloc()/GlobalFree() to see if your clicks go away.
Just my $.02.

-- 
Bruce 
Re: memory fragmentation
#146
Author: Jonathan Benedicto
Date: Mon, 16 May 2005 15:56
16 lines
1786 bytes
" Bruce Salzman" <bruce@nospam.org> wrote in message 
news:4288c053@newsgroups.borland.com...
>
> Do you "new"/"delete" your buffers? I have found situations where 
> Borland's memory manager returns memory blocks that are improperly 
> aligned (as far as some WinAPI functions are concerned). You might 
> try using GlobalAlloc()/GlobalFree() to see if your clicks go away.
> Just my $.02.

The crazy thing is that when I do use new / delete, I don't get the 
clicks. It is just when I re-use a buffer that was previously 
allocated that the clicks come.

But thank you for your input.

Jonathan 
Re: memory fragmentation
#149
Author: Mark Jacobs
Date: Tue, 17 May 2005 08:31
24 lines
2144 bytes
Jonathan Benedicto wrote:
> The crazy thing is that when I do use new / delete, I don't get the 
> clicks. It is just when I re-use a buffer that was previously 
> allocated that the clicks come.

 From what you have said so far, it looks like one of the entities in the wave 
header is not being set correctly, and I suspect it's the dwLoops member. I 
set dwLoops, dwBufferLength and lpData, every 1/4 second (buffer-full). This 
is what I use :-
...
   sounding=true;
   wvhd[nxtbf].lpData=wvbfr[nxtbf];
   wvhd[nxtbf].dwBufferLength=bfln[nxtbf];
   wvhd[nxtbf].dwLoops=0;
   wh=waveOutPrepareHeader(phwo,&wvhd[nxtbf],sizeof(WAVEHDR));
   if (wh==MMSYSERR_NOERROR)
     waveOutWrite(phwo,&wvhd[nxtbf],sizeof(WAVEHDR));
   else ShowMessage("waveOutPrepareHeader failed");
   sounding=false;
...
HTH
-- 
Mark Jacobs
http://www.dkcomputing.co.uk
Re: memory fragmentation
#154
Author: Jonathan Benedicto
Date: Tue, 17 May 2005 17:11
23 lines
1969 bytes
"Mark Jacobs" <http://www.jacobsm.com/mjmsg.htm?mj@critical> wrote in 
message news:4289ab9f@newsgroups.borland.com...
>
> From what you have said so far, it looks like one of the entities in 
> the wave header is not being set correctly, and I suspect it's the 
> dwLoops member. I set dwLoops, dwBufferLength and lpData, every 1/4 
> second (buffer-full). This is what I use :-

Thank you for continuing to provide ideas. I think that you may be 
right, because yesterday I tried a last resort:

char *TempBufferPtr = WaveHeader->lpData;
ZeroMemory(TempBufferPtr, 8192);
ZeroMemory(WaveHeader, sizeof(WAVEHDR));
WaveHeader->lpData = TempBufferPtr;

And it seems that the clicks are just about silenced. I can still hear 
them when I turn the speakers up, but that could be my sound card, 
speakers or mike. So I'm going to leave it at this.

Thank you again for your help.

Jonathan 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads