270 likes | 382 Vues
Ray Bradley Karla N. Juárez David Wood Advisor: Dr. Stephen Murrell May 2 nd , 2005. Overview. What is DMC? Implementation choices Equipment used Coding the game Beat detection Direct input Graphics Integration Testing Demonstration Improvements Thoughts. What is DMC?.
E N D
Ray Bradley Karla N. Juárez David Wood Advisor: Dr. Stephen Murrell May 2nd, 2005
Overview • What is DMC? • Implementation choices • Equipment used • Coding the game • Beat detection • Direct input • Graphics • Integration • Testing • Demonstration • Improvements • Thoughts
What is DMC? • DMC is based on very popular arcade game Dance Dance Revolution (DDR) • Simple Idea • Players stand on a mat • Step on the arrows that correspond to scrolling arrows • DMC is an enhanced version of DDR • Detects beats in real-time • Use your own music
DMC’s Features • Users choose a sound (.wav) file • Players can adjust • The frequency the game uses to find beats • The sensitivity used in determining beats • When a beat is detected in real-time, game randomly grabs a dance pattern and executes that pattern
Choices for Implementation • Graphics Library • OpenGL • DirectX • DirectInput • Coding Language • Java • C++ • Compatible with graphics libraries • Widely used in game programming • Beat Detection • Simple Sound Energy Algorithm • Frequency Selected Sound Energy Algorithm • Detection based on frequency • Detected beats missed by Simple Algorithm • Sound File Format • .WAV • Raw data • No compression
Gathering Equipment • MadCatz Beat Pad for Sony Playstation • Playstation to USB Converter/Adapter
Coding Overview • Beat Detection • Obtaining input from dance pad using DirectX • Graphics using DirectX
Beat Detection Theory • Sound Energy Algorithm • A beat is heard when the sound energy at that instant is greater than average of previous energies. • Instant ~ 23 ms • Sound History ~ 1 sec • Fast Fourier Transform • Separate sound into frequency sub-bands • Detect beats at specific frequency ranges
Beat Detection Implementation • Wave File • 44100 samples/sec • Stereo (2 channels) • Compute FFT of buffers, Left and Right • Packed together; Left: Real, Right: Imaginary • Unpacked with aid of the Fourier symmetries:
Beat Detection Implementation • Compute magnitude of complex pairs at chosen frequency sub-band • Sub-bands • 43 sub-bands • Width grows exponentially with frequency
Beat Detection Implementation • Compare computed instant energy density with local average energy density multiplied by a sensitivity constant • Adjust local average energy density by adding in newest and subtracting out oldest
Reading/Playing Wave Files • Wave Reader Class • Reads wave file • Supplies pointer to data buffer • Methods to refill the data buffer • Buffered Player Class • Manages communication with windows sound device • Uses 10 level buffering scheme • Accepts pointer to data buffer and refill function
DirectX’s Input Method • DirectInput gathers information from input device • Classes are designed to accommodate various devices • More control than using the Windows API for input devices
DirectInput • “Joystick” class provides access to functions specifically for “joystick” control • The following functions were used to access gamepad • EnumDevicesCallback(); • EnumObjectsCallback(); • DirectInput8Create(); • g_lpDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumDevicesCallback, NULL, DIEDFL_ATTACHEDONLY) • g_joystickDevice->EnumObjects( EnumObjectsCallback, NULL, DIDFT_ALL) • g_joystickDevice->Acquire();
DirectInput • Once the object has been “created” and “acquired” only two function calls are necessary to gather the pad’s input • g_joystickDevice->Poll(); • g_joystickDevice->GetDeviceState( sizeof(DIJOYSTATE2), &gamepad );
The Axis Problem • Driver for converter detects arrow pads as axes • Buffer was designed to remember the last 6 inputs • Could not be too large or it would affect game play • Timer controlled how often buffer would be updated
Contacting Soyo • Attempts were made to find alternative drivers for the converter • Contacted Soyo, still waiting for answer
Coding the Graphics • Two classes were created • Arrow Outline • Stationary • 4 objects used in game • Scrolling Arrow • Movement is required • 5 arrows for each direction are constructed, but not all used at a time
Coding the Graphics • Basic Arrow Class • Arrow(int intDirection) • bool IsActive(); • void ResetArrow(); • void SetTexture();
Graphics – Setting Texture • Arrow object can be made for any direction • Direction is passed as a parameter to constructor • Constructor chooses the region required for texture – bitmap image drawn on top of object • Coordinates from bitmap file correspond to screen coordinates
Graphics – Texture & Animation • Animation can be done by modifying bitmap-to-screen coordinates • Requires access to graphics card each time coordinates are modified • Faster approach is to use matrix translation D3DXMatrixTranslation(&mat, x, y, z) • Requires significant computing power when constantly rendering • Use a timer to send ‘Render’ signal
Graphics - Text • Easy to implement using Direct3D’s font class and methods • LPD3DXFONT • Used to • Confirm correct step • Keep score • Display frequency and sensitivity
Integration • The input objects were added directly to graphics code • Beat detection added • Single object • Instantiated in separate thread • Communicates using structure • Sends WM_BEAT message when beat detected • User interface added • Start screen • Open file dialog box • Frequency and sensitivity controls • OOP design made integration easy
Testing • Problems discovered • Delay between when the arrow was stepped on and when DMC registered step • Beat detection caused graphics to slow down • Tweaked the timing of WM_BEAT message
DMC Demo • Let’s play
Future Improvements • Graphics • Dancing model • User interface • Custom dialog box • Control through game pad • Two-player mode • Additional difficulty levels • Device driver for button detection • Support other audio formats • Allow users to edit dance patterns
Final Thoughts • Utilized techniques learned in programming courses • Gained experience programming in Windows environment as well as DirectX programming