Example #1
0
      public ALFormat GetFormat(SoundPack pack)
      {
        if (pack.Channels != 2 && pack.Channels != 1)
          throw new ArgumentException("channels");

        if (pack.BitPerChannel != 8 && pack.BitPerChannel != 16)
          throw new ArgumentException("bitPerChannel");

        if (pack.Channels == 1)
          return pack.BitPerChannel == 8 ? ALFormat.Mono8 : ALFormat.Mono16;
        else
          return pack.BitPerChannel == 8 ? ALFormat.Stereo8 : ALFormat.Stereo16;
      }
Example #2
0
    public void Enqueue(string id, long packNumber, SoundPack pack)
    {
      if (string.IsNullOrEmpty(id))
        throw new ArgumentException("id");

      if (!IsInited)
        return;

      lock (syncObject)
      {
        SourceDescription source;
        if (!sources.TryGetValue(id, out source))
        {
          int sourceId = AL.GenSource();
          source = new SourceDescription(sourceId);
          sources.Add(id, source);
        }

        if (source.LastPlayedNumber > packNumber)
          return;

        source.LastPlayedNumber = packNumber;

        int bufferId = AL.GenBuffer();
        AL.BufferData(bufferId, source.GetFormat(pack), pack.Data, pack.Data.Length, pack.Frequency);
        AL.SourceQueueBuffer(source.Id, bufferId);

        if (AL.GetSourceState(source.Id) != ALSourceState.Playing)
          AL.SourcePlay(source.Id);

        ClearBuffers(source, 0);
      }
    }