Multiple AudioChannel pointers playing same track

Started by geork, Thu 27/06/2013 17:17:38

Previous topic - Next topic

geork

I have the following code:
Code: AGS
//Header of script
AudioChannel *Channel[5];
//Body of script
void AddSound(AudioClip *clip, AudioPriority priority, RepeatStyle repeat, int volume){
  int i, transfer;
  while(i<5){
    if(Channel[i] == null){ transfer = i; i = 10;}
    i ++;
  }
  if(i!=11){ Display("Too many sounds!"); return;}
  Channel[transfer] = clip.Play(priority, repeat);
  Channel[transfer].Volume = volume;
}
void AddSoundAt(AudioClip *clip, AudioPriority priority, RepeatStyle repeat, int x, int y, int volume){
  int i, transfer;
  while(i<5){
    if(Channel[i] == null){ transfer = i; i = 10;}
    i ++;
  }
  if(i!=11){ Display("Too many sounds!"); return;}
  Channel[transfer] = clip.Play(priority, repeat);
  Channel[transfer].Volume = volume;
  Channel[transfer].SetRoomLocation(x, y);
}

then in Room_AfterFadeIn():
Code: AGS
 AddSound(aSound1, eAudioPriorityHigh, eRepeat, 100);
 AddSoundAt(aSound2, eAudioPriorityHigh, eRepeat, 2173, 412, 100);
 AddSoundAt(aSound3, eAudioPriorityHigh, eRepeat, 439, 421, 100);


  The weird thing is, only aSound3 is played. After further investigation, I discovered that the first 3 Channels (Channel[0] to Channel[2]) all have aSound3 as the sound they are playing.

  Annoyingly, the above used to work normaly, but after I replaced some sound files and modified the code like this:
Code: AGS
//Body
void CheckSoundsAreNotNull(){
  int i;
  while(i<5){
    if(Channel[i] != null){
      if(!Channel[i].IsPlaying) Channel[i] = null;
    }
    i++;
  }
}
void AddSound(AudioClip *clip, AudioPriority priority, RepeatStyle repeat, int volume){
  CheckSoundsAreNotNull();
  //same code as above
}
void AddSoundAt(AudioClip *clip, AudioPriority priority, RepeatStyle repeat, int x, int y, int volume){
  CheckSoundsAreNotNull();
  //same code as above
}

Seeing that only the last declared sound was playing, I reverted to the unmodified code, but it seemed the damage had been done and only Sound3 was playing?

Any ideas as to what could be causing this?

Thanks again!

UPDATE: just attempted this code in Room_AfterFadeIn() to replace the previous room code:
Code: AGS
 aSound1.Play();
 aSound2.Play();
 aSound3.Play();

it seems to have the same problem now...

Crimson Wizard

Go to Audio -> Types and select (double click) type "Sound". What is the value of "Max Channels" property?
I have a suspicion it may be set to 1. If it is, set it to larger number, or 0 (unlimited).

E: I forgot to ask what type are your aSoundX clips? You need to check corresponding type.

geork

Ah, they were all Ambient, but Ambient "Max Channels" was set to 1. Changed it to 0 and everything works! :)

Thanks again!

SMF spam blocked by CleanTalk