200742111447069

所属分类:多媒体编程
开发工具:Visual Basic
文件大小:100KB
下载次数:25
上传日期:2008-05-25 14:08:06
上 传 者xiongjohn
说明:  在VB中同时播放多个音频文件本来就是一个难点。很多游戏采用PlaySound函数,但这个函数只支持同时播放一个音频,还有些游戏干脆采用 Direct X来迂回解决这个问题。其实这个问题可以通过一般的API来解决,这个实例就演示了如何同时播放10个以上的音频并不占用CPU。
(At the same time, in the VB player was originally a number of audio files is a hard nut to crack. A lot of games using PlaySound function, but this function only supports an audio player at the same time, some games simply bypass the use of Direct X to solve this problem. In fact, this issue can be resolved through the general API to solve this example demonstrates how to play more than 10 audio does not occupy CPU.)

文件列表:
200742111447069\Sounds\Bulgarian.wav (22218, 2006-10-22)
200742111447069\Sounds\Czech.wav (8540, 2006-10-22)
200742111447069\Sounds\Danish.wav (7178, 2006-10-22)
200742111447069\Sounds\Hebrew.wav (9496, 2006-10-22)
200742111447069\Sounds\Icelandic.wav (10650, 2006-10-22)
200742111447069\Sounds\Irish.wav (10018, 2006-10-22)
200742111447069\Sounds\Norwegian.wav (8788, 2006-10-22)
200742111447069\Sounds\Polish.wav (8780, 2006-10-22)
200742111447069\Sounds\Russian.wav (9966, 2006-10-22)
200742111447069\Sounds\Swedish.wav (8990, 2006-10-22)
200742111447069\Sounds\Tepissd3.wav (31118, 1999-09-01)
200742111447069\Sounds\Ukrainian.wav (18750, 2006-10-22)
200742111447069\Sounds\『源码天空』.url (164, 2005-02-08)
200742111447069\Sounds\免费『商业源码』.url (164, 2005-02-08)
200742111447069\Sounds\使用说明.txt (1619, 2006-07-30)
200742111447069\Sounds (0, 2006-10-23)
200742111447069\DemoWindow.frm (47959, 2006-10-22)
200742111447069\GrigriSoundManager.vbp (833, 2006-10-22)
200742111447069\SoundManager.bas (21205, 2006-10-22)
200742111447069\SoundManagerNotifier.cls (685, 2006-10-22)
200742111447069\『源码天空』.url (164, 2005-02-08)
200742111447069\免费『商业源码』.url (164, 2005-02-08)
200742111447069\使用说明.txt (1619, 2006-07-30)
200742111447069 (0, 2007-05-10)

Grigri's Sound Manager for VB6 ============================== Written by : grigri Version : 1.0 [22/10/2006] Intro ----- Playing multiple sounds simultaneously is not an easy task, especially in VB. Most VB applications (and games!) that use sound use the PlaySound() API function [which only allows one sound at a time]; others resort to DirectX or third-party DLLs such as BASS. This project is a first step to ending all that, presenting an API-only method. The multimedia API set is nasty, really nasty. Even in C it's not easy to manage, and in VB it just gets worse. I have waded through most of the ambiguous 'documentation' and the pathetic 'code examples' and I believe I've made a good start. How It Works ------------ The system is deployed as one module and a notification interface. An internal array of sound buffers (limited to 32 but easily changed) is managed by the system. All external calls reference the buffer index. Confused? Here's a really quick-and-dirty example of how to use it. ' Load, play and free a sound in one line of code LoadSoundFile FreeBuffer, "c:\some\sound\file.wav", BufferFlagInstant Important Point: At the end of the application, you **MUST** call `SoundManager.DestroySoundManager()`. If you don't, you'll end up crashing your application or VB, depending on whether you're in the IDE or not. The notification interface allows you to be notified when a sound is loaded, freed, playing or stopped. The demo application shows the proper usage. SoundManager API ---------------- * `DestroySoundManager()` Parameters : None Return Type : None (`Sub`) Frees all loaded sounds and destroys internal structures. This *MUST* be called when you're done. I can't stress this enough. * `FreeBuffer()` Parameters : None Return Type : `Long` Returns the first free buffer index. Analogous to the VB `FreeFile()` function * `SoundStatus()` Parameters : - `BufferIndex` (IN) [`Long`] Return Type : `SoundBufferStatus` (Enumeration) Returns the status of the buffer `BufferIndex` * `LoadSoundFile()` Parameters : - `BufferIndex` (IN) [`Long`] - `FileName` (IN) [`String`] - `Flags` (IN,OPTIONAL) [`SoundBufferFlags` (Enumeration)] Return Type : `Boolean` Loads the specified wave file into the specified buffer. The optional flags can be used to make the buffer play/free itself automatically, and/or to not generate notifications of status change. If the specified buffer is not empty, it will be stopped/freed as required. * `FreeSound()` Parameters : - `BufferIndex` (IN) [`Long`] Return Type : None (`Sub`) Frees the specified buffer. If it is currently playing, it will be stopped. * `StopSound()` Parameters : - `BufferIndex` (IN) [`Long`] Return Type : None (`Sub`) Stops playback on the specified buffer. If not playing, nothing happens. * `PlaySound()` Parameters : - `BufferIndex` (IN) [`Long`] Return Type : `Boolean` Begins playback of the specified buffer. If it is currently playing, it will be stopped first, resulting in a "restart" -- playing the buffer from the beginning. Notification Interface Callback Methods --------------------------------------- All callback methods have identical prototypes, passing the buffer index as the sole parameter, and not returning any value. Each method corresponds to a status change of the specified buffer, and is called *after* the status has been updated. The names are self-explanatory. * `SoundLoaded()` : Status is `BufferLoaded` * `SoundUnloaded()` : Status is `BufferEmpty` * `SoundPlayStart()` : Status is `BufferPlaying` * `SoundPlayEnd()` : Status is `BufferLoaded` Error Handling -------------- Most functions will simply fail silently in case of an error, returning a `False` value, if appropriate. The current exception is the `LoadSoundFile()` function, which uses `MsgBox()` to display errors. Better error handling is being planned for the next version. Honestly. Limitations ----------- * This version only supports uncompressed .WAV files. No .mp3, .au, .voc, .ogg or .aac. * Every sound to be played is loaded in memory entirely before playback begins. This means that large sound files are not catered for by this method. Streaming sounds IS possible with the API, using a free-threaded rotating buffer chain, which seems to be impossible (or at least EXTREMELY difficult) in VB. * Although it seems stable now, it was quite unstable during development and I had more than a few crashes. Each crash took VB down with it. So be warned! Use at your own risk. Future Enhancements Planned (short-term) --------------------------- * Better error handling * Pause/Resume playback * Looping * Loading sounds from resources and memory * Volume and pitch control Future Enhancements Hoped For (long-term) ----------------------------- * Streaming playback * Support for different sound formats

近期下载者

相关文件


收藏者