Thread: gernerating sound from motherboard

  1. #16
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    Quote Originally Posted by CChakra View Post
    I tried to play with assembly language to generate sounds but it's a big pain in neck.I don't
    want to remember horrible instructions to generate a simple ring tone. LOL

    So I want the calculation tips to generate sounds.Please provide me any charts or something
    like that.

    best regards,
    Chakra


    here's the "scratchpad" code i was referring to earlier.

    Code:
            sine *s = new sine();
            s->a = 1;
            s->f = 0.0928798185941/2;
            controlPanel *p = new controlPanel(this,s);
    
            WAVEFORMATEX format;
    
            format.wFormatTag = WAVE_FORMAT_PCM;
            format.nChannels = 2;
            format.nSamplesPerSec = 44100;
            format.wBitsPerSample = 16;
            format.nBlockAlign = format.nChannels*format.wBitsPerSample/8;
            format.nAvgBytesPerSec = format.nBlockAlign*format.nSamplesPerSec;
            format.cbSize =0;
    
    
            HANDLE output;
    
             MMRESULT result = waveOutOpen(
                    &output,
                    WAVE_MAPPER,
                     &format,
                    0,
                    0,
                    CALLBACK_NULL
            );
    
            if(result==MMSYSERR_NOERROR)
            {
                    const unsigned int wl = 65536;
                    unsigned short maxv = pow(2,8*sizeof(maxv)-1);
                    char wave[wl];
                    for(int i=0;i<wl;i+=sizeof(maxv))
                    {
                            short v = 0.025*maxv*s->value(i);
                            *(short *)(wave+i)= v;
                    }
                    WAVEHDR header;
                    header.lpData = wave;
                    header.dwBufferLength = wl;
                    header.dwFlags = WHDR_BEGINLOOP;
                    header.dwLoops = 0;
                    MMRESULT wowresult;
                    MMRESULT wophresult = waveOutPrepareHeader(
                      output,
                      &header,
                      sizeof(header)
                    );
                    int a;
                    switch(wophresult)
                    {
                            case MMSYSERR_NOERROR:
    
                                    wowresult = waveOutWrite(output,&header,wl);
                                    break;
                            case MMSYSERR_INVALHANDLE:
                                    a=0;
                                    break;
                            case MMSYSERR_NODRIVER:
                                    a=0;
                                    break;
                            case MMSYSERR_NOMEM:
                                    a=0;
                                    break;
                    }
            }
            else
            {
            }

    notes in even temperament (the more or less standard tuning scale used for most keyed instruments) can be related to each other by a factor of 2^(n/12) where n is the difference in number of semitones (notes, including sharps/flats).

    the note A is an integer. A4 is 440 Hz.
    Last edited by m37h0d; 01-30-2009 at 12:34 PM.

  2. #17

  3. #18
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    OpenAL will do this in much fewer lines of code and with less pain. Combine that with freealut which loads wav files and there really is no substitute.

  4. #19
    Registered User
    Join Date
    Sep 2008
    Posts
    76
    Bubba and M37h0d thanks for your precious information.

    What you explained me is beyond my question. Hehehe

    What I actually wanted was to generate sound from internal PC speaker.Just a ring-tone nothing
    more.Well I am not serious c++ programmer.I have only played with Turbo C++ not high and
    heavy APIS.

    Well I got the function Beep(int,int) which does that.But I don't understand how to put values
    on it what I got from a ring-tone web-site.

    for ex:

    Code:
    g,8p,16a#.,8p,16g,16p,16g,8c6,8g,8f,8g,8p,16d.6,8p,16g,16p,
    16g,8d#6,8d6,8a#,8g,8d6,8g6,16g,16f,16p,16f,8d,8a#,2g,4p,16f6,8d6,
    8c6,8a#,4g,8a#.,16g,16p,16g,8c6,8g,8f,4g,8d.6,16g.

  5. #20
    Registered User
    Join Date
    Sep 2008
    Posts
    76

    Dos.h from Turbo C 3.0

    I am curious to know how sound() function works.If you have time and goodness
    please explain me.
    Last edited by CChakra; 01-31-2009 at 02:09 AM. Reason: had to delete the code of dos.h

  6. #21
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    Quote Originally Posted by CChakra View Post
    Bubba and M37h0d thanks for your precious information.

    What you explained me is beyond my question. Hehehe

    Code:
    g,8p,16a#.,8p,16g,16p,16g,8c6,8g,8f,8g,8p,16d.6,8p,16g,16p,
    16g,8d#6,8d6,8a#,8g,8d6,8g6,16g,16f,16p,16f,8d,8a#,2g,4p,16f6,8d6,
    8c6,8a#,4g,8a#.,16g,16p,16g,8c6,8g,8f,4g,8d.6,16g.

    notes in even temperament (the more or less standard tuning scale used for most keyed instruments) can be related to each other by a factor of 2^(n/12) where n is the difference in number of semitones (notes, including sharps/flats).

    the note A is an integer. A4 is 440 Hz.
    i don't know what all of the above are - some of them look sortof like notes, but i can't quite make sense of it.

    either way the self-quoted excerpt above is relevant to your interests.

    e.g:

    if A4 = 440Hz, what is the frequency of C4?

    counting the semitones, we have: A#,B,C = 3

    therefore C4 = A4*2^(3/12) = 440*1.189 = 523.25 Hz
    Last edited by m37h0d; 01-31-2009 at 11:12 AM.

  7. #22
    Registered User
    Join Date
    Sep 2008
    Posts
    76
    thanks for the method , you told me exactly what I was looking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sound lags in multi-thread version
    By VirtualAce in forum Game Programming
    Replies: 23
    Last Post: 08-27-2008, 11:54 AM
  2. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 01:58 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  4. DirectSound - multiple sounds
    By Magos in forum Game Programming
    Replies: 9
    Last Post: 03-03-2004, 04:33 PM
  5. sounds?
    By BODYBUILDNERD in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 03:34 PM