작성자 : Aurélien Da Campo (Adolio)
데모 폴더로 이동하여 프로젝트를 구성하고 실행하거나 최신 릴리스를 받으면 아카이브에서 데모 바이너리를 사용할 수 있어야합니다.
트랙을 등록하고 사운드를 인스턴스화하는 메인 클래스. 다음 예제는 두 개의 트랙 (MP3 & WAV)을 등록하고 트리밍 및 샘플링 옵션을 설정합니다. 그런 다음 세 가지 소리가 인스턴스화됩니다.
// Embedded sounds (Note that WAV files requires a mime type)
[ Embed( source = "../media/sound/engine.mp3" ) ] public static const EngineSoundMp3 : Class ;
[ Embed( source = "../media/sound/engine.wav" , mimeType = "application/octet-stream" ) ] public static const EngineSoundWav : Class ;
private var _soundManager : SoundManager ;
public function SoundManagerExample()
{
// Create Sound Manager
_soundManager = new SoundManager();
_soundManager.maxChannelCapacity = 8; // Limit number of simultaneous playing sounds (for this sound manager only)
_soundManager.isPoolingEnabled = true; // Enable pooling to re-used already instantiated sounds and reduce GC impacts
// Register sounds
var engineSoundMp3Config:TrackConfiguration = _soundManager.registerTrack( "Engine 1" , new Mp3Track(new EngineSoundMp3())); // Register a MP3 track
var engineSoundWavConfig:TrackConfiguration = _soundManager.registerTrack( "Engine 2" , new WavTrack(new EngineSoundWav())); // Register a WAV track
// Trimming configuration
engineSoundMp3Config.findTrim(0.01); // Find start & end trim durations to remove silences inherent to mp3 format (with a silent threshold of 0.01)
// Sampling rate configuration
engineSoundWavConfig.sampling = 4096; // This defines how much samples are read per sampling request. The value must be between 2048 (included) and 8192 (included).
// Base volume configuration for mastering
engineSoundMp3Config.baseVolume = 0.5; // Custom mastering at track configuration level, the sound can now be player at 1.0 but will still be influenced by this mastering.
// Play sounds
var engine1_once:SoundInstance = _soundManager.play( "Engine 1" , 1.0); // Play once
var engine1_twice:SoundInstance = _soundManager.play( "Engine 1" , 1.0, 0, 1); // Play twice (repeat once)
var engine2_infinite:SoundInstance = _soundManager.play( "Engine 2" , 1.0, 0, -1); // Play infinite
// Control master volume
_soundManager.volume = 0.8;
}제어 할 수있는 사운드의 인스턴스. 다음 예는 사운드 이벤트를 듣는 방법, 사운드 제어 방법 및 다양한 정보를 얻는 방법을 보여줍니다.
var si : SoundInstance = _soundManager . play ( "Engine 1" , 1.0 , 1337 , 5 ) ; // Play at max volume, starting at 1,337 sec., 6 times (looping 5 times)
//-----------------------------------------------------------------------------
//-- Events
//-----------------------------------------------------------------------------
si . started . add ( function (si : SoundInstance) : void { trace( "Sound started. " + si.type); } ) ;
si . stopped . add ( function (si : SoundInstance) : void { trace( "Sound stopped. " + si.type); } ) ;
si . paused . add ( function (si : SoundInstance) : void { trace( "Sound paused. " + si.type); } ) ;
si . resumed . add ( function (si : SoundInstance) : void { trace( "Sound resumed. " + si.type); } ) ;
si . completed . add ( function (si : SoundInstance) : void { trace( "Sound completed. " + si.type); } ) ;
si . destroyed . add ( function (si : SoundInstance) : void { trace( "Sound destroyed. " + si.type); } ) ;
//-----------------------------------------------------------------------------
//-- Controls
//-----------------------------------------------------------------------------
// Execution controls
si . pause () ;
si . resume () ;
si . stop () ;
si . play ( 0.5 , 0 , 1.0 ) ; // (Re)play twice (repeat once)
// Position
si . position = 1337 ; // In milliseconds
si . positionRatio = 0.5 ; // This includes the loops so here it will play only the second loop!
// Mute
si . isMuted = true ;
si . isMuted = false ;
// Volume
si . volume = 0 ;
si . volume = 0.8 ;
// Pan
si . pan = - 0.5 ; // Half left
// Pitch
si . pitch = 0.8 ; // 20% slower
si . pitch = 1.2 ; // 20% faster
si . pitch = 1.0 ; // Back to default
//-----------------------------------------------------------------------------
//-- Status info
//-----------------------------------------------------------------------------
trace ( "Type: " + si . type ) ; // Type
trace ( "Volume: " + si . volume ) ; // Volume
trace ( "Mixed volume: " + si . mixedVolume) ; // Equals to _soundManager.volume * volume
trace ( "Pan: " + si . pan ) ; // Pan
trace ( "Pitch: " + si . pitch) ; // Pitch
trace ( "Sound length: " + si . length ) ; // One loop length in milliseconds (trimmed)
trace ( "Sound total length: " + si . totalLength) ; // Total length in milliseconds (including loops & trim durations)
trace ( "Loops: " + si . loops ) ; // Total loops
trace ( "Current loop: " + si . currentLoop) ; // Current loop (-1 = infinite, 0 = first play, 1 = second play, etc.)
trace ( "Remaining loops: " + si . loopsRemaining) ; // Remaining loops
trace ( "Remaining time: " + si . remainingTime) ; // Remaining time in milliseconds
trace ( "Current position: " + si . position ) ; // Current position in milliseconds
trace ( "Current position (ratio): " + si . positionRatio) ; // Current position (ratio, between 0..1)
trace ( "Is started: " + si . isStarted) ; // Is started?
trace ( "Is playing: " + si . isPlaying ) ; // Is playing?
trace ( "Is paused: " + si . isPaused) ; // Is paused?
trace ( "Is muted: " + si . isMuted) ; // Is muted?
trace ( "Is destroyed: " + si . isDestroyed) ; // Is destroyed? 풀링은 이미 인스턴스화 된 Sound Instances 재사용하여 메모리 소비를 크게 줄일 수 있습니다. 이것은 또한 Garbage Collector 통로로 인한 지연을 최소화해야합니다. 따라서이 기능은 응용 프로그램에서 동일한 사운드를 많이 재생할 때 매우 유용 할 수 있습니다 (예 : 플레이어 발자취, 아처 군대가 던진 화살표 등).
풀링 기능은 다음과 같은 방식으로 활성화 될 수 있습니다.
_soundManager . isPoolingEnabled = true ; 중요 : Sound Instance 완료되면 자동으로 풀로 반환됩니다. 완성 된 Sound Instances 에 대한 참조를 유지하지 않도록주의하십시오. 곧 다른 곳에서 재사용 할 수 있기 때문입니다.
무한 루핑 사운드 (예 : 원활한 루핑 사운드)를 다음 방법을 호출하여 수영장으로 수동으로 반환 할 수 있습니다.
_soundManager . releaseSoundInstanceToPool(mySound) ; 중요 : 풀링 기능이 활성화 될 때는 Sound Instances 파괴하지 마십시오. 이것은 물체 재활용 메커니즘을 깨뜨릴 것입니다.
TrackConfiguration.findTrim() 유틸리티 메소드를 사용하여 MP3 및 트리밍 지속 시간을 구성하는 것입니다.classpath 에서 src 폴더를 추가하거나 소스 폴더에 src 폴더의 내용을 붙여 넣습니다.또는
.swc 파일을 사용하십시오.종속성을 포함하는 것을 잊지 마십시오 (아래 참조).
libs 폴더 포함)