Game music and sound playback

zhaozj2021-02-08  252

In the Win32 environment, there is too much way to play music sounds, and there is a common point that you don't need to spend a lot of heart, you can get what you need. The continuation of the subject, this issue we focus on music and sound performance.

□ game music

I believe that many people must agree with the status of music in the game, recalling the domestic RPG classic "剑 奇 奇", peel off the level of music, the whole game will be inferior, especially appropriate scenes with appropriate Music, make players integrate into the plot. When I cried, I laughed when I laughed, and I was about to be collected. The rest of the RPG is not particularly highlighted, and the sound of the sword when she knows the hacking. Therefore, it is usually not very payable in the performance of the sound. The real-time battle game focuses on the sound performance of the killing, a large man, a mixed voice, which involves the mixed part, and we will also explore it under our bottom. After reading this article, you will learn when to use what kind of procedure to express another life of the game: music and sound.

□ Starting from MIDI

The music part under the early DOS, most of which uses the sonic card specifications, and the silent name is this format. Of course, the game usually does not let you see the real practice, but internal use this format is much. No doubtful. The game under WINDOW is much more, in order to fully reach the space utilization phase, the game will use a lot of WAV format files, or directly burn the music into the format of the track. Especially a lot of games like to adopt the first piece of information, the second piece of music, usually do not play the game can also be used as a music CD to listen, is a full texture. Of course, I mean that these music must be in the ear, if the music itself is born, even if it is burned into a track, it is a messy, can't change this fact.

Under WINDOW, the size of the space is absolutely the best choice, and a five-minute MIDI doesn't have a size of 100,000 characters. This is a one-minute occupancy amount of WAV format with MB. It is simply The little witch saw the big witch, so the music on the website, the music of the game is very suitable for using MIDI, and the music part I personally pay attention to the melody, as for the number of musical instruments used by music itself, I will pay less attention, people The ears have a certain limit, as long as no noise is produced, with a beautiful melody, can be accepted.

□ Play MIDI program

The point of playing music in the game is to loop play, that is, after playing, let him start playing from the head until the scene is replaced, or the game is over. Therefore, when the MIDI file is played, it must be notified to make an appropriate processing. When playing MIDI, as long as the support of the multimedia of Window, you will get it immediately, and even directly from the Help's procedure, it can be met, it can also meet the needs, because this thing is quite formulating, A Jun and B Jun wrote The program code is also roughly long, and there is not much nonsense. It is simple to see how the program is:

Class Cmidi

{

PUBLIC:

DWORD Play (hwnd, char * filename);

Void replay ();

Void Stop ();

Private:

Uint WDEVICEID; // MCI device code

DWORD dwreturn;

MCI_open_parms mciopenparms;

MCI_Play_Parms McIPlayParms;

MCI_STATUS_PARMS MCISTATUSPARMS;

MCI_SEQ_SET_PARMS MCISEQSETPARMS;

}

It is also possible to use him into a category. And the part of the interface needs to be simplified. From intone, the first action is playback (Play), then a replay, of course, is of course a good job ( STOP), not many, just three, of course, you will think of it, is there a pause interface, no problem, this is not a difficult thing, the extra three minutes should be a pleasant.

After understanding the category, let's take a look at how the actual part is, starting with cmidi :: play ():

DWORD CMIDI :: Play (hwnd hwnd, char * midifile)

{

/ / Turn on the hardware device of MIDI, we use a general internal value

MciopenParms.lpstrDeviceType = "Sequenceer";

/ / This number is the name of the MIDI file to play

Mciopenparms.lpstreamentname = midifile;

// Way to play MIDI instead of String by using Message

IF (dwreturn = MCISENDCOMMAND (NULL, MCI_Open,

MCI_open_type | mci_open_element,

(DWORD) & mciopenparms)

Return (dwreturn);

// The Device Opened SuccessFully; Get The Device ID.

WDEVICEID = mciopenparms.wdeviceId;

// Check if the output port is the miDi mapper.

MCISTATUSPARMS.DWITEM = MCI_SEQ_STATUS_PORT;

IF (dwreturn = mciSendcommand (WDEVICEID, MCI_STATUS,

MCI_STATUS_ITEM, (DWORD) & MCISTATUSPARMS)))

{

MCISENDCOMMAND (WDEVICEID, MCI_Close, 0, NULL);

Return (dwreturn);

}

/ / In order to achieve the purpose of repeated playback, we must allow our programs to receive

// mm_mcinotify's message, the way this letter call is passed

/ / WM_PLAY message to the device, told him to start playing.

McIPlayParms.dwcallback = (dword) hwnd;

IF (dwreturn = MCISENDCOMMAND (WDEviceID, MCI_Play, MCI_notify,

(DWORD) & mcIPlayParms)))))))

{

MCISENDCOMMAND (WDEVICEID, MCI_Close, 0, NULL);

Return (dwreturn);

}

Return (0L);

}

There are two ways to play MIDI, the first is to use the string command hardware action, the second is to pass the message, we use the second, the reason is very clear, must be passed through the message, we can get Choze whether the music is played.

Next, let's take a look at cmidi :: relay?

Void cmidi :: relaplay ()

{

McISendCommand (WDEVICEID, MCI_Seek, MCI_seek_to_start, null); McISendCommand (WDEVICEID, MCI_Play, MCI_notify, (lpvoid) & mcIPLAYPARMS);

}

It's really simple, I only contains two calls in the letter, and the first call is sent to the device, and told him to move the MIDI's play indicator to the most open part, that is, MCI_Seek_To_Start,

The practice is just like a mobile archive indicator. Then, the second instruction light also understands that it is called him to continue to play, and don't forget MCI_Notify. When you play, you still have to inform us.

Last look at cmidi :: stop () method:

Void cmidi :: stop ()

{

MCISENDCOMMAND (WDEVICEID, MCI_Close, 0, NULL);

}

More and more pure, there is only a letter call, where the message is MCI_Close, which ends the entire music. When you end the play, you will play another music, it is very simple, call CMIDI :: play () again.

The use of the entire category is roughly like this: first configure an actual CMIDI object to be sent, as long as the cmIDI MIDI in the whole country; that is, the MIDI is the real object. Site call midi.play (hwnd, "ff3celes.mid") at the beginning of the scene; enter the correct MIDI file name. Here I played the three generations of the Space Warrior, just demonstration, of course, this music is really great. And inside the message ring, we must define a message:

Case MM_MCINOTIFY:

Midi.replay ();

Break;

After the music is played, we will receive this message from MM_MCINOTIFY. At this time, call cmidi :: relay (). When the scene is replaced, it is necessary to re-a new music, or the time of the program, is the time to call CMIDI :: STOP (). Because a scene will only have a music in the same time, our category is good, don't worry.

转载请注明原文地址:https://www.9cbs.com/read-1387.html

New Post(0)