AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Way to detect when sound finished playing (https://forums.alliedmods.net/showthread.php?t=89590)

hleV 04-08-2009 07:35

Way to detect when sound finished playing
 
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?

fysiks 04-08-2009 07:57

Re: Way to detect when sound finished playing
 
Since you are using a client side command I would guess not because everything would only require handling client-side.

Arkshine 04-08-2009 08:42

Re: Way to detect when sound finished playing
 
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 );     }

hleV 04-08-2009 08:50

Re: Way to detect when sound finished playing
 
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).

xPaw 04-08-2009 09:00

Re: Way to detect when sound finished playing
 
you still can use arkshine's stock and make an set_task.

hleV 04-08-2009 09:21

Re: Way to detect when sound finished playing
 
Quote:

Originally Posted by xPaw (Post 800678)
you still can use arkshine's stock and make an set_task.

...
I don't know when the sound starts in my case...

hleV 06-15-2009 04:17

Re: Way to detect when sound finished playing
 
Bump.

I now need some program or working code (arkshine's one returns 0.000000) to get the length of a wave sound.

Arkshine 06-15-2009 04:54

Re: Way to detect when sound finished playing
 
My code works fine.

Attach the wav which doesn't work.

hleV 06-16-2009 07:37

Re: Way to detect when sound finished playing
 
Looks like I forgot to add "sound/". ^^


All times are GMT -4. The time now is 02:22.

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