Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 68
Registered: ‎03-12-2013
My Device: BB Z10
My Carrier: Rogers

alSourcePlay succeeds, but there is no sound in one case

I have my sound code working fine using alSourcePlay just like the samples suggest. However, when there is other audio going on this produces no sound. We are developing a VOIP application and when there is a VOIP call in progress with audio, the calls to alSourcePlay seem to succeed (no errors) but there is no audio played. As an example, when the VOIP call is in progress we might want to play an audio file for keyclicks, or to indicate call waiting, etc. I suspect the BB Z10 device is coded to ignore some audio sources while others are playing? What is the workaround to force the alSourcePlay to play even though there is other audio going on?

 

Here is how we setup the audio for a call...

 

if ((ret = audio_manager_snd_pcm_open_name(
AUDIO_TYPE_VIDEO_CHAT,
&stream->pb_pcm, &stream->pb_audio_manager_handle,
(char*)"voice",
SND_PCM_OPEN_PLAYBACK)) < 0)
{
  TRACE_((THIS_FILE, "audio_manager_snd_pcm_open_name ret = %d", ret));
  return PJMEDIA_EAUD_SYSERR;
}

/* Required call from January 2013 gold OS release */
snd_pcm_plugin_set_disable(stream->pb_pcm, PLUGIN_DISABLE_MMAP);

 

/* Required call from January 2013 gold OS release */
snd_pcm_plugin_set_enable(stream->pb_pcm, PLUGIN_ROUTING);

 

memset (&pi, 0, sizeof (pi));
pi.channel = SND_PCM_CHANNEL_PLAYBACK;
if ((ret = snd_pcm_plugin_info (stream->pb_pcm, &pi)) < 0) {
  TRACE_((THIS_FILE, "snd_pcm_plugin_info ret = %d", ret));
  return PJMEDIA_EAUD_SYSERR;
}

 

memset (&pp, 0, sizeof (pp));

/* Request VoIP compatible capabilities */
pp.mode = SND_PCM_MODE_BLOCK;
pp.channel = SND_PCM_CHANNEL_PLAYBACK;
pp.start_mode = SND_PCM_START_FULL;
pp.stop_mode = SND_PCM_STOP_ROLLOVER;
pp.buf.block.frag_size = param->samples_per_frame * param->bits_per_sample / 8;
/* RIM recommends maximum of 5 */
pp.buf.block.frags_max = 5;
pp.buf.block.frags_min = 1;
pp.format.interleave = 1;
pp.format.rate = param->clock_rate;
pp.format.voices = param->channel_count;
pp.format.format = get_alsa_pcm_fmt(param);

/* Make the calls as per the wave sample */
if ((ret = snd_pcm_plugin_params (stream->pb_pcm, &pp)) < 0) {
  TRACE_((THIS_FILE, "snd_pcm_plugin_params ret = %d", ret));
  return PJMEDIA_EAUD_SYSERR;
}

 

memset (&setup, 0, sizeof (setup));
memset (&group, 0, sizeof (group));
setup.channel = SND_PCM_CHANNEL_PLAYBACK;
setup.mixer_gid = &group.gid;

if ((ret = snd_pcm_plugin_setup (stream->pb_pcm, &setup)) < 0) {
  TRACE_((THIS_FILE, "snd_pcm_plugin_setup ret = %d", ret));
  return PJMEDIA_EAUD_SYSERR;
}

 

 

And this is how we use the alSourcePlay...

 

ALuint bufferID = 0;

// Get the corresponding buffer id set up in the init function.
if (!m_hSoundBuffers.contains(m_Dir.absoluteFilePath(name)))
{
  bufferID = addFile(name);
} else
{
  bufferID = m_hSoundBuffers[m_Dir.absoluteFilePath(name)];
}

if (bufferID != 0)
{
  if (alIsSource(m_uiSoundSource) == AL_TRUE)
  {

    // Attach the buffer to an available source.
    alSourcei(m_uiSoundSource, AL_BUFFER, bufferID);
    ALenum result = alGetError();
   if (result != AL_NO_ERROR)
   {
     l.p("alSourcei: OpenAL reported the error: %s", alutGetErrorString(result));
     return false;
   }

   // Set the source pitch value.
   alSourcef(m_uiSoundSource, AL_PITCH, pitch);
   result = alGetError();
   if (result != AL_NO_ERROR)
   {
     l.p("alSourcef(AL_PITCH): OpenAL reported the error: %s", alutGetErrorString(result));
     return false;
   }

   // Set the source gain value.
   alSourcef(m_uiSoundSource, AL_GAIN, gain);
   result = alGetError();
   if (result != AL_NO_ERROR)
   {
     l.p("alSourcef(AL_GAIN): OpenAL reported the error: %s", alutGetErrorString(result));
     return false;
   }

   alSourcei(m_uiSoundSource, AL_LOOPING, isLooping);
   result = alGetError();
   if (result != AL_NO_ERROR)
   {
     l.p("alSourcei(AL_LOOPING): OpenAL reported the error: %s", alutGetErrorString(result));
     return false;
   }

   // Play the source.
   alSourcePlay(m_uiSoundSource);
   result = alGetError();
   if (result != AL_NO_ERROR)
   {
     l.p("alSourcePlay: OpenAL reported the error: %s", alutGetErrorString(result));
     return false;
   }
  }
} else
{
  l.p("The buffer was not found.");
  return false;
}

 

Developer
Posts: 68
Registered: ‎03-12-2013
My Device: BB Z10
My Carrier: Rogers

Re: alSourcePlay succeeds, but there is no sound in one case

Also, while there is a VOIP call in progress, we make calls to the following to control where the audio is played on the device (speakers, headset, etc.)...

 

ret = audio_manager_set_handle_type(
stream->pb_ctrl_audio_manager_handle,
AUDIO_TYPE_VIDEO_CHAT,
output,
input);

 

if (ret == 0) {
  /* RIM recommend this call */
  ret = audio_manager_set_handle_routing_conditions(
  stream->pb_ctrl_audio_manager_handle,
  SETTINGS_RESET_ON_DEVICE_CONNECTION);
  if (ret != 0) {
    TRACE_((THIS_FILE,
    "audio_manager_set_handle_routing_conditions ret = %d",
    ret));
    return PJMEDIA_EAUD_SYSERR;
  }
} else {
  TRACE_((THIS_FILE, "audio_manager_set_handle_type ret = %d", ret));
  return PJMEDIA_EAUD_SYSERR;
}