Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

How the virtual-channel is played? #1

Closed
ntop001 opened this issue Oct 11, 2017 · 4 comments
Closed

How the virtual-channel is played? #1

ntop001 opened this issue Oct 11, 2017 · 4 comments

Comments

@ntop001
Copy link

ntop001 commented Oct 11, 2017

if a SoundCollection(about 10s long) is assigned to a virtual-channel (at time 0s), after a while ... until 4s, now a real-channel is free to use. How pindrop play it ? it'll be played from start or played from the audio's 4/10 position ?

@alexames
Copy link

Let me make sure I understand the question: You have a 10 second long sound loaded, and you play it. Then you stop the sound 4 seconds in. Once the sound it stopped it loses its position. Playing a new sound (even if its the same sound) will start again at the beginning. If you want to start it from the 4 second mark where you left off, you need to pause the sound instead.

@ntop001
Copy link
Author

ntop001 commented Oct 14, 2017

@alexames thx for your reply. The sound is not stoped by me, it's stoped by pindrop. I see some code as follows. these code will stop low priority channel and assign it's real-channel to a higher priority channel.

static void UpdateRealChannels(PriorityList* priority_list,
                               FreeList* real_free_list,
                               FreeList* virtual_free_list) {
  PriorityList::reverse_iterator reverse_iter = priority_list->rbegin();
  for (auto iter = priority_list->begin(); iter != priority_list->end();
       ++iter) {
    if (!iter->is_real()) {
      // First check if there are any free real channels.
      if (!real_free_list->empty()) {
        // We have a free real channel. Assign this channel id to the channel
        // that is trying to resume, clear the free channel, and push it into
        // the virtual free list.
        ChannelInternalState* free_channel = &real_free_list->front();
        iter->Devirtualize(free_channel);
        virtual_free_list->push_front(*free_channel);
        iter->Resume();
      } else {
        // If there aren't any free channels, then scan from the back of the
        // list for low priority real channels.
        reverse_iter =
            std::find_if(reverse_iter, PriorityList::reverse_iterator(iter),
                         [](const ChannelInternalState& channel) {
                           return channel.real_channel().Valid();
                         });
        if (reverse_iter == priority_list->rend()) {
          // There is no more swapping that can be done. Return.
          return;
        }
        // Found a real channel that we can give to the higher priority
        // channel.
        iter->Devirtualize(&*reverse_iter);
      }
    }
  }
}

@alexames
Copy link

Yeah, if you have too many sounds playing at once it will stop playing the lowest priority sounds. I believe in the sample file I have the number of channels set relatively low, but it could realistically be pretty large (how large depends on how much other work your app is doing - you'll have to profile to figure out the right balance).

Right now the underlying library used to mix the audio (SDL_mixer) doesn't have the ability to play a sound starting from a certain timestamp, so when a sound begins playing again it will just start from the beginning rather than from where it should.

@ntop001
Copy link
Author

ntop001 commented Oct 23, 2017

@alexames Got it.

@ntop001 ntop001 closed this as completed Oct 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants