Sound & MIDI - what's a DWORD?

This is a discussion on Sound & MIDI - what's a DWORD? within the C++ Programming forums, part of the General Programming Boards category; I just cludged this together today Code: #include <windows.h> #include <cmath> #include <iostream> #include <iomanip> using namespace std; double Semitone ...

  1. #1
    -JM
    -JM is offline
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79

    Sound & MIDI - what's a DWORD?

    I just cludged this together today

    Code:
    #include <windows.h>
    #include <cmath>
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    double Semitone = pow(2.0,(1.0/12.0));
    double Pitch = 16.3516;
    
    
    int main()
    {
        cout<<left;
        cout<<"Chromatic Scale: Eight Octaves with frequencies";
        for (int n = 12; n<109; n++) // Corresponding to MIDI note numbers
        {if (!(n%6))
        {cout<<endl;
        if (!(n%12))
        {cout<<endl;}}
        cout<<setw(12)<<Pitch;
        Beep(Pitch, 75);
        Pitch = Pitch*Semitone;
        }
        cout<<"Done!";
        cin.get();
        return 0;
    }
    but I'd like to MIDI it, and then move on to truly useful stuff. I've got the simple "C-E-G" MIDI code working, but what the heck is a DWORD and how do I insert my desired note # into the 5th and 6th hex digits??

    Thanks -

    JM

    (lots of books but no time or patience!)
    Huh?

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    A DWORD stands for double word, which is 4 bytes. Treat it as a 4 byte unsigned intiger.

  3. #3
    -JM
    -JM is offline
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    Duh, that makes sense! Thanks - now how can I replace the 2nd (3rd?) byte with a variable?
    Code:
    DWORD NoteC = 0x007f3c90; 
    DWORD NoteE = 0x007f4090; 
    DWORD NoteG = 0x007f4390;
    something like

    Code:
    DWORD NoteX = 0x007fX90
    if X is two hex digits.

    Sorry for the stupid n00b questions!

    -JM
    Huh?

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Code:
    0x007f0090 | (myVariable << 8)
    Where myVariable has values of 0 - 255. The | is the binary OR operator, and the << is a bitwise shift. Binary or takes each bit of the two operators, and if either one is 1, the corresponding bit in the result is 1, otherwise zero. Bitwise shifts just move bits. The binary number 10110 shifted two to the left is 1011000. (Bits will fall off of both ends. 1001 shifted right once is 100.) Google for more info.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    -JM
    -JM is offline
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    Exactly what I needed - thanks!
    Huh?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 03:48 PM
  2. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 12:58 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 11:38 AM
  4. DirectSound - multiple sounds
    By Magos in forum Game Programming
    Replies: 9
    Last Post: 03-03-2004, 03:33 PM
  5. sounds?
    By BODYBUILDNERD in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 02:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21