2012-02-02 3 views
3

나는 소리를 내기 위해 SDL audio을 사용하고 있습니다.그 자체에서 콜백을 일시 중지 할 수 있습니까?

SDL_LockAudio이 알려줍니다 :

콜백 함수에서 이것을 호출하지 마십시오 또는 당신은 교착 상태의 원인이됩니다.

그러나, SDL_PauseAudio 그런 말을하지 않는 대신 알려줍니다 :

:

이 기능은 일시 정지 및 오디오 콜백 처리를 일시 중지가 해제 내 믹서 콜백은 다음과 같습니다

void AudioPlaybackCallback(void *, core::bty::UInt8 *stream, int len) 
{ 
     // number of bytes left to play in the current sample 
     const int thisSampleLeft = currentSample.dataLength - currentSample.dataPos; 
     // number of bytes that will be sent to the audio stream 
     const int amountToPlay = std::min(thisSampleLeft, len); 

     if (amountToPlay > 0) 
     { 
      SDL_MixAudio(stream, 
          currentSample.data + currentSample.dataPos, 
          amountToPlay, 
          currentSample.volume); 

      // update the current sample 
      currentSample.dataPos += amountToPlay; 
     } 
     else 
     { 
      if (PlayingQueue::QueueHasElements()) 
      { 
       // update the current sample 
       currentSample = PlayingQueue::QueuePop(); 
      } 
      else 
      { 
       // since the current sample finished, and there are no more samples to 
       // play, pause the playback 
       SDL_PauseAudio(1); 
      } 
     } 
} 

PlayingQueue은 정적 012에 대한 액세스를 제공하는 클래스입니다.개체입니다. 멋진 일은 없어.

SDL 및 alsa 라이브러리를 업데이트하기 전까지는 정상적으로 작동했습니다. 이제 더 이상 되돌릴 수 없습니다. 그 이후로 나는 내 로그에서 볼 :

ALSA lib에 pcm.c : 7316 : 나는 SDL에는 버그 나 ALSA 라이브러리 (이 대부분이다가없는 가정하면

발생 (snd_pcm_recover) 언더런 가능성이 잘못된,이 메시지를 검색 한 후), 내 코드를 수정하거나 최소한 언더런을 피할 수 있어야한다고 생각합니다.

그럼, 질문은 : 콜백을 일시 중지 할 수 있습니까? 내가보고있는 언더런을 일으킬 수 있습니까?

답변

2

마지막으로 알아 냈습니다.

SDL_PauseAudio(1);이 콜백에서 호출되면 SDL은 다른 콜백 (오디오 스트림에 0 만 넣음)으로 전환하려고합니다. 콜백은 함수가 호출 된 후 실행을 완료합니다.

따라서 콜백에서이 함수를 호출하는 것이 안전합니다.

관련 문제