Exemplo n.º 1
0
TEST(cubeb, configure_stream)
{
  int r;
  cubeb * ctx;
  cubeb_stream * stream;
  cubeb_stream_params params;

  r = common_init(&ctx, "test_sanity");
  ASSERT_EQ(r, CUBEB_OK);
  ASSERT_NE(ctx, nullptr);

  params.format = STREAM_FORMAT;
  params.rate = STREAM_RATE;
  params.channels = 2; // panning
  params.layout = CUBEB_LAYOUT_STEREO;

  r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
                        test_data_callback, test_state_callback, &dummy);
  ASSERT_EQ(r, CUBEB_OK);
  ASSERT_NE(stream, nullptr);

  r = cubeb_stream_set_volume(stream, 1.0f);
  ASSERT_TRUE(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);

  r = cubeb_stream_set_panning(stream, 0.0f);
  ASSERT_TRUE(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);

  cubeb_stream_destroy(stream);
  cubeb_destroy(ctx);
}
Exemplo n.º 2
0
static void
test_configure_stream(void)
{
  int r;
  cubeb * ctx;
  cubeb_stream * stream;
  cubeb_stream_params params;

  BEGIN_TEST;

  r = cubeb_init(&ctx, "test_sanity");
  assert(r == 0 && ctx);

  params.format = STREAM_FORMAT;
  params.rate = STREAM_RATE;
  params.channels = 2; // panning

  r = cubeb_stream_init(ctx, &stream, "test", params, STREAM_LATENCY,
                        test_data_callback, test_state_callback, &dummy);
  assert(r == 0 && stream);

  r = cubeb_stream_set_volume(stream, 1.0f);
  assert(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);

  r = cubeb_stream_set_panning(stream, 0.0f);
  assert(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);

  cubeb_stream_destroy(stream);
  cubeb_destroy(ctx);
  END_TEST;
}
Exemplo n.º 3
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.º 4
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
}
Exemplo n.º 5
0
int run_panning_volume_test(int is_float)
{
  int r = CUBEB_OK;

  cubeb *ctx = NULL;
  synth_state* synth = NULL;
  cubeb_stream *stream = NULL;
  const char * backend_id = NULL;

  r = cubeb_init(&ctx, "Cubeb audio test");
  if (r != CUBEB_OK) {
    fprintf(stderr, "Error initializing cubeb library\n");
    goto cleanup;
  }
  backend_id = cubeb_get_backend_id(ctx);

  if ((is_float && !supports_float32(backend_id)) ||
      (!is_float && !supports_int16(backend_id))) {
    /* don't treat this as a test failure. */
    goto cleanup;
  }

  cubeb_stream_params params;
  params.format = is_float ? CUBEB_SAMPLE_FLOAT32NE : CUBEB_SAMPLE_S16NE;
  params.rate = 44100;
  params.channels = 2;

  synth = synth_create(params.channels, params.rate);
  if (synth == NULL) {
    fprintf(stderr, "Out of memory\n");
    goto cleanup;
  }

  r = cubeb_stream_init(ctx, &stream, "test tone", NULL, NULL, NULL, &params,
                        4096, is_float ? data_cb_float : data_cb_short,
                        state_cb_audio, synth);
  if (r != CUBEB_OK) {
    fprintf(stderr, "Error initializing cubeb stream: %d\n", r);
    goto cleanup;
  }

  fprintf(stderr, "Testing: volume\n");
  for(int i=0;i <= 4; ++i)
  {
    fprintf(stderr, "Volume: %d%%\n", i*25);

    cubeb_stream_set_volume(stream, i/4.0f);
    cubeb_stream_start(stream);
    delay(400);
    cubeb_stream_stop(stream);
    delay(100);
  }

  fprintf(stderr, "Testing: panning\n");
  for(int i=-4;i <= 4; ++i)
  {
    fprintf(stderr, "Panning: %.2f%%\n", i/4.0f);

    cubeb_stream_set_panning(stream, i/4.0f);
    cubeb_stream_start(stream);
    delay(400);
    cubeb_stream_stop(stream);
    delay(100);
  }

cleanup:
  cubeb_stream_destroy(stream);
  cubeb_destroy(ctx);
  synth_destroy(synth);

  return r;
}