Raised This Month: $51 Target: $400
 12% 

[EXTENSION] Sound Info Library v1.0.1


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 10-08-2009 , 16:58   [EXTENSION] Sound Info Library v1.0.1
Reply With Quote #1



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:hndlString: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:hndlString: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:hndlString: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:hndlString: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:hndlString: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).
Attached Files
File Type: zip soundlib_v1.0.1.zip (306.9 KB, 10524 views)
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 10-26-2014 at 18:02.
berni is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode