Copyright © 2001-2019 MultiMedia Soft

How to detect silent portions of sound files

Previous pageReturn to chapter overviewNext page

Active DJ Studio allows detecting silent portions of sound files in different ways:

 

automatic silence detection when a sound is loaded inside a player
manual silence detection before starting playback of a sound loaded inside a player
manual silence detection directly on a sound file stored on disk
realtime silence detection during playback

 

Let's see how the various ways differ from each other:

 

 

Automatic silence detection when a sound is loaded inside a player

 

In this case silent portions of a sound file, usually found at the beginning and at the end of the audio stream, are automatically detected each time a song is loaded inside a player through one of the many methods beginning with the "Load" prefix like LoadSound or LoadSoundFromMemory (with the exception of the LoadInternetStream method).

 

By default this feature is disabled but can be enabled through the SilenceDetectionOnPlayerLoadAutoSet method: this setting becomes effective as soon as a new sound is loaded into the given player. Silence detection is performed inside a secondary thread so silence positions are not immediately available after loading the sound: when silence positions become available the container application is notified through the SilencePositionAvailable event.

 

 

Manual silence detection before starting playback of a sound loaded inside a player

 

As seen on the point above, by default silence detection is disabled when loading a new sound inside a player: in this situation you can obtain silent portions at the beginning and at the end of the loaded sound in two ways:

 

through the SilenceDetectionOnPlayer method: in this case silence detection is performed inside the main thread of the container application so, when the method returns control to the caller, silence positions are immediately available.
through the SilenceDetectionOnPlayerRequest method: in this case silence detection is performed inside a secondary thread so, when the method returns control to the caller, silence positions are not immediately available; when silence positions are calculated the container application is notified through the SilencePositionAvailable event.

 

 

Manual silence detection directly on a sound file stored on disk

 

If you don't need to start a playback session with a specific audio file you can in any case detect the initial and final silent portions through the SilenceDetectionOnFile method: as seen for the SilenceDetectionOnPlayer method, also in this case silence detection is performed inside the main thread of the container application so, when the method returns control to the caller, silence positions are immediately available.

 

 

Realtime silence detection during playback

 

During a playback session there may be the need to detect when the sound level stays under a certain threshold for a given amount of time: this task can be performed by enabling the realtime silence detection system through the SilenceDetectionRealTimeEnable method. Parameters related to the silence detection processing, like the sound level threshold and the minimal duration of the silent portion, can be set through the SilenceDetectionRealTimeParamsSet method which should be invoked before enabling silence detection.

 

Differently from other ways described on points above, which can only detect the initial and final portions of silence on audio files whose duration is known, when realtime silence detection is enabled you can detect silent portions of songs which may be located within other audible data and, more interesting, realtime silence detection could be enabled on Internet streams loaded through the LoadInternetStream method or on audio queues created using the StreamQueueCreate method.

 

Each time a silent portion of song is detected, the container application is notified through the SilenceDetectionStateChange event: obviously the same event is fired again when the silent portions ends and new audible samples are met.

 

In order to improve the granularity of realtime silence detection is recommended setting a small update time for the playback buffer by setting the BufferUpdateTime property to a value around 10 milliseconds.