Monthly Target: $400 Donations: $242
 60% 

[EXTENSION] Sound Info Library v1.0.1


Post New Thread Reply   
 
Thread Tools Display Modes
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, 4926 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
Chanz
Veteran Member
Join Date: Aug 2008
Location: Germany - Stuttgart
Old 10-10-2009 , 17:56   Re: [EXTENSION] Sound Info Library 0.9 beta
Reply With Quote #2

very nice work.
I can't wait for a sound plugin that uses this, since its annoying to write into a config file how long every sound is. ;)

Hey and how about a mp3-server-based-player? something like radio on demand.
Chanz is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 12-25-2011 , 14:19   Re: [EXTENSION] Sound Info Library 0.9 beta
Reply With Quote #3

Quote:
Originally Posted by Chanz View Post
I can't wait for a sound plugin that uses this, since its annoying to write into a config file how long every sound is. ;)
here is one http://forums.alliedmods.net/showthread.php?t=174799

by the include file
some natives misses buffers

Last edited by Despirator; 12-25-2011 at 14:33.
Despirator is online now
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 02-06-2012 , 18:34   Re: [EXTENSION] Sound Info Library 1.0
Reply With Quote #4

Sound Info Library v1 released !

Date: 07.02.2012

Changelog:
  • Added more accurate native GetSoundDurationFloat() (returns seconds + milli seconds)
  • Code cleanup
  • Updated Taglib to 1.7
__________________
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; 02-06-2012 at 18:35.
berni is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 02-07-2012 , 01:52   Re: [EXTENSION] Sound Info Library 1.0
Reply With Quote #5

PHP Code:
/**
 * Get the Year 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 GetSoundYear(Handle:hndl);

/**
 * Get the Track number 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 GetSoundNum(Handle:hndl);
/**
 * Get the Bit rate of sound (kbps)
 *
 * @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 GetSoundBitRate(Handle:hndl);

/**
 * Get the Sampling rate of sound (hz)
 *
 * @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 GetSoundSamplingRate(Handle:hndl); 
where's the buffer?
Despirator is online now
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 02-07-2012 , 03:22   Re: [EXTENSION] Sound Info Library 1.0
Reply With Quote #6

Ah that's a mistake in the documentation, the values are returned as integer, there are no string buffers.
__________________
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
berni is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 02-07-2012 , 17:02   Re: [EXTENSION] Sound Info Library v1.0.1
Reply With Quote #7

Sound Info Library v1.0.1 released !

Date: 07.02.2012

Changelog:
  • Fixed .inc native documentation
__________________
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
berni is offline
naris
SourceMod Donor
Join Date: Dec 2006
Old 02-15-2012 , 20:17   Re: [EXTENSION] Sound Info Library v1.0.1
Reply With Quote #8

The .inc file should *really* have double inclusion protection.
Something like this:

Code:
#if defined _soundlib_included
  #endinput
#endif
#define _soundlib_included
That would also allow #tryinclude to be used (in conjunction with #if defined _soundlib_included blocks) to allow plugins to provide advanced features when this plugin is available and yet still be compilable by the web compiler.
naris is offline
Chanz
Veteran Member
Join Date: Aug 2008
Location: Germany - Stuttgart
Old 02-15-2012 , 20:30   Re: [EXTENSION] Sound Info Library v1.0.1
Reply With Quote #9

Quote:
Originally Posted by naris View Post
The .inc file should *really* have double inclusion protection.
Something like this:

Code:
#if defined _soundlib_included
  #endinput
#endif
#define _soundlib_included
That would also allow #tryinclude to be used (in conjunction with #if defined _soundlib_included blocks) to allow plugins to provide advanced features when this plugin is available and yet still be compilable by the web compiler.
It already has this in it. function list != <include>.ini
__________________
[ SourceModPlugins.org ][ My Plugins ]

Thank you for donations: [ Paypal ]

Video Tutorial (German): [ Gameserver & SourceMod Plugins mit HLSW verwalten ]
Chanz is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 02-16-2012 , 07:32   Re: [EXTENSION] Sound Info Library v1.0.1
Reply With Quote #10

Quote:
Originally Posted by Chanz View Post
It already has this in it. function list != <include>.ini
does it ?
__________________
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
berni is offline
Reply


Thread Tools
Display Modes

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 16:18.


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