Skip to main content
gamedev.net
🔒 Locked

Basic Music In C

Started by STVOY Sep 15, 2000 at 2:30 PM 5 replies 450+ views
A. Buza
A. Buza
Well, I believe you'll either have to use DirectSound (or some other library), or program the soundcard registers directly through DOS interrupts or something.

Its not known to be a very simple thing to do.. why do you think most games used 3rd party libraries in the DOS days? And if you count DirectSound/Music, they still use 3rd party stuff.

...I could be wrong though.

Edited by - A. Buza on September 15, 2000 8:14:20 PM
Martee
Martee
Well, you could always check out the Allegro source code...

Martee
Magnum Games
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Quantum
Quantum
look up PlaySound to play a wav file in a win32 program (pretty sure it works in console apps)
Staffan
Staffan
Hey, does anyone know how to get the good ol'' mighty pc speaker playing from C? God, I miss those times...

"Paranoia is the belief in a hidden order behind the visible." - Anonymous
felisandria
felisandria
Here is what you need to do simple, standard MCI midi playing in windows, as cut/pasted out of my code.


void CGameBoard:layMusic()
{
UINT deviceID;
DWORD dwReturn;
MCI_OPEN_PARMS openParms;
MCI_PLAY_PARMS playParms;
char buff[100];

openParms.lpstrDeviceType = "sequencer";
openParms.lpstrElementName = "pegmusic.mid";
if (dwReturn = mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE|MCI_OPEN_ELEMENT|MCI_WAIT,
(DWORD)(LPVOID)&openParms))
{
mciGetErrorString(dwReturn, buff, sizeof(buff));
MessageBox(buff, "ERROR", MB_OK|MB_ICONEXCLAMATION);
return;
}
deviceID = openParms.wDeviceID;
playParms.dwCallback = (DWORD)m_hWnd;
if (dwReturn = mciSendCommand(deviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)(LPVOID)&playParms))
return;
m_deviceID = deviceID;
m_playParms = playParms;
}

LONG CGameBoard::OnMciNotify(UINT wFlags, LONG lDevId)
{
MCI_PLAY_PARMS playParms;
playParms.dwFrom = 0;
switch(wFlags) {
case MCI_NOTIFY_SUCCESSFUL:
playParms.dwCallback = (DWORD)m_hWnd;
mciSendCommand(lDevId, MCI_PLAY, MCI_NOTIFY|MCI_FROM, (DWORD)(LPVOID)&playParms);
break;
case MCI_NOTIFY_FAILURE:
// m_wndStatus.SetWindowText(_T("Playback interrupted!"));
break;
case MCI_NOTIFY_SUPERSEDED:
// m_wndStatus.SetWindowText(_T("Playback stopped!"));
break;
}
return 0L;
}

void CGameBoard::SetMusicOff(BOOL off)
{
if (m_bMusicFlag)
{
if (off)
mciSendCommand(MCI_ALL_DEVICE_ID, MCI_CLOSE, NULL, NULL);
}
else
{
if (!off)
PlayMusic();
}

m_bMusicFlag = !off;
}


Note that this means you have to process the
MM_MCINOTIFY
in your message handlers, so that the song will restart when it finishes.

Tell me if you have problems.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.