• PlaySound increases memory with some HDMI drivers

    From Delphi Jobs@21:1/5 to All on Mon Dec 5 08:09:36 2022
    Hi all

    This is the code I'm using for a long time to play sound
    After some time the memory would start to incrse and the system would crash, what am i doing wrong or is there a better way to play sound from a file or resource


    Any help, please..
    TIS_YON


    HB_FUNC( PLAYSOUND2 )
    {
    LPCSTR pszSound = ( hb_pcount()>0 && ISCHAR(1) )? hb_parc(1):NULL;
    HMODULE hmod = GetModuleHandle(NULL);
    DWORD fdwSound = SND_NODEFAULT;
    if( hb_pcount()>3 && ISLOG(4) && hb_parl(4) )
    fdwSound |= SND_RESOURCE;
    else
    fdwSound |= SND_FILENAME;
    if( hb_pcount()>1 && ISLOG(2) && hb_parl(2) )
    fdwSound |= SND_SYNC;
    else
    fdwSound |= SND_ASYNC;
    if( hb_pcount()>2 && ISLOG(3) && hb_parl(3) )
    fdwSound |= SND_LOOP;
    //if( !pszSound )
    // fdwSound |= SND_PURGE;
    hb_retl( PlaySound( pszSound, hmod, fdwSound ) );
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Mon Dec 5 18:56:37 2022
    Il 05/12/2022 17:09, Delphi Jobs ha scritto:

    Hi all

    This is the code I'm using for a long time to play sound
    After some time the memory would start to incrse and the system would crash, what am i doing wrong or is there a better way to play sound from a file or resource


    Any help, please..

    Try this:

    FUNCTION MAIN()


    SNDPLAYSOUND( "c:\windows\media\tada.wav", 0 )

    RETURN NIL


    #pragma BEGINDUMP

    #include "windows.h"
    #include "hbapi.h"


    HB_FUNC( SNDPLAYSOUND )
    {
    hb_retnl( sndPlaySound( hb_parc( 1 ), hb_parni( 2 ) ) );
    }

    #pragma ENDDUMP

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Delphi Jobs on Tue Dec 6 06:32:40 2022
    Dear Delphi Jobs:

    On Monday, December 5, 2022 at 9:09:38 AM UTC-7, Delphi Jobs wrote:
    Hi all

    This is the code I'm using for a long time to play sound
    After some time the memory would start to incrse and the
    system would crash, what am i doing wrong or is there a
    better way to play sound from a file or resource

    So you are allocating memory, but not releasing it. Or could use STATIC / LOCAL variables, that are defined once.

    Any help, please..
    TIS_YON


    HB_FUNC( PLAYSOUND2 )
    {
    LPCSTR pszSound = ( hb_pcount()>0 && ISCHAR(1) )? hb_parc(1):NULL;

    You have just allocated memory, pszSound

    HMODULE hmod = GetModuleHandle(NULL);

    You have just allocated memory, hmod

    DWORD fdwSound = SND_NODEFAULT;

    You have just allocated memory, fdwSound

    if( hb_pcount()>3 && ISLOG(4) && hb_parl(4) )
    fdwSound |= SND_RESOURCE;
    else
    fdwSound |= SND_FILENAME;
    if( hb_pcount()>1 && ISLOG(2) && hb_parl(2) )
    fdwSound |= SND_SYNC;
    else
    fdwSound |= SND_ASYNC;
    if( hb_pcount()>2 && ISLOG(3) && hb_parl(3) )
    fdwSound |= SND_LOOP;
    //if( !pszSound )
    // fdwSound |= SND_PURGE;

    ... So I'd put the call to PlaySound on its own line, and add:

    PlaySound( pszSound, hmod, fdwSound )
    RELEASE pszSound, hmod, fdwSound
    hb_retl( .T. );
    }

    You could also do something with the keyword LOCAL for each of those definitions, and not have to do the release.
    Enrico's method is NOT wrong, but does not address why you are having a memory leak.

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Tue Dec 6 16:30:35 2022
    Il 06/12/2022 15:32, dlzc ha scritto:

    So you are allocating memory, but not releasing it. Or could use STATIC / LOCAL variables, that are defined once.

    LPCSTR pszSound = ( hb_pcount()>0 && ISCHAR(1) )? hb_parc(1):NULL;

    You have just allocated memory, pszSound

    You are confusing xHarbour code and C code. For me the problem is in the PlaySound() function that I don't know what it does.

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Enrico Maria Giordano on Tue Dec 6 08:51:56 2022
    Dear Enrico:

    On Tuesday, December 6, 2022 at 8:32:35 AM UTC-7, Enrico Maria Giordano wrote:
    Il 06/12/2022 15:32, dlzc ha scritto:

    So you are allocating memory, but not releasing it. Or could
    use STATIC / LOCAL variables, that are defined once.

    LPCSTR pszSound = ( hb_pcount()>0 && ISCHAR(1) )? hb_parc(1):NULL;

    You have just allocated memory, pszSound

    You are confusing xHarbour code and C code.
    ... the Newsgroup they are asking on. How are these variables defined, made 'LOCAL' in C? In the function definition, right?

    https://www.geeksforgeeks.org/variables-in-c/
    ... looks like "STATIC" is a better choice, and lose the 'release' suggestion.

    For me the problem is in the
    PlaySound() function that I don't know what it does.

    Could be a non-trivial memory leak there too, sure. Sound files are often large. Maybe log free memory before and after each call?

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Tue Dec 6 18:50:01 2022
    Il 06/12/2022 17:51, dlzc ha scritto:

    You are confusing xHarbour code and C code.

    ... the Newsgroup they are asking on. How are these variables defined, made 'LOCAL' in C? In the function definition, right?

    They are already defined as the C equivalent of LOCAL. There is no
    memory leak in that code. The only place where it could be is, as I
    alredy wrote, the unknown function PlaySound().

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Enrico Maria Giordano on Tue Dec 6 12:02:42 2022
    On Tuesday, December 6, 2022 at 10:50:01 AM UTC-7, Enrico Maria Giordano wrote:
    Il 06/12/2022 17:51, dlzc ha scritto:

    You are confusing xHarbour code and C code.

    ... the Newsgroup they are asking on. How are these variables defined,
    made 'LOCAL' in C? In the function definition, right?

    They are already defined as the C equivalent of LOCAL. There is no
    memory leak in that code. The only place where it could be is, as I
    alredy wrote, the unknown function PlaySound().

    Agreed on PlaySound. I find a thread on MSN that cite it (presumably built-in language function) as 1 Meg with every call, but might be out-of-date.

    Thanks for your persistence / tolerance.

    David A. Smith (I don't do C, it makes me C-sick.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Delphi Jobs@21:1/5 to dlzc on Tue Dec 6 14:46:57 2022
    On Tuesday, December 6, 2022 at 3:02:43 PM UTC-5, dlzc wrote:
    On Tuesday, December 6, 2022 at 10:50:01 AM UTC-7, Enrico Maria Giordano wrote:
    Il 06/12/2022 17:51, dlzc ha scritto:

    You are confusing xHarbour code and C code.

    ... the Newsgroup they are asking on. How are these variables defined, made 'LOCAL' in C? In the function definition, right?

    They are already defined as the C equivalent of LOCAL. There is no
    memory leak in that code. The only place where it could be is, as I
    alredy wrote, the unknown function PlaySound().
    Agreed on PlaySound. I find a thread on MSN that cite it (presumably built-in language function) as 1 Meg with every call, but might be out-of-date.

    Thanks for your persistence / tolerance.

    David A. Smith (I don't do C, it makes me C-sick.)

    Hi All and thanks so much for the help
    I did not have a chance yet to test

    I believe playSound took over the Microsoft legacy sndPlaySound http://www.jasinskionline.com/windowsapi/ref/s/sndplaysound.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Delphi Jobs on Wed Dec 7 06:35:24 2022
    On Tuesday, December 6, 2022 at 3:46:59 PM UTC-7, Delphi Jobs wrote:
    Hi All and thanks so much for the help
    I did not have a chance yet to test

    I believe playSound took over the Microsoft legacy sndPlaySound http://www.jasinskionline.com/windowsapi/ref/s/sndplaysound.html

    It is entirely possible it is just a wrapper problem, since PlaySound is also a WIN32 control. Should not be a leak in the Windoze code itself...
    https://learn.microsoft.com/en-us/windows/win32/multimedia/using-playsound-to-play-system-sounds

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)