Exemplo n.º 1
0
void AudioStream::ResetStreamIfNeeded()
{
  cubeb_device * device;
  // Only reset a device if a mic is active, and this is a low latency stream.
  if (!mMicrophoneActive || mLatencyRequest != LowLatency) {
    return;
  }
  if (cubeb_stream_get_current_device(mCubebStream.get(), &device) == CUBEB_OK) {
    // This a microphone that goes through the headphone plug, reset the
    // output to prevent echo building up.
    if (strcmp(device->input_name, "emic") == 0) {
      LOG(("Resetting audio output"));
      Reset();
    }
    cubeb_stream_device_destroy(mCubebStream.get(), device);
  }
}
Exemplo n.º 2
0
// On certain MacBookPro, the microphone is located near the left speaker.
// We need to pan the sound output to the right speaker if we are using the mic
// and the built-in speaker, or we will have terrible echo.
void AudioStream::PanOutputIfNeeded(bool aMicrophoneActive)
{
#ifdef XP_MACOSX
  cubeb_device* device;
  int rv;
  char name[128];
  size_t length = sizeof(name);
  bool panCenter = false;

  rv = sysctlbyname("hw.model", name, &length, NULL, 0);
  if (rv) {
    return;
  }

  if (!strncmp(name, "MacBookPro", 10)) {
    if (cubeb_stream_get_current_device(mCubebStream.get(), &device) == CUBEB_OK) {
      // Check if we are currently outputing sound on external speakers.
      if (!strcmp(device->output_name, "ispk")) {
        // Pan everything to the right speaker.
        if (aMicrophoneActive) {
          LOG(("%p Panning audio output to the right.", this));
          if (cubeb_stream_set_panning(mCubebStream.get(), 1.0) != CUBEB_OK) {
            NS_WARNING("Could not pan audio output to the right.");
          }
        } else {
          panCenter = true;
        }
      } else {
        panCenter = true;
      }
      if (panCenter) {
        LOG(("%p Panning audio output to the center.", this));
        if (cubeb_stream_set_panning(mCubebStream.get(), 0.0) != CUBEB_OK) {
          NS_WARNING("Could not pan audio output to the center.");
        }
      }
      cubeb_stream_device_destroy(mCubebStream.get(), device);
    }
  }
#endif
}
Exemplo n.º 3
0
void AudioCallbackDriver::PanOutputIfNeeded(bool aMicrophoneActive)
{
#ifdef XP_MACOSX
    cubeb_device* out;
    int rv;
    char name[128];
    size_t length = sizeof(name);

    rv = sysctlbyname("hw.model", name, &length, NULL, 0);
    if (rv) {
        return;
    }

    if (!strncmp(name, "MacBookPro", 10)) {
        if (cubeb_stream_get_current_device(mAudioStream, &out) == CUBEB_OK) {
            // Check if we are currently outputing sound on external speakers.
            if (!strcmp(out->output_name, "ispk")) {
                // Pan everything to the right speaker.
                if (aMicrophoneActive) {
                    if (cubeb_stream_set_panning(mAudioStream, 1.0) != CUBEB_OK) {
                        NS_WARNING("Could not pan audio output to the right.");
                    }
                } else {
                    if (cubeb_stream_set_panning(mAudioStream, 0.0) != CUBEB_OK) {
                        NS_WARNING("Could not pan audio output to the center.");
                    }
                }
            } else {
                if (cubeb_stream_set_panning(mAudioStream, 0.0) != CUBEB_OK) {
                    NS_WARNING("Could not pan audio output to the center.");
                }
            }
            cubeb_stream_device_destroy(mAudioStream, out);
        }
    }
#endif
}