Advertisement

Basic Music In C

Started by September 15, 2000 02:30 PM
5 comments, last by STVOY 24 years, 3 months ago
Well Now, I was wondering if anyone could tell me how to create basic music in C. Nothing fancy just adlib is fine. STVOY Mega Moh Mine!! The Yipsilon Home Page (Under Construction)
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
Advertisement
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
Well Now,

Is there way I can link to a wav or midi file like some simple games seem to do.

STVOY

Mega Moh Mine!!


The Yipsilon Home Page (Under Construction)



look up PlaySound to play a wav file in a win32 program (pretty sure it works in console apps)
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
Advertisement
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. ~

This topic is closed to new replies.

Advertisement