src/media/audio/audio_core/output_pipeline_unittest.cc
// Identical to |Loopback|, except we run mix and linearize stages at different rates.
Identical to |Loopback|, except we run mix and linearize stages at different rates.
Identical to |Loopback| except we run mix and linearize stages at different rates .
TEST_F(OutputPipelineTest, LoopbackWithUpsample) {
  auto test_effects = testing::TestEffectsModule::Open();
  test_effects.AddEffect("add_1.0").WithAction(TEST_EFFECTS_ACTION_ADD, 1.0);
  PipelineConfig::MixGroup root{
      .name = "linearize",
      .input_streams =
          {
              RenderUsage::BACKGROUND,
          },
      .effects =
          {
              {
                  .lib_name = "test_effects.so",
                  .effect_name = "add_1.0",
                  .instance_name = "",
                  .effect_config = "",
              },
          },
      .inputs = {{
          .name = "mix",
          .input_streams =
              {
                  RenderUsage::MEDIA,
                  RenderUsage::SYSTEM_AGENT,
                  RenderUsage::INTERRUPTION,
                  RenderUsage::COMMUNICATION,
              },
          .effects =
              {
                  {
                      .lib_name = "test_effects.so",
                      .effect_name = "add_1.0",
                      .instance_name = "",
                      .effect_config = "",
                  },
              },
          .loopback = true,
          .output_rate = 48000,
          .output_channels = 2,
      }},
      .loopback = false,
      .output_rate = 96000,
      .output_channels = 2,
  };
  auto pipeline_config = PipelineConfig(root);
  auto volume_curve = VolumeCurve::DefaultForMinGain(VolumeCurve::kDefaultGainForMinVolume);
  auto pipeline = std::make_shared<OutputPipelineImpl>(pipeline_config, volume_curve, 128,
                                                       kDefaultTransform, device_clock_);
  auto buf = pipeline->ReadLock(zx::time(0), 0, 96);
  ASSERT_TRUE(buf);
  ASSERT_EQ(buf->start().Floor(), 0u);
  ASSERT_EQ(buf->length().Floor(), 96u);
  CheckBuffer(buf->payload(), 2.0, 192);
  auto transform = pipeline->loopback()->ReferenceClockToFixed();
  auto loopback_frame =
      Fixed::FromRaw(transform.timeline_function.Apply((zx::time(0)).get())).Floor();
  auto loopback_buf = pipeline->loopback()->ReadLock(zx::time(0) + zx::msec(1), loopback_frame, 48);
  ASSERT_TRUE(loopback_buf);
  ASSERT_EQ(loopback_buf->start().Floor(), 0u);
  ASSERT_EQ(loopback_buf->length().Floor(), 48u);
  CheckBuffer(loopback_buf->payload(), 1.0, 96);
}
TEST_F ( OutputPipelineTest , LoopbackWithUpsample ) { auto test_effects = testing :: TestEffectsModule :: Open ( ) ; test_effects . AddEffect ( " " ) . WithAction ( TEST_EFFECTS_ACTION_ADD , 1.0 ) ; PipelineConfig :: MixGroup root { . name = " " , . input_streams = { RenderUsage :: BACKGROUND , } , . effects = { { . lib_name = " " , . effect_name = " " , . instance_name = " " , . effect_config = " " , } , } , . inputs = { { . name = " " , . input_streams = { RenderUsage :: MEDIA , RenderUsage :: SYSTEM_AGENT , RenderUsage :: INTERRUPTION , RenderUsage :: COMMUNICATION , } , . effects = { { . lib_name = " " , . effect_name = " " , . instance_name = " " , . effect_config = " " , } , } , . loopback = true , . output_rate = 48000 , . output_channels = 2 , } } , . loopback = false , . output_rate = 96000 , . output_channels = 2 , } ; auto pipeline_config = PipelineConfig ( root ) ; auto volume_curve = VolumeCurve :: DefaultForMinGain ( VolumeCurve :: kDefaultGainForMinVolume ) ; auto pipeline = std :: make_shared < OutputPipelineImpl > ( pipeline_config , volume_curve , 128 , kDefaultTransform , device_clock_ ) ; auto buf = pipeline -> ReadLock ( zx :: time ( 0 ) , 0 , 96 ) ; ASSERT_TRUE ( buf ) ; ASSERT_EQ ( buf -> start ( ) . Floor ( ) , 0u ) ; ASSERT_EQ ( buf -> length ( ) . Floor ( ) , 96u ) ; CheckBuffer ( buf -> payload ( ) , 2.0 , 192 ) ; auto transform = pipeline -> loopback ( ) -> ReferenceClockToFixed ( ) ; auto loopback_frame = Fixed :: FromRaw ( transform . timeline_function . Apply ( ( zx :: time ( 0 ) ) . get ( ) ) ) . Floor ( ) ; auto loopback_buf = pipeline -> loopback ( ) -> ReadLock ( zx :: time ( 0 ) + zx :: msec ( 1 ) , loopback_frame , 48 ) ; ASSERT_TRUE ( loopback_buf ) ; ASSERT_EQ ( loopback_buf -> start ( ) . Floor ( ) , 0u ) ; ASSERT_EQ ( loopback_buf -> length ( ) . Floor ( ) , 48u ) ; CheckBuffer ( loopback_buf -> payload ( ) , 1.0 , 96 ) ; }
Identical to |Loopback|, except we run mix and linearize stages at different rates.
Identical to |Loopback| except we run mix and linearize stages at different rates .
// Verify our stream from the pipeline has the effects applied (we have no input streams so we // should have silence with a two effects that adds 1.0 to each sample (one on the mix stage // and one on the linearize stage). Therefore we expect all samples to be 2.0. // We loopback after the mix stage and before the linearize stage. So we should observe only a // single effects pass. Therefore we expect all loopback samples to be 1.0.