FMOD
 

三、音乐播放

A、FMUSIC_PlaySong

 例子:FMUSIC_MODULE *mod = 0;//初始化

     。。。

mod = FMUSIC_LoadSong("canyon.mid");//加载音乐

     。。。

 FMUSIC_PlaySong(mod);   //播放

以下是此函数详细资料

/////////////////

FMUSIC_PlaySong

Starts a song playing.

signed char F_API FMUSIC_PlaySong(
FMUSIC_MODULE *mod
);

Parameters

modPointer to the song to be played.
//要播放歌曲指针

Return Value

TRUE song succeeded playing
FALSE song failed playing

/////////////////////////////

B、FSOUND_PlaySound

例子:FSOUND_SAMPLE * notre_son;//初始化

    。。。。

   notre_son = FSOUND_Sample_Load(FSOUND_FREE, "sound\\bgsound.mp3", FSOUND_NORMAL, 0, 0);//加载

   。。。。

  FSOUND_PlaySound(0, notre_son);//播放

以下是关于此函数的详细说明

///////////////////////////////////

FSOUND_PlaySound

Plays a sample in a specified channel, using the sample's default frequency, volume
and pan settings.
//用一个指定通道来播放例子,使用默认的频率,音量,pan设置

int F_API FSOUND_PlaySound(
int channel,
FSOUND_SAMPLE *sptr
);

Parameters

channel

0+
The absolute channel number in the channel pool.

//通道pool里的绝对通道号。
Remember software channels come first, followed by hardware channels.

//记住软通道使用在前,再接才是硬通道
You cannot play a software sample on a hardware channel and vice versa.

//你不可以用一个硬通道来播放一个软例子,反过来也一样。
FSOUND_FREE
Chooses a free channel to play in.

//选择一个空闲通道来播放

If all channels are used then it
selects a channel with a sample playing that has an EQUAL or LOWER priority
than the sample to be played.

//如果所有通道都被使用,则会选择一个有EQUAL(平等) 或 LOWER(更低)优先权的通道来播放。
FSOUND_ALL
Passing this will cause ALL channels to play. (note this will make things
VERY noisy!)

//使用它会导致所以通道播放。(这样会很噪音)
If FSOUND_ALL is used the last channel success flag will be returned.
//如果使用的是FSOUND_ALL ,返回的会是最后一个通道的成功标志。

sptrPointer to the sample to be played.
//要播放例子的指针

Return Value

On success, the channel handle that was selected is returned.
On failure, -1 is returned.

Remarks

If you play a FSOUND_HW3D declared sample with this function, then the position and velocity
are set to those of the listener.

//如果用这个函数播放一个FSOUND_HW3D声明例子,位置和速度被设置给倾听者

Other attributes such as volume, frequency and pan are taken
from the sample's default volume, frequency, pan etc.

//其他属性如音量,频率和pan从默认中获取。
----------
The channel handle :
The return value is reference counted. This stops the user from updating a stolen channel.
Basically it means the only sound you can change the attributes (ie volume/pan/frequency/3d position) for are the one you specifically called playsound for. If another sound steals that channel, and you keep trying to change its attributes (ie volume/pan/frequency/3d position), it will do nothing.
This is great if you have sounds being updated from tasks and you just forget about it.
You can keep updating the sound attributes and if another task steals that channel, your original task wont change the attributes of the new sound!!!
The lower 12 bits contain the channel number. (yes this means a 4096 channel limit for FMOD :)
The upper 19 bits contain the reference count.
The top 1 bit is the sign bit.
ie
S RRRRRRRRRRRRRRRRRRR CCCCCCCCCCCC
----------
Remember if not using FSOUND_FREE, then the channel pool is split up into software and hardware channels.

//记住如果没有正在使用FSOUND_FREE,之后通道pool会被分为软件和硬件通道。
Software channels occupy the first n indicies specified by the value passed into FSOUND_Init.
Hardware channels occupy the next n indicies after this, and can be a variable amount, depending on the hardware.

//软通道占据用FSOUND_Init指定的N个 indicies 。硬通道分到之后N个 indicies ,可以有个有效量,取决于硬件
Use FSOUND_GetNumHardwareChannels to query how many channels are available in hardware.

//可以使用FSOUND_GetNumHardwareChannels 去质问有多少通道在硬件中有效。

//////////////////////////////////////

另:FSOUND_PlaySoundEx

例如:

channel = FSOUND_PlaySoundEx(FSOUND_FREE, samp2, NULL, TRUE);

以下是此函数的详细资料

//////////////////////////////

FSOUND_PlaySoundEx

Extended featured version of FSOUND_PlaySound.

//FSOUND_PlaySound的扩展版本
New functionality includes the ability to start the sound paused.

//新函数包含开始声音暂停的功能。
This allows attributes of a channel to be set freely before the sound actually starts playing, until FSOUND_SetPaused(FALSE) is used.

//这个通道允许属性在声音真正播放前被设为自由。直到使用FSOUND_SetPaused(FALSE)。
Also added is the ability to associate the channel to a specified DSP unit.

//同样增加了分配通道到一个指定DSP单元的功能。

This allows the user to 'group' channels into seperate DSP units, which allows effects to be inserted between these 'groups', and allow various things like having one group affected by reverb (wet mix) and another group of channels unaffected (dry).

//允许用户把 'group' 通道分到可以把效果插入这些'group' 中的DSP单元中,允许像有一组湿声和另一组干声明通道的各种方式。

This is useful to seperate things like music from being affected by DSP effects, while other sound effects are.
//通常把如音乐的东西从DSP效果分离。

int F_API FSOUND_PlaySoundEx(
int channel,
FSOUND_SAMPLE *sptr,
FSOUND_DSPUNIT *dspunit,
signed char startpaused
);

Parameters

channel0+
The absolute channel number in the channel pool.
Remember software channels come first, followed by hardware channels.
You cannot play a software sample on a hardware channel and vice versa.
FSOUND_FREE
Chooses a free channel to play in. If all channels are used then it
selects a channel with a sample playing that has an EQUAL or LOWER priority
than the sample to be played.
FSOUND_ALL
Plays the sound on all channels.
//同上
sptrPointer to the sample to be played.
//同上
dspunitOptional. NULL by default. Pointer to a dsp unit to attach the channel to for channel grouping. Only attach a sound to a user created DSP unit, and not a system DSP unit.
//可选。默认为空。把一个dsp单元附加在通道上的指针。只有把声音附加在一个用户自建DSP单元,不是一个系统DSP单元。
pausedStart the sound paused or not. Pausing the sound allows attributes to be set before the sound starts.
//是否开始声音暂停。在声音开始之前可以设置是否允许暂停。

Return Value

On success, the channel handle that was selected is returned.
On failure, -1 is returned.

Remarks

FSOUND_ALL is supported. Passing this will cause ALL channels to play. (note this could make things VERY noisy!)//同上
If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.//如果是使用FSOUND_ALL ,返回的是最后通道值。返回值在大多情况下都没有用。
----------
The channel handle :
The return value is reference counted. This stops the user from updating a stolen channel.
This means the only sound you can change the attributes (ie volume/pan/frequency/3d position) for are the
one you specifically called playsound for. If another sound steals that channel, and you keep trying to
change its attributes (ie volume/pan/frequency/3d position), it will do nothing.
This is great if you have sounds being updated from tasks and you just forget about it.
You can keep updating the sound attributes and if another task steals that channel, your original task
wont change the attributes of the new sound!!!
The lower 12 bits contain the channel number. (yes this means a 4096 channel limit for FMOD :)
The upper 19 bits contain the reference count.
The top 1 bit is the sign bit.
ie
S RRRRRRRRRRRRRRRRRRR CCCCCCCCCCCC
----------
Remember if not using FSOUND_FREE, then the channel pool is split up into software and hardware channels.
Software channels occupy the first n indicies specified by the value passed into FSOUND_Init.
Hardware channels occupy the next n indicies after this, and can be a variable amount, depending on the hardware.
Use FSOUND_GetNumHardwareChannels to query how many channels are available in hardware.

//同上
----------
If you attach a sound to a DSP unit (for grouping purposes), the callback for the DSP unit will be overwritten with fmod's internal mixer callback, so the callback the user supplied is rendered obsolete and is not called.
Also, do not attach sounds to system DSP units, the assignment will be ignored if you do.

//如果你把一个声音附加在一个DSP单元上,DSP单元的回调将会被fmod的内在混合回调覆盖,所以用户提供的回调会作废和不被调用,同时,不把声音附加在系统DSP单元,这个任务将会忽略。

////////////////////////////////////

C、FSOUND_Stream_Play

例子:FSOUND_Stream_Play(FSOUND_FREE, stream)

以下是此函数的详细说明

//////////////////////////////

FSOUND_Stream_Play

Starts a pre-opened stream playing.

int F_API FSOUND_Stream_Play(
int channel,
FSOUND_STREAM *stream
);

Parameters

channel0+ The channel index in the channel pool. This must not exceed the maximum number of channels allocated with FSOUND_Init
FSOUND_FREE
Chooses a free channel to play in. If all channels are used then it
selects a channel with a sample playing that has a lower priority than the
sample to be played.
//同上
streamPointer to the already opened stream to be played.
//要播放的已经打开的指针

Return Value

On success, the channel handle the stream is playing in is returned.
On failure, -1 is returned.

Remarks

When a stream starts to play, it inherits a special high priority (256).

//当一个stream开始播放时,它继承一个特别高的优先权(256)。
It cannot be rejected by other sound effect channels in the normal fashion as the user can never set a priority above 255 normally.

//当用户没有设置一个低于256的正常优先权时,它不能被其他声效通道以正常方式拒绝。
--------------
If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready.
--------------
FSB streaming is not supported if the format from FSBank is 'Retain original format'. On PC platforms, only PCM and ADPCM FSB files are allowed.

//同前
--------------
FSOUND_STEREOPAN is recommended for stereo streams if you call FSOUND_SetPan. This puts the left and right channel to full volume.

//如果你调用FSOUND_SetPan,FSOUND_STEREOPAN会被推荐给立体声。他可以把左右声道都调为最大音量。
Otherwise a normal pan will give half volume for left and right. See FSOUND_SetPan for more information on this.

//相反一个正常pan会带一半音量给左和右。查看FSOUND_SetPan 去了解更多信息。
--------------
You can use normal channel based commands (such as FSOUND_SetVolume etc) on the return handle, as it is a channel handle.

//你可以用正常通道的基本命令到返回句柄上,当它是一个通道句柄时

另:FSOUND_Stream_PlayEx

例如:  channel = FSOUND_Stream_PlayEx(FSOUND_FREE, stream, NULL, TRUE);

以下是此函数的详细说明

///////////////////////

FSOUND_Stream_PlayEx

Extended featured version of FSOUND_Stream_Play.
Added functionality includes the ability to start the stream paused. This allows attributes
of a stream channel to be set freely before the stream actually starts playing, until FSOUND_SetPaused(FALSE) is used.
Also added is the ability to associate the stream channel to a specified DSP unit. This allows
the user to 'group' channels into seperate DSP units, which allows effects to be inserted
between these 'groups', and allow various things like having one group affected by reverb (wet mix) and another group of
channels unaffected (dry). This is useful to seperate things like music from being affected
by DSP effects, while other sound effects are.
//同上

int F_API FSOUND_Stream_PlayEx(
int channel,
FSOUND_STREAM *stream,
FSOUND_DSPUNIT *dspunit,
signed char paused
);

Parameters

channel0+
The absolute channel number in the channel pool.
Remember software channels come first, followed by hardware channels.
You cannot play a software sample on a hardware channel and vice versa.
FSOUND_FREE
Chooses a free channel to play in. If all channels are used then it
selects a channel with a sample playing that has an EQUAL or LOWER priority
than the sample to be played.
//同上
streamPointer to the already opened stream to be played.
//同上
dspunitPointer to a dsp unit to attach the channel to.
//同上
pausedStart the stream paused or not. Pausing the stream channel allows attributes to be set before it is unpaused.
//同上

Return Value

On success, a channel handle the stream is playing in is returned.
On failure, -1 is returned.

Remarks

When a stream starts to play, it inherits a special high priority (256).

//同上
It cannot be rejected by other sound effect channels in the normal fashion as the user can never set a priority above 255 normally.

//同上
--------
FSOUND_STEREOPAN is recommended for stereo streams if you call FSOUND_SetPan. This puts the left and right channel to full volume.
Otherwise a normal pan will give half volume for left and right. See FSOUND_SetPan for more information on this.

//同上
--------
You can use normal channel based commands (such as FSOUND_SetVolume etc) on the return handle, as it is a channel handle.

//同上