Announcer sound playing

Discussions about Coding and Scripting
Post Reply
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Announcer sound playing

Post by 1337GameDev »

I have a few game modes im working on, and have announcer intro sounds, as well as messages throughout the gametypes, and cannot get sounds to play.

I recorded using audacity, and exported as 16-bit wav.

I import into my uc script using this directive:

Code: Select all

#exec AUDIO IMPORT FILE="Sounds\MyIntro.wav" NAME="MyIntro" GROUP="Announcer"
var Sound IntroSound;

defaultproperties {
    IntroSound=Sound'MyGame.Announcer.MyIntro',
}
And then try to play it using these commands:

Code: Select all

For (P=Level.PawnList; P!=None; P=P.NextPawn) {
	//P.PlaySound(IntroSound,, 32.0);
	if(P.IsA('PlayerPawn')) {
		PlayerPawn(P).ClientPlaySound(IntroSound,, true);
	}
}
Neither option seem to play the sound... I notice no errors / accessed nones in my log files, so the sounds should be imported just fine when I compile my package.

Is there any specific import parameters i'm missing? What about volume issues? When ive imported weapon / item sounds, they are sometimes very low volume.

Ideas?
Last edited by 1337GameDev on Thu Jan 13, 2022 5:17 pm, edited 1 time in total.
User avatar
OjitroC
Godlike
Posts: 3613
Joined: Sat Sep 12, 2015 8:46 pm

Re: Announcer sound playing

Post by OjitroC »

You have a compiled package so - are the sounds in the package? Do they play in the Sound Browser?

What samplerate did you use when recording and exporting the sounds?
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Announcer sound playing

Post by 1337GameDev »

OjitroC wrote: Wed Jan 12, 2022 5:34 pm You have a compiled package so - are the sounds in the package? Do they play in the Sound Browser?

What samplerate did you use when recording and exporting the sounds?
Yup, they play in the sound browser.

The sample rate was the Audacity default - 44.1kHz.
User avatar
The_Cowboy
Skilled
Posts: 165
Joined: Mon Jan 24, 2011 3:22 am
Personal rank: Codezilla

Re: Announcer sound playing

Post by The_Cowboy »

Well the code seems alright to me.
What you can do is embed log every line and see everything is executed in right sequence.
If you need help look up my mutator FlagAnnouncements floating somewhere.
Feralidragon wrote:Trial and error is sometimes better than any tutorial, because we learn how it works for ourselfs, which kills any doubts about anything :tu:
Patreon: https://www.patreon.com/FreeandOpen
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Announcer sound playing

Post by 1337GameDev »

I looked it up, and it DynamicLoads audio, which was interesting. The audio file playing was:


Code: Select all

function PostBeginPlay()
{
    local byte i;
    local FlagBase fb;
    local bool IsTrue;
    local string ServerPackages;

    Log("+----------------------------------------------------------------------------------------------------+");
    Log("|                                                              ");
    Log("|           FlagAnnouncements Loading ...                   ");
    Log("|           Author     -     The_Cowboy                        ");
    Log("|          Voicepack   -    "@VoicePack@"                       ");
    Log("|                                                              ");

    // Get server actor list.
	ServerPackages = (consoleCommand("get Engine.GameEngine ServerPackages"));

    if( !(instr(ServerPackages, Voicepack ) > 0) )
     {
      Log("| (Error) - VoicePack "@VoicePack@" is not found in ServerPackages");
      Log("| FlagAnnouncements will now destroy itself ");
      Log("+----------------------------------------------------------------------------------------------------+");
     super.PostBeginPlay();
     Destroy();
     return;
     }

    if ( bPickupAnnouncement )
    {
        Log("|++ Loading FlagPickup Announcement                                ");

        if (!(DynamicLoadSound(PickupAnnouncement[0],"RedFlag_Taken")
        && DynamicLoadSound(PickupAnnouncement[1],"BlueFlag_Taken")))
            LogError("Flag_taken","PickupAnnouncement");
    }
    else Log("|-- FlagPickup Announcement not loaded                             ");
    
    [.............]
    
}
    
// =============================================================================
// DynamicLoadSound ~ Load a sound from our VoicePack
// =============================================================================

function bool DynamicLoadSound (out sound zzSound, string zzSoundName)
{
   // zzLastSoundName = zzSoundName;
    zzSound = sound(DynamicLoadObject(VoicePack$"."$zzSoundName,class'sound',true));

    if (zzSound == None)
        return false;
    else
        return true;
}

function PlayDroppedAnnouncement(byte Team)
{
    local Pawn P;

       for ( P=Level.PawnList; P!=None; P=P.nextPawn )
       {
          if (PlayerPawn(P) != None && DroppedAnnouncement[Team] != None)
             PlayerPawn(P).ClientPlaySound(DroppedAnnouncement[Team]);
       }
}
Interesting mutator.

Does this

Code: Select all

ServerPackages = (consoleCommand("get Engine.GameEngine ServerPackages"));
load ALL server package names into a comma delimited string? Then you use:

Code: Select all

if( !(instr(ServerPackages, Voicepack ) > 0) )
to ensure this mutator ONLY loads if that package ('Voicepack') is in the string? So for example, if my code depends on ChaosUT, i could do this:

Code: Select all

if( !(instr(ServerPackages, "ChaosUT") > 0) )
and my code will detect if ChaosUT isn't included as a loaded package? And this can be any package name? What if I want to check for a package when NOT running on a server? (local client only / self host client)?

I also use essentially the same code to play the sound, and my sound doesn't play :/ Ideas?

EDIT:

I found an issue:
The sounds I have are NONE when I check using an if statement... Why would this be?

I set it in the default properties block..... And there's no import errors.....

IntroSound=Sound'MyGame.Announcer.MyIntro',
User avatar
OjitroC
Godlike
Posts: 3613
Joined: Sat Sep 12, 2015 8:46 pm

Re: Announcer sound playing

Post by OjitroC »

Snce the sound you want to play Sound'MyGame.Announcer.MyIntro' is set in the default properties, have you tried testing the package with a default sound that you know works in the game? So why not extract or just use a sound from one of the default voicepacks - if that sound plays, the problem lies in the wav files you want to use; if that sound doesn't play, the problem lies with the code.

Is the problem to do with using 'Announcer' as the group name? It's a default sound package and is called in code elsewhere.

I think I have come across issues with using sounds with 44100Hz samplerate in VPs - not all but some - they do play in the sound browser but then either don't play ingame or cause other effects (altering weapon sounds for example). Personally I just follow the codec of default sounds and then there are (normally) no issues.
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Announcer sound playing

Post by sektor2111 »

Whenever I did a sound out of stock, I was willing to check it. I used a temporary cube map (or cylinder, lol) and adding there a "SpecialEvent" delegated to play a sound triggered and figuring best settings for such Sound Event. If you don't hear anything then sound file is not good. As far as I recall I have exported sounds from Editor, examining their format and using THE SAME format for any new sound taken from any random source.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Announcer sound playing

Post by 1337GameDev »

Hmm, I followed this post:

viewtopic.php?f=51&p=76215#p76215

and used "wav pcm 11khz 8bit mono" (but chose 16-bin pcm in export)

I was able to get it to play, but the volume is very low and is interrupted with multiple other sounds.... Despite me inputting "true" for flags to interrupt other sounds....

I use this:

Code: Select all

if(MyIntroSound == None){
	Log("MyIntroSound sound was NONE");
} else {
	Log("MyIntroSound sound was NOT none");
}

For (P=Level.PawnList; P!=None; P=P.NextPawn) {
	if(P.IsA('PlayerPawn')){
		PlayerPawn(P).ClientPlaySound(MyIntroSound, true, true);
	}
}
In the before check, it reports that the sound was NONE, despite it playing... ?

I am super confused. I don't understand what's going on.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Announcer sound playing

Post by 1337GameDev »

I finally have something that's workable:

Creating the sounds (in audacity):
  1. Record audio
  2. Go to left of audio, and right click on the track properties, and click "Split Stereo To Mono"
  3. Delete one of the tracks
  4. In the lower left, in project settings, I changed the "Project Rate" to "22050" Hz
  5. Select all the audio (I use CTRL+A)
  6. Go to "Tracks" in the top menu, and click "Resample," ensure 22050Hz is input, and click accept
  7. Select all the audio (I use CTRL+A)
  8. Go to Effect -> Amplify, and accept the default value (it selects the max for the waveform without clipping -- you can make this larger if you enable some clipping of the max peaks of the waveform)
  9. Click on File -> Export -> Export as WAV
  10. Select "Signed 16-bit PCM" in the "Encoding" option
  11. Save the audio wherever
In-Game Code:

Import using a normal audio import directive.

I made this method/class to play the audio (so i have control over audio volume level versus just fixed to 16 -- as idk the maximum volume, but it seems higher than 16):

Code: Select all

class SoundHelper extends Actor nousercreate;

//Copied mainly from PlayerPawn.uc
simulated static function ClientPlaySound(PlayerPawn pp, sound ASound, optional bool bInterrupt, optional bool bVolumeControl, optional float VolumeLevel) {
    local Actor SoundPlayer;

    if(pp == None){
        return;
    }
    
    //just to be safe
    VolumeLevel = FClamp(VolumeLevel, 0.1, 200.0);

    pp.LastPlaySound = pp.Level.TimeSeconds;	// so voice messages won't overlap
    if (pp.ViewTarget != None) {
	SoundPlayer = pp.ViewTarget;
    } else {
	SoundPlayer = pp;
    }

    SoundPlayer.PlaySound(ASound, pp.ESoundSlot.SLOT_None, VolumeLevel, bInterrupt);
    SoundPlayer.PlaySound(ASound, pp.ESoundSlot.SLOT_Interface, VolumeLevel, bInterrupt);
    SoundPlayer.PlaySound(ASound, pp.ESoundSlot.SLOT_Misc, VolumeLevel, bInterrupt);
    SoundPlayer.PlaySound(ASound, pp.ESoundSlot.SLOT_Talk, VolumeLevel, bInterrupt);
}
Then call in code using the following:

Code: Select all

For (P=Level.PawnList; P!=None; P=P.NextPawn) {
	if(P.IsA('PlayerPawn')) {
		class'SoundHelper'.static.ClientPlaySound(PlayerPawn(P), SoundName, true, true, 100);
	}
}
Seems to work alright. Doesn't interrupt environment / other actor sounds however, but this is good enough.
Post Reply