AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   [EXTENSION] Sound Info Library v1.0.1 (https://forums.alliedmods.net/showthread.php?t=105816)

berni 10-08-2009 16:58

[EXTENSION] Sound Info Library v1.0.1
 
1 Attachment(s)
https://www.bcserv.eu/images/sourcemod/soundinfolib.png

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).

Chanz 10-10-2009 17:56

Re: [EXTENSION] Sound Info Library 0.9 beta
 
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. :)

Despirator 12-25-2011 14:19

Re: [EXTENSION] Sound Info Library 0.9 beta
 
Quote:

Originally Posted by Chanz (Post 957989)
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

berni 02-06-2012 18:34

Re: [EXTENSION] Sound Info Library 1.0
 
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

Despirator 02-07-2012 01:52

Re: [EXTENSION] Sound Info Library 1.0
 
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?

berni 02-07-2012 03:22

Re: [EXTENSION] Sound Info Library 1.0
 
Ah that's a mistake in the documentation, the values are returned as integer, there are no string buffers.

berni 02-07-2012 17:02

Re: [EXTENSION] Sound Info Library v1.0.1
 
Sound Info Library v1.0.1 released !

Date: 07.02.2012

Changelog:
  • Fixed .inc native documentation

naris 02-15-2012 20:17

Re: [EXTENSION] Sound Info Library v1.0.1
 
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.

Chanz 02-15-2012 20:30

Re: [EXTENSION] Sound Info Library v1.0.1
 
Quote:

Originally Posted by naris (Post 1651299)
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

berni 02-16-2012 07:32

Re: [EXTENSION] Sound Info Library v1.0.1
 
Quote:

Originally Posted by Chanz (Post 1651310)
It already has this in it. function list != <include>.ini

does it ?


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

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