Raised This Month: $ Target: $400
 0% 

Way to detect when sound finished playing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-08-2009 , 07:35   Way to detect when sound finished playing
Reply With Quote #1

Hi. I was wondering if there's any way to detect when the sound was finished playing to client.

Like if I use this in game console
Code:
spk "misc/ut3/doublekill multikill megakill ultrakill monsterkill"
it will play one sound after another without overlapping. So, as I understand, the game itself detects when the sound has finished playing and then start another one.
So I wonder if there's a way to do it by AMXX. Maybe with CBase?
__________________

Last edited by hleV; 04-08-2009 at 07:37.
hleV is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-08-2009 , 07:57   Re: Way to detect when sound finished playing
Reply With Quote #2

Since you are using a client side command I would guess not because everything would only require handling client-side.
__________________
fysiks is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-08-2009 , 08:42   Re: Way to detect when sound finished playing
Reply With Quote #3

You can use a plugin to calculate the length of a wav sound then playing each sound without overlapping.

For the wav, what I'm using :

Code:
    /*         (*) Wav file format.         (*) More informations : http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/                [  Offset     Field      Size  ]                 0      ChunkId        4  |             4      ChunkSize      4  |-> The "RIFF" chunk descriptor.             8      Format         4  |                         12     SubChuck1ID    4  |             16     SubChuck1Size  4  |                 20     AudioFormat    2  |             22     NumChannels    2  |-> The "fmt" sub-chunk.             24     SampleRate     4  |             28     ByteRate       4  |             32     BlockAlign     2  |             34     BitPerSample   2  |                         36     SubChunk2ID    4  |             40     SubChunk2Size  4  |-> The "data" sub-chunk             44     Data           |  |                          SubChunk2Size                                   (*) Time = SubChunk2Size / ( BitPerSample * SampleRate ) / 8.     */     Float:GetWavDuration( const WavFile[] )     {         new Frequence [ 4 ];         new Bitrate   [ 2 ];         new DataLength[ 4 ];         new File;                 // --| Open the file.         File = fopen( WavFile, "rb" );                 // --| Get the frequence from offset 24. ( Read 4 bytes )         fseek( File, 24, SEEK_SET );         fread_blocks( File, Frequence, 4, BLOCK_INT );                 // --| Get the bitrate from offset 34. ( read 2 bytes )         fseek( File, 34, SEEK_SET );         fread_blocks( File, i_Bitrate, 2, BLOCK_BYTE );                 // --| Search 'data'. If the 'd' not on the offset 40, we search it.         if ( fgetc( File ) != 'd' ) while( fgetc( File ) != 'd' && !feof( File ) ) {}                 // --| Get the data length from offset 44. ( after 'data', read 4 bytes )         fseek( File, 3, SEEK_CUR );         fread_blocks( File, DataLength, 4, BLOCK_INT );         // --| Close file.         fclose( File );                 // --| Calculate the time. ( Data length / ( frequence * bitrate ) / 8 ).         return float( DataLength[ 0 ] ) / ( float( Frequence[ 0 ] * i_Bitrate[ 0 ] ) / 8.0 );     }

Last edited by Arkshine; 04-08-2009 at 08:44.
Arkshine is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-08-2009 , 08:50   Re: Way to detect when sound finished playing
Reply With Quote #4

Yeah, thanks. But I needed something to detect when the player is no longer hearing the sound, so I could start a new one (this doesn't include emit sound, just the sound to the client only).
__________________
hleV is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 04-08-2009 , 09:00   Re: Way to detect when sound finished playing
Reply With Quote #5

you still can use arkshine's stock and make an set_task.
__________________
xPaw is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-08-2009 , 09:21   Re: Way to detect when sound finished playing
Reply With Quote #6

Quote:
Originally Posted by xPaw View Post
you still can use arkshine's stock and make an set_task.
...
I don't know when the sound starts in my case...
__________________
hleV is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-15-2009 , 04:17   Re: Way to detect when sound finished playing
Reply With Quote #7

Bump.

I now need some program or working code (arkshine's one returns 0.000000) to get the length of a wave sound.
__________________
hleV is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-15-2009 , 04:54   Re: Way to detect when sound finished playing
Reply With Quote #8

My code works fine.

Attach the wav which doesn't work.
__________________
Arkshine is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-16-2009 , 07:37   Re: Way to detect when sound finished playing
Reply With Quote #9

Looks like I forgot to add "sound/". ^^
__________________
hleV 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 02:22.


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