playing raw waveform (MMsystem) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

playing raw waveform (MMsystem)

dzanossidzanossi Posts: 6Member
how to encode the waveform in the buffer, for ex. if i would like to achieve sine sound ?

Comments

  • JonathanJonathan Posts: 2,914Member
    : how to encode the waveform in the buffer, for ex. if i would like to
    : achieve sine sound ?
    :
    Easy way that may[1] work:

    1) Generate a single cycle of the sine wave.
    2) Use waveOutOpen and do stuff needed to prepare the wave output device.
    3) Create a wave header, specifying the buffer containing the single cycle as the data. [2]
    4) Prepare the header (waveOutPrepareHeader)
    5) waveOutWrite it.
    6) Keep a pointer to that header. Prepare the next one.
    7) waveOutWrite the next one.
    8) waveOutUnprepareHeader the last header you kept the pointer to. This should (maybe only if you give the "right" parameters) not return until that bit of data was played. There are perhaps better ways of doing this, involving callbacks, but I don't think anything beats the simplicity of this approach if it's appropriate for your app.
    9) Loop...

    Here's my implementation of the waveOut APIs from AMaMP [3]:-
    http://cvs.sourceforge.net/viewcvs.py/*checkout*/amamp/core/amamp_io_win32wave.c?content-type=text/plain&rev=1.10

    Hope this helps,

    Jonathan

    [1] I say "may" because it may complain about you feeding it pointers to the same buffer again and again, due to drivers perhaps locking it. If this is the case, simply make a copy of the single cycle of the sine wave each time you create a wave header, before preparing it. Don't forget to free the memory after you unprepare the header. I did this and ended up with an app that leaked memory at a rate of 10 megs per minute. Really!

    [2] In fact, you may want several cycles, particularly if it's a higher frequency, so you aren't being too inefficient and making loads of API calls and maybe memory copies for lots of tiny bits of data.

    [3] http://amamp.sourceforge.net/

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • rpalmarpalma Posts: 4Member
    : : how to encode the waveform in the buffer, for ex. if i would like to
    : : achieve sine sound ?
    : :
    : Easy way that may[1] work:
    :
    : 1) Generate a single cycle of the sine wave.
    : 2) Use waveOutOpen and do stuff needed to prepare the wave output device.
    : 3) Create a wave header, specifying the buffer containing the single cycle as the data. [2]
    : 4) Prepare the header (waveOutPrepareHeader)
    : 5) waveOutWrite it.
    : 6) Keep a pointer to that header. Prepare the next one.
    : 7) waveOutWrite the next one.
    : 8) waveOutUnprepareHeader the last header you kept the pointer to. This should (maybe only if you give the "right" parameters) not return until that bit of data was played. There are perhaps better ways of doing this, involving callbacks, but I don't think anything beats the simplicity of this approach if it's appropriate for your app.
    : 9) Loop...
    :
    : Here's my implementation of the waveOut APIs from AMaMP [3]:-
    : http://cvs.sourceforge.net/viewcvs.py/*checkout*/amamp/core/amamp_io_win32wave.c?content-type=text/plain&rev=1.10
    :
    : Hope this helps,
    :
    : Jonathan
    :
    : [1] I say "may" because it may complain about you feeding it pointers to the same buffer again and again, due to drivers perhaps locking it. If this is the case, simply make a copy of the single cycle of the sine wave each time you create a wave header, before preparing it. Don't forget to free the memory after you unprepare the header. I did this and ended up with an app that leaked memory at a rate of 10 megs per minute. Really!
    :
    : [2] In fact, you may want several cycles, particularly if it's a higher frequency, so you aren't being too inefficient and making loads of API calls and maybe memory copies for lots of tiny bits of data.
    :
    : [3] http://amamp.sourceforge.net/
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

  • rpalmarpalma Posts: 4Member
    Hi Jonathan,

    I am unable to locate your referenced file.

    amamp_io_win32wave.c

    I'm not usre if there is something wrong with the URL.

    Any help would be much appreciated.

    Thank-you,
    Robert













    : : how to encode the waveform in the buffer, for ex. if i would like to
    : : achieve sine sound ?
    : :
    : Easy way that may[1] work:
    :
    : 1) Generate a single cycle of the sine wave.
    : 2) Use waveOutOpen and do stuff needed to prepare the wave output device.
    : 3) Create a wave header, specifying the buffer containing the single cycle as the data. [2]
    : 4) Prepare the header (waveOutPrepareHeader)
    : 5) waveOutWrite it.
    : 6) Keep a pointer to that header. Prepare the next one.
    : 7) waveOutWrite the next one.
    : 8) waveOutUnprepareHeader the last header you kept the pointer to. This should (maybe only if you give the "right" parameters) not return until that bit of data was played. There are perhaps better ways of doing this, involving callbacks, but I don't think anything beats the simplicity of this approach if it's appropriate for your app.
    : 9) Loop...
    :
    : Here's my implementation of the waveOut APIs from AMaMP [3]:-
    : http://cvs.sourceforge.net/viewcvs.py/*checkout*/amamp/core/amamp_io_win32wave.c?content-type=text/plain&rev=1.10
    :
    : Hope this helps,
    :
    : Jonathan
    :
    : [1] I say "may" because it may complain about you feeding it pointers to the same buffer again and again, due to drivers perhaps locking it. If this is the case, simply make a copy of the single cycle of the sine wave each time you create a wave header, before preparing it. Don't forget to free the memory after you unprepare the header. I did this and ended up with an app that leaked memory at a rate of 10 megs per minute. Really!
    :
    : [2] In fact, you may want several cycles, particularly if it's a higher frequency, so you aren't being too inefficient and making loads of API calls and maybe memory copies for lots of tiny bits of data.
    :
    : [3] http://amamp.sourceforge.net/
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

  • JonathanJonathan Posts: 2,914Member
    : I am unable to locate your referenced file.
    :
    : amamp_io_win32wave.c
    :
    : I'm not usre if there is something wrong with the URL.
    :
    SourceForge have had a few issues with their CVS web view tool. It appears to be working again now.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.