On 27.09.2008 03:35, Jim Sager wrote:
> I copied the following code from sndtest.  I am able to play the sound, 
> but I do not know how to deallocate the memory.  Can someone please 
> advise me what I'd have to type to deallocate memory?
> 
> I see five things to deallocate:
> soundbuf,snddata,sndstream,sndsource,sndsource3d
> 
> I just don't know what to type to deallocate them.

First, keep in mind these are interfaces and thus the underlying 
instances are freed when the last reference to them is 'released'. From 
the looks of it you use csRef<>s to store the interface pointers - good, 
that means you don't have to worry about releasing much: as soon as the 
csRef<> instances are destroyed the underlying objects are released (and 
if no other references are held, freed).

Now, pay attention to where the refs are declared. soundbuf, snddata, 
sndstream are local variables - so they're actually released as soon as 
that method below is left, you don't have to worry about them.

sndsource and sndsource3d are probably class members; that is, they are 
released when the class instance gets destroyed. If that is too late for 
you, you can do one of the following:
- assign another interface, the previously interface gets released
- manually clear the reference by calling e.g. sndsource.Invalidate()

hth,
-f.r.

> 
> const char* fname = "/this/data/lesson1/1.wav";
>   csRef<iDataBuffer> soundbuf = VFS->ReadFile (fname);
>   if (!soundbuf)
>     {
> printf("Can't load file '%s'! \n", fname);
> exit(0);
> 
> }
>   csRef<iSndSysData> snddata = sndloader->LoadSound (soundbuf);
>   if (!snddata)
>  {
>    printf("Can't load sound '%s'! \n", fname);
> exit(0);
> }
> 
>   csRef<iSndSysStream> sndstream = sndrenderer->CreateStream (snddata,
>       CS_SND3D_ABSOLUTE);
>   if (!sndstream)
> {
> printf("Can't create stream for '%s'!\n", fname);
> exit(0);
> }
> 
> 
>   sndsource = sndrenderer->CreateSource (sndstream);
>   if (!sndsource)
> {
> printf("Can't create source for '%s'!\n", fname);
> exit(0);
> }
>   sndsource3d = scfQueryInterface<iSndSysSourceSoftware3D> (sndsource);
> 
>   sndsource3d->SetPosition (GetSoundPos (0));
>   sndsource3d->SetVolume (3.0f);
> 
>   sndstream->Unpause ();
> 
> 
> ------------------------------------------------------------------------
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Crystal-main mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/crystal-main
> Unsubscribe: mailto:[EMAIL PROTECTED]


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]

Reply via email to