Download: https://github.com/downloads/bcserv/...lib_v1.0.1.zip
Sourcecode on Github: https://github.com/bcserv/soundlib -
Forks & Pull requests are welcome
Licenses: GPL, LGPL, MPL
Because the source engines internal functionality to calculate the length of a sound file fails, I decided to write my own extension, that handles the calculation. I've spent allot of time into this.
I came out with an extension which is able to read various kind of information out of mp3 files or files in general that have the id3 tag besides of the sound length.
Note: it probably can't read VBR encoded mp3's accurate in some cases.
If the library doesn't load on Windows install this:
Microsoft Visual C++ 2010 SP1 Redistributable Package (x86)
Microsoft Visual C++ 2010 SP1 Redistributable Package (x64)
If it says "libz.so.1: cannot open shared object file: No such file or directory" read this post:
https://forums.alliedmods.net/showpo...3&postcount=52
Here is a list of things it can read:
- sound length
- bit rate
- sampling rate
- Artist (Id3)
- Title (Id3)
- Sound Num (Id3)
- Year (Id3)
- Album (Id3)
- Commend (Id3)
- Genre (Id3)
I think this is very useful for plugins like saysounds
Enjoy
Example code
PHP Code:
new Handle:soundfile = OpenSoundFile("funnysounds/myfunnysound.mp3");
if (soundfile == INVALID_HANDLE) {
PrintToServer("Invalid handle !");
return Plugin_Handled;
}
PrintToServer("Sound Length: %f seconds", GetSoundLengthFloat(soundfile));
CloseHandle(soundFile);
Function List:
PHP Code:
/**
* Opens a sound file.
*
* @note Sound files are closed with CloseHandle().
*
* @param file File to open
* @param relativeToSound if true, it is relative to the sound directory, otherwise you have to build the path yourself
* @return A Handle to the sound file, INVALID_HANDLE on open error.
*/
native Handle:OpenSoundFile(const String:file[], bool:relativeToSound=true);
/**
* Gets the length of the sound file in seconds
*
* @param hndl Handle to the sound file.
* @return The song length in seconds
*/
native GetSoundLength(Handle:hndl);
/**
* Gets the length of the sound file in seconds as float.
* Note: this probably won't work with some VBR encoded mp3's
*
* @param hndl Handle to the sound file.
* @return The song length in seconds as float
*/
native Float:GetSoundLengthFloat(Handle:hndl);
/**
* Get the Bit rate of sound (kbps)
*
* @param hndl Handle to the sound file
* @return sound bitrate (cell)
*/
native GetSoundBitRate(Handle:hndl);
/**
* Get the Sampling rate of sound (hz)
*
* @param hndl Handle to the sound file
* @return sampling rate (cell)
*/
native GetSoundSamplingRate(Handle:hndl);
/**
* Get the Artist of the sound
*
* @param hndl Handle to the sound file
* @param buffer Buffer to use for storing the string.
* @param maxlength Maximum length of the buffer.
* @return Length of string written to buffer.
*/
native GetSoundArtist(Handle:hndl, String:buffer[], maxlength);
/**
* Get the Track title of sound
*
* @param hndl Handle to the sound file
* @param buffer Buffer to use for storing the string.
* @param maxlength Maximum length of the buffer.
* @return Length of string written to buffer.
*/
native GetSoundTitle(Handle:hndl, String:buffer[], maxlength);
/**
* Get the Track number of the sound
*
* @param hndl Handle to the sound file
* @return sound number (cell)
*/
native GetSoundNum(Handle:hndl);
/**
* Get the Album of the sound
*
* @param hndl Handle to the sound file
* @param buffer Buffer to use for storing the string.
* @param maxlength Maximum length of the buffer.
* @return Length of string written to buffer.
*/
native GetSoundAlbum(Handle:hndl, String:buffer[], maxlength);
/**
* Get the Year of sound
*
* @param hndl Handle to the sound file
* @return sound year (cell)
*/
native GetSoundYear(Handle:hndl);
/**
* Get the Comment of the sound
*
* @param hndl Handle to the sound file
* @param buffer Buffer to use for storing the string.
* @param maxlength Maximum length of the buffer.
* @return Length of string written to buffer.
*/
native GetSoundComment(Handle:hndl, String:buffer[], maxlength);
/**
* Get the Genre of the sound
*
* @param hndl Handle to the sound file
* @param buffer Buffer to use for storing the string.
* @param maxlength Maximum length of the buffer.
* @return Length of string written to buffer.
*/
native GetSoundGenre(Handle:hndl, String:buffer[], maxlength);
This extension makes use of the
Taglib library, I compiled static libraries for windows & linux.
The
Taglib is under the
GNU Lesser General Public License (LGPL) and the
Mozilla Public License (MPL).