1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.audio.cts; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertNotNull; 21 import static org.junit.Assert.assertTrue; 22 23 import android.content.Context; 24 import android.media.AudioManager; 25 import android.media.audiofx.DynamicsProcessing; 26 import android.media.audiofx.DynamicsProcessing.BandBase; 27 import android.media.audiofx.DynamicsProcessing.BandStage; 28 import android.media.audiofx.DynamicsProcessing.Channel; 29 import android.media.audiofx.DynamicsProcessing.Eq; 30 import android.media.audiofx.DynamicsProcessing.EqBand; 31 import android.media.audiofx.DynamicsProcessing.Limiter; 32 import android.media.audiofx.DynamicsProcessing.Mbc; 33 import android.media.audiofx.DynamicsProcessing.MbcBand; 34 import android.platform.test.annotations.AppModeFull; 35 import android.platform.test.annotations.AppModeSdkSandbox; 36 import android.util.Log; 37 38 import androidx.test.runner.AndroidJUnit4; 39 40 import org.junit.Test; 41 import org.junit.runner.RunWith; 42 43 @AppModeSdkSandbox(reason = "Allow test in the SDK sandbox (does not prevent other modes).") 44 @RunWith(AndroidJUnit4.class) 45 public class DynamicsProcessingTest extends PostProcTestBase { 46 47 private static final String TAG = "DynamicsProcessingTest"; 48 private DynamicsProcessing mDP; 49 50 private static final int MIN_CHANNEL_COUNT = 1; 51 private static final float EPSILON = 0.00001f; 52 private static final int DEFAULT_VARIANT = 53 DynamicsProcessing.VARIANT_FAVOR_FREQUENCY_RESOLUTION; 54 private static final boolean DEFAULT_PREEQ_IN_USE = true; 55 private static final int DEFAULT_PREEQ_BAND_COUNT = 2; 56 private static final boolean DEFAULT_MBC_IN_USE = true; 57 private static final int DEFAULT_MBC_BAND_COUNT = 2; 58 private static final boolean DEFAULT_POSTEQ_IN_USE = true; 59 private static final int DEFAULT_POSTEQ_BAND_COUNT = 2; 60 private static final boolean DEFAULT_LIMITER_IN_USE = true; 61 private static final float DEFAULT_FRAME_DURATION = 9.5f; 62 private static final float DEFAULT_INPUT_GAIN = -12.5f; 63 64 private static final int TEST_CHANNEL_COUNT = 2; 65 private static final float TEST_GAIN1 = 12.1f; 66 private static final float TEST_GAIN2 = -2.8f; 67 private static final int TEST_CHANNEL_INDEX = 0; 68 private static final int TEST_BAND_INDEX = 0; 69 70 // ----------------------------------------------------------------- 71 // DynamicsProcessing tests: 72 // ---------------------------------- 73 74 // ----------------------------------------------------------------- 75 // 0 - constructors 76 // ---------------------------------- 77 78 // Test case 0.0: test constructor and release 79 @AppModeFull(reason = "Fails for instant but not enough to block the release") 80 @Test test0_0ConstructorAndRelease()81 public void test0_0ConstructorAndRelease() throws Exception { 82 if (!hasAudioOutput()) { 83 return; 84 } 85 try { 86 AudioManager am = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); 87 assertNotNull("null AudioManager", am); 88 createDynamicsProcessing(AudioManager.AUDIO_SESSION_ID_GENERATE); 89 releaseDynamicsProcessing(); 90 91 final int session = am.generateAudioSessionId(); 92 assertTrue("cannot generate new session", session != AudioManager.ERROR); 93 createDynamicsProcessing(session); 94 } finally { 95 releaseDynamicsProcessing(); 96 } 97 } 98 99 @Test test0_1ConstructorWithConfigAndRelease()100 public void test0_1ConstructorWithConfigAndRelease() throws Exception { 101 if (!hasAudioOutput()) { 102 return; 103 } 104 try { 105 createDefaultEffect(); 106 } finally { 107 releaseDynamicsProcessing(); 108 } 109 } 110 111 // ----------------------------------------------------------------- 112 // 1 - create with parameters 113 // ---------------------------------- 114 115 @Test test1_0ParametersEngine()116 public void test1_0ParametersEngine() throws Exception { 117 if (!hasAudioOutput()) { 118 return; 119 } 120 try { 121 createDefaultEffect(); 122 123 // Check Parameters: 124 DynamicsProcessing.Config engineConfig = mDP.getConfig(); 125 final float preferredFrameDuration = engineConfig.getPreferredFrameDuration(); 126 assertEquals("preferredFrameDuration is different", DEFAULT_FRAME_DURATION, 127 preferredFrameDuration, EPSILON); 128 129 final int preEqBandCount = engineConfig.getPreEqBandCount(); 130 assertEquals("preEqBandCount is different", DEFAULT_PREEQ_BAND_COUNT, preEqBandCount); 131 132 final int mbcBandCount = engineConfig.getMbcBandCount(); 133 assertEquals("mbcBandCount is different", DEFAULT_MBC_BAND_COUNT, mbcBandCount); 134 135 final int postEqBandCount = engineConfig.getPostEqBandCount(); 136 assertEquals("postEqBandCount is different", DEFAULT_POSTEQ_BAND_COUNT, 137 postEqBandCount); 138 } finally { 139 releaseDynamicsProcessing(); 140 } 141 } 142 143 @Test test1_1ParametersChannel()144 public void test1_1ParametersChannel() throws Exception { 145 if (!hasAudioOutput()) { 146 return; 147 } 148 try { 149 createDefaultEffect(); 150 151 // Check Parameters: 152 final int channelCount = mDP.getChannelCount(); 153 assertTrue("unexpected channel count", channelCount >= MIN_CHANNEL_COUNT); 154 155 Channel channel = mDP.getChannelByChannelIndex(TEST_CHANNEL_INDEX); 156 157 final float inputGain = channel.getInputGain(); 158 assertEquals("inputGain is different", DEFAULT_INPUT_GAIN, inputGain, EPSILON); 159 } finally { 160 releaseDynamicsProcessing(); 161 } 162 } 163 164 @Test test1_2ParametersPreEq()165 public void test1_2ParametersPreEq() throws Exception { 166 if (!hasAudioOutput()) { 167 return; 168 } 169 try { 170 createDefaultEffect(); 171 172 DynamicsProcessing.Eq eq = mDP.getPreEqByChannelIndex(TEST_CHANNEL_INDEX); 173 174 final boolean inUse = eq.isInUse(); 175 assertEquals("inUse is different", DEFAULT_PREEQ_IN_USE, inUse); 176 177 final int bandCount = eq.getBandCount(); 178 assertEquals("band count is different", DEFAULT_PREEQ_BAND_COUNT, bandCount); 179 releaseDynamicsProcessing(); 180 } finally { 181 releaseDynamicsProcessing(); 182 } 183 } 184 185 @Test test1_3ParametersMbc()186 public void test1_3ParametersMbc() throws Exception { 187 if (!hasAudioOutput()) { 188 return; 189 } 190 try { 191 createDefaultEffect(); 192 193 DynamicsProcessing.Mbc mbc = mDP.getMbcByChannelIndex(TEST_CHANNEL_INDEX); 194 195 final boolean inUse = mbc.isInUse(); 196 assertEquals("inUse is different", DEFAULT_MBC_IN_USE, inUse); 197 198 final int bandCount = mbc.getBandCount(); 199 assertEquals("band count is different", DEFAULT_MBC_BAND_COUNT, bandCount); 200 } finally { 201 releaseDynamicsProcessing(); 202 } 203 } 204 205 @Test test1_4ParametersPostEq()206 public void test1_4ParametersPostEq() throws Exception { 207 if (!hasAudioOutput()) { 208 return; 209 } 210 try { 211 createDefaultEffect(); 212 213 DynamicsProcessing.Eq eq = mDP.getPostEqByChannelIndex(TEST_CHANNEL_INDEX); 214 215 boolean inUse = eq.isInUse(); 216 assertEquals("inUse is different", DEFAULT_POSTEQ_IN_USE, inUse); 217 218 int bandCount = eq.getBandCount(); 219 assertEquals("band count is different", DEFAULT_POSTEQ_BAND_COUNT, bandCount); 220 } finally { 221 releaseDynamicsProcessing(); 222 } 223 } 224 225 @Test test1_5ParametersLimiter()226 public void test1_5ParametersLimiter() throws Exception { 227 if (!hasAudioOutput()) { 228 return; 229 } 230 231 try { 232 createDefaultEffect(); 233 234 DynamicsProcessing.Limiter limiter = mDP.getLimiterByChannelIndex(TEST_CHANNEL_INDEX); 235 236 final boolean inUse = limiter.isInUse(); 237 assertEquals("inUse is different", DEFAULT_LIMITER_IN_USE, inUse); 238 } finally { 239 releaseDynamicsProcessing(); 240 } 241 } 242 243 @Test test1_6Channel_perStage()244 public void test1_6Channel_perStage() throws Exception { 245 if (!hasAudioOutput()) { 246 return; 247 } 248 249 try { 250 createDefaultEffect(); 251 252 Channel channel = mDP.getChannelByChannelIndex(TEST_CHANNEL_INDEX); 253 254 // Per Stage 255 mDP.setInputGainAllChannelsTo(TEST_GAIN1); 256 257 Eq preEq = mDP.getPreEqByChannelIndex(TEST_CHANNEL_INDEX); 258 EqBand preEqBand = preEq.getBand(TEST_BAND_INDEX); 259 preEqBand.setGain(TEST_GAIN1); 260 preEq.setBand(TEST_BAND_INDEX, preEqBand); 261 mDP.setPreEqAllChannelsTo(preEq); 262 263 Mbc mbc = mDP.getMbcByChannelIndex(TEST_CHANNEL_INDEX); 264 MbcBand mbcBand = mbc.getBand(TEST_BAND_INDEX); 265 mbcBand.setPreGain(TEST_GAIN1); 266 mbc.setBand(TEST_BAND_INDEX, mbcBand); 267 mDP.setMbcAllChannelsTo(mbc); 268 269 Eq postEq = mDP.getPostEqByChannelIndex(TEST_CHANNEL_INDEX); 270 EqBand postEqBand = postEq.getBand(TEST_BAND_INDEX); 271 postEqBand.setGain(TEST_GAIN1); 272 postEq.setBand(TEST_BAND_INDEX, postEqBand); 273 mDP.setPostEqAllChannelsTo(postEq); 274 275 Limiter limiter = mDP.getLimiterByChannelIndex(TEST_CHANNEL_INDEX); 276 limiter.setPostGain(TEST_GAIN1); 277 mDP.setLimiterAllChannelsTo(limiter); 278 279 int channelCount = mDP.getChannelCount(); 280 for (int i = 0; i < channelCount; i++) { 281 Channel channelTest = mDP.getChannelByChannelIndex(i); 282 assertEquals("inputGain is different in channel " + i, TEST_GAIN1, 283 channelTest.getInputGain(), EPSILON); 284 285 Eq preEqTest = new Eq(mDP.getPreEqByChannelIndex(i)); 286 EqBand preEqBandTest = preEqTest.getBand(TEST_BAND_INDEX); 287 assertEquals("preEQBand gain is different in channel " + i + " band " + 288 TEST_BAND_INDEX, TEST_GAIN1, preEqBandTest.getGain(), EPSILON); 289 290 Mbc mbcTest = new Mbc(mDP.getMbcByChannelIndex(i)); 291 MbcBand mbcBandTest = mbcTest.getBand(TEST_BAND_INDEX); 292 assertEquals("mbcBand preGain is different in channel " + i + " band " + 293 TEST_BAND_INDEX, TEST_GAIN1, mbcBandTest.getPreGain(), EPSILON); 294 295 Eq postEqTest = new Eq(mDP.getPostEqByChannelIndex(i)); 296 EqBand postEqBandTest = postEqTest.getBand(TEST_BAND_INDEX); 297 assertEquals("postEQBand gain is different in channel " + i + " band " + 298 TEST_BAND_INDEX, TEST_GAIN1, postEqBandTest.getGain(), EPSILON); 299 300 Limiter limiterTest = new Limiter(mDP.getLimiterByChannelIndex(i)); 301 assertEquals("limiter gain is different in channel " + i, 302 TEST_GAIN1, limiterTest.getPostGain(), EPSILON); 303 304 // change by Stage 305 mDP.setInputGainbyChannel(i, TEST_GAIN2); 306 assertEquals("inputGain is different in channel " + i, TEST_GAIN2, 307 mDP.getInputGainByChannelIndex(i), EPSILON); 308 309 preEqBandTest.setGain(TEST_GAIN2); 310 preEqTest.setBand(TEST_BAND_INDEX, preEqBandTest); 311 mDP.setPreEqByChannelIndex(i, preEqTest); 312 assertEquals("preEQBand gain is different in channel " + i + " band " + 313 TEST_BAND_INDEX, TEST_GAIN2, 314 mDP.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), EPSILON); 315 316 mbcBandTest.setPreGain(TEST_GAIN2); 317 mbcTest.setBand(TEST_BAND_INDEX, mbcBandTest); 318 mDP.setMbcByChannelIndex(i, mbcTest); 319 assertEquals("mbcBand preGain is different in channel " + i + " band " + 320 TEST_BAND_INDEX, TEST_GAIN2, 321 mDP.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), EPSILON); 322 323 postEqBandTest.setGain(TEST_GAIN2); 324 postEqTest.setBand(TEST_BAND_INDEX, postEqBandTest); 325 mDP.setPostEqByChannelIndex(i, postEqTest); 326 assertEquals("postEQBand gain is different in channel " + i + " band " + 327 TEST_BAND_INDEX, TEST_GAIN2, 328 mDP.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), EPSILON); 329 330 limiterTest.setPostGain(TEST_GAIN2); 331 mDP.setLimiterByChannelIndex(i, limiterTest); 332 assertEquals("limiter gain is different in channel " + i, 333 TEST_GAIN2, mDP.getLimiterByChannelIndex(i).getPostGain(), EPSILON); 334 } 335 } finally { 336 releaseDynamicsProcessing(); 337 } 338 339 } 340 341 @Test test1_7Channel_perBand()342 public void test1_7Channel_perBand() throws Exception { 343 if (!hasAudioOutput()) { 344 return; 345 } 346 try { 347 createDefaultEffect(); 348 349 Channel channel = mDP.getChannelByChannelIndex(TEST_CHANNEL_INDEX); 350 351 // Per Band 352 EqBand preEqBand = mDP.getPreEqBandByChannelIndex(TEST_CHANNEL_INDEX, TEST_BAND_INDEX); 353 preEqBand.setGain(TEST_GAIN1); 354 mDP.setPreEqBandAllChannelsTo(TEST_BAND_INDEX, preEqBand); 355 356 MbcBand mbcBand = mDP.getMbcBandByChannelIndex(TEST_CHANNEL_INDEX, TEST_BAND_INDEX); 357 mbcBand.setPreGain(TEST_GAIN1); 358 mDP.setMbcBandAllChannelsTo(TEST_BAND_INDEX, mbcBand); 359 360 EqBand postEqBand = mDP.getPostEqBandByChannelIndex(TEST_CHANNEL_INDEX, 361 TEST_BAND_INDEX); 362 postEqBand.setGain(TEST_GAIN1); 363 mDP.setPostEqBandAllChannelsTo(TEST_BAND_INDEX, postEqBand); 364 365 int channelCount = mDP.getChannelCount(); 366 367 for (int i = 0; i < channelCount; i++) { 368 369 EqBand preEqBandTest = new EqBand(mDP.getPreEqBandByChannelIndex(i, 370 TEST_BAND_INDEX)); 371 assertEquals("preEQBand gain is different in channel " + i + " band " + 372 TEST_BAND_INDEX, TEST_GAIN1, preEqBandTest.getGain(), EPSILON); 373 374 MbcBand mbcBandTest = new MbcBand(mDP.getMbcBandByChannelIndex(i, TEST_BAND_INDEX)); 375 assertEquals("mbcBand preGain is different in channel " + i + " band " + 376 TEST_BAND_INDEX, TEST_GAIN1, mbcBandTest.getPreGain(), EPSILON); 377 378 EqBand postEqBandTest = new EqBand(mDP.getPostEqBandByChannelIndex(i, 379 TEST_BAND_INDEX)); 380 assertEquals("postEQBand gain is different in channel " + i + " band " + 381 TEST_BAND_INDEX, TEST_GAIN1, postEqBandTest.getGain(), EPSILON); 382 383 // change per Band 384 preEqBandTest.setGain(TEST_GAIN2); 385 mDP.setPreEqBandByChannelIndex(i, TEST_BAND_INDEX, preEqBandTest); 386 assertEquals("preEQBand gain is different in channel " + i + " band " + 387 TEST_BAND_INDEX, TEST_GAIN2, 388 mDP.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), EPSILON); 389 390 mbcBandTest.setPreGain(TEST_GAIN2); 391 mDP.setMbcBandByChannelIndex(i, TEST_BAND_INDEX, mbcBandTest); 392 assertEquals("mbcBand preGain is different in channel " + i + " band " + 393 TEST_BAND_INDEX, TEST_GAIN2, 394 mDP.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), 395 EPSILON); 396 397 postEqBandTest.setGain(TEST_GAIN2); 398 mDP.setPostEqBandByChannelIndex(i, TEST_BAND_INDEX, postEqBandTest); 399 assertEquals("postEQBand gain is different in channel " + i + " band " + 400 TEST_BAND_INDEX, TEST_GAIN2, 401 mDP.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 402 EPSILON); 403 } 404 405 } finally { 406 releaseDynamicsProcessing(); 407 } 408 } 409 410 @Test test1_8Channel_setAllChannelsTo()411 public void test1_8Channel_setAllChannelsTo() throws Exception { 412 if (!hasAudioOutput()) { 413 return; 414 } 415 try { 416 createDefaultEffect(); 417 418 Channel channel = mDP.getChannelByChannelIndex(TEST_CHANNEL_INDEX); 419 // get Stages, apply all channels 420 Eq preEq = new Eq(mDP.getPreEqByChannelIndex(TEST_CHANNEL_INDEX)); 421 EqBand preEqBand = new EqBand(preEq.getBand(TEST_BAND_INDEX)); 422 preEqBand.setGain(TEST_GAIN1); 423 preEq.setBand(TEST_BAND_INDEX, preEqBand); 424 channel.setPreEq(preEq); 425 426 Mbc mbc = new Mbc(mDP.getMbcByChannelIndex(TEST_CHANNEL_INDEX)); 427 MbcBand mbcBand = new MbcBand(mbc.getBand(TEST_BAND_INDEX)); 428 mbcBand.setPreGain(TEST_GAIN1); 429 mbc.setBand(TEST_BAND_INDEX, mbcBand); 430 channel.setMbc(mbc); 431 432 Eq postEq = new Eq(mDP.getPostEqByChannelIndex(TEST_CHANNEL_INDEX)); 433 EqBand postEqBand = new EqBand(postEq.getBand(TEST_BAND_INDEX)); 434 postEqBand.setGain(TEST_GAIN1); 435 postEq.setBand(TEST_BAND_INDEX, postEqBand); 436 channel.setPostEq(postEq); 437 438 Limiter limiter = new Limiter(mDP.getLimiterByChannelIndex(TEST_CHANNEL_INDEX)); 439 limiter.setPostGain(TEST_GAIN1); 440 channel.setLimiter(limiter); 441 442 mDP.setAllChannelsTo(channel); 443 444 int channelCount = mDP.getChannelCount(); 445 for (int i = 0; i < channelCount; i++) { 446 assertEquals("preEQBand gain is different in channel " + i + " band " + 447 TEST_BAND_INDEX, TEST_GAIN1, 448 mDP.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), EPSILON); 449 450 assertEquals("mbcBand preGain is different in channel " + i + " band " + 451 TEST_BAND_INDEX, TEST_GAIN1, 452 mDP.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), EPSILON); 453 454 assertEquals("postEQBand gain is different in channel " + i + " band " + 455 TEST_BAND_INDEX, TEST_GAIN1, 456 mDP.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), EPSILON); 457 458 assertEquals("limiter gain is different in channel " + i, 459 TEST_GAIN1, mDP.getLimiterByChannelIndex(i).getPostGain(), EPSILON); 460 } 461 462 } finally { 463 releaseDynamicsProcessing(); 464 } 465 } 466 467 @Test test1_9Channel_setChannelTo()468 public void test1_9Channel_setChannelTo() throws Exception { 469 if (!hasAudioOutput()) { 470 return; 471 } 472 try { 473 createDefaultEffect(); 474 475 Channel channel = mDP.getChannelByChannelIndex(TEST_CHANNEL_INDEX); 476 477 Eq preEq = new Eq(mDP.getPreEqByChannelIndex(TEST_CHANNEL_INDEX)); 478 EqBand preEqBand = new EqBand(preEq.getBand(TEST_BAND_INDEX)); 479 480 Mbc mbc = new Mbc(mDP.getMbcByChannelIndex(TEST_CHANNEL_INDEX)); 481 MbcBand mbcBand = new MbcBand(mbc.getBand(TEST_BAND_INDEX)); 482 483 Eq postEq = new Eq(mDP.getPostEqByChannelIndex(TEST_CHANNEL_INDEX)); 484 EqBand postEqBand = new EqBand(postEq.getBand(TEST_BAND_INDEX)); 485 486 Limiter limiter = new Limiter(mDP.getLimiterByChannelIndex(TEST_CHANNEL_INDEX)); 487 488 // get Stages, apply per channel 489 int channelCount = mDP.getChannelCount(); 490 for (int i = 0; i < channelCount; i++) { 491 float gain = i % 2 == 0 ? TEST_GAIN1 : TEST_GAIN2; 492 493 preEqBand.setGain(gain); 494 preEq.setBand(TEST_BAND_INDEX, preEqBand); 495 channel.setPreEq(preEq); 496 497 mbcBand.setPreGain(gain); 498 mbc.setBand(TEST_BAND_INDEX, mbcBand); 499 channel.setMbc(mbc); 500 501 postEqBand.setGain(gain); 502 postEq.setBand(TEST_BAND_INDEX, postEqBand); 503 channel.setPostEq(postEq); 504 505 limiter.setPostGain(gain); 506 channel.setLimiter(limiter); 507 508 mDP.setChannelTo(i, channel); 509 } 510 511 for (int i = 0; i < channelCount; i++) { 512 float expectedGain = i % 2 == 0 ? TEST_GAIN1 : TEST_GAIN2; 513 assertEquals("preEQBand gain is different in channel " + i + " band " + 514 TEST_BAND_INDEX, expectedGain, 515 mDP.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 516 EPSILON); 517 518 assertEquals("mbcBand preGain is different in channel " + i + " band " + 519 TEST_BAND_INDEX, expectedGain, 520 mDP.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), 521 EPSILON); 522 523 assertEquals("postEQBand gain is different in channel " + i + " band " + 524 TEST_BAND_INDEX, expectedGain, 525 mDP.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 526 EPSILON); 527 528 assertEquals("limiter gain is different in channel " + i, 529 expectedGain, mDP.getLimiterByChannelIndex(i).getPostGain(), EPSILON); 530 } 531 532 } finally { 533 releaseDynamicsProcessing(); 534 } 535 } 536 537 // ----------------------------------------------------------------- 538 // 2 - config builder tests 539 // ---------------------------------- 540 541 @Test test2_0ConfigBasic()542 public void test2_0ConfigBasic() throws Exception { 543 if (!hasAudioOutput()) { 544 return; 545 } 546 DynamicsProcessing.Config config = getBuilderWithValues().build(); 547 548 assertEquals("getVariant is different", DEFAULT_VARIANT, 549 config.getVariant()); 550 assertEquals("isPreEqInUse is different", DEFAULT_PREEQ_IN_USE, 551 config.isPreEqInUse()); 552 assertEquals("getPreEqBandCount is different", DEFAULT_PREEQ_BAND_COUNT, 553 config.getPreEqBandCount()); 554 assertEquals("isMbcInUse is different", DEFAULT_MBC_IN_USE, 555 config.isMbcInUse()); 556 assertEquals("getMbcBandCount is different", DEFAULT_MBC_BAND_COUNT, 557 config.getMbcBandCount()); 558 assertEquals("isPostEqInUse is different", DEFAULT_POSTEQ_IN_USE, 559 config.isPostEqInUse()); 560 assertEquals("getPostEqBandCount is different", DEFAULT_POSTEQ_BAND_COUNT, 561 config.getPostEqBandCount()); 562 assertEquals("isLimiterInUse is different", DEFAULT_LIMITER_IN_USE, 563 config.isLimiterInUse()); 564 assertEquals("getPreferredFrameDuration is different", DEFAULT_FRAME_DURATION, 565 config.getPreferredFrameDuration(), EPSILON); 566 } 567 568 @Test test2_1ConfigChannel()569 public void test2_1ConfigChannel() throws Exception { 570 if (!hasAudioOutput()) { 571 return; 572 } 573 DynamicsProcessing.Config config = getBuilderWithValues(TEST_CHANNEL_COUNT).build(); 574 575 // per channel 576 Channel channel = config.getChannelByChannelIndex(TEST_CHANNEL_INDEX); 577 // change some parameters 578 channel.setInputGain(TEST_GAIN1); 579 580 // get stages from channel 581 Eq preEq = channel.getPreEq(); 582 EqBand preEqBand = preEq.getBand(TEST_BAND_INDEX); 583 preEqBand.setGain(TEST_GAIN1); 584 channel.setPreEqBand(TEST_BAND_INDEX, preEqBand); 585 586 Mbc mbc = channel.getMbc(); 587 MbcBand mbcBand = mbc.getBand(TEST_BAND_INDEX); 588 mbcBand.setPreGain(TEST_GAIN1); 589 channel.setMbcBand(TEST_BAND_INDEX, mbcBand); 590 591 Eq postEq = channel.getPostEq(); 592 EqBand postEqBand = postEq.getBand(TEST_BAND_INDEX); 593 postEqBand.setGain(TEST_GAIN1); 594 channel.setPostEqBand(TEST_BAND_INDEX, postEqBand); 595 596 Limiter limiter = channel.getLimiter(); 597 limiter.setPostGain(TEST_GAIN1); 598 channel.setLimiter(limiter); 599 600 config.setAllChannelsTo(channel); 601 for (int i = 0; i < TEST_CHANNEL_COUNT; i++) { 602 Channel channelTest = new Channel(config.getChannelByChannelIndex(i)); 603 assertEquals("inputGain is different in channel " + i, TEST_GAIN1, 604 channelTest.getInputGain(), EPSILON); 605 606 EqBand preEqBandTest = new EqBand(channelTest.getPreEqBand(TEST_BAND_INDEX)); 607 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 608 TEST_GAIN1, preEqBandTest.getGain(), EPSILON); 609 610 MbcBand mbcBandTest = new MbcBand(channelTest.getMbcBand(TEST_BAND_INDEX)); 611 assertEquals("mbcBand preGain is different in channel " + i + " band " + 612 TEST_BAND_INDEX, TEST_GAIN1, mbcBandTest.getPreGain(), EPSILON); 613 614 EqBand postEqBandTest = new EqBand(channelTest.getPostEqBand(TEST_BAND_INDEX)); 615 assertEquals("postEQBand gain is different in channel " + i + " band " + 616 TEST_BAND_INDEX, TEST_GAIN1, postEqBandTest.getGain(), EPSILON); 617 618 Limiter limiterTest = new Limiter(channelTest.getLimiter()); 619 assertEquals("limiter gain is different in channel " + i, 620 TEST_GAIN1, limiterTest.getPostGain(), EPSILON); 621 622 /// changes per channelIndex 623 channelTest.setInputGain(TEST_GAIN2); 624 preEqBandTest.setGain(TEST_GAIN2); 625 channelTest.setPreEqBand(TEST_BAND_INDEX, preEqBandTest); 626 mbcBandTest.setPreGain(TEST_GAIN2); 627 channelTest.setMbcBand(TEST_BAND_INDEX, mbcBandTest); 628 postEqBandTest.setGain(TEST_GAIN2); 629 channelTest.setPostEqBand(TEST_BAND_INDEX, postEqBandTest); 630 limiterTest.setPostGain(TEST_GAIN2); 631 channelTest.setLimiter(limiterTest); 632 config.setChannelTo(i, channelTest); 633 634 assertEquals("inputGain is different in channel " + i, TEST_GAIN2, 635 config.getInputGainByChannelIndex(i), EPSILON); 636 637 // get by module 638 Eq preEqTest = config.getPreEqByChannelIndex(i); 639 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 640 TEST_GAIN2, preEqTest.getBand(TEST_BAND_INDEX).getGain(), EPSILON); 641 642 Mbc mbcTest = config.getMbcByChannelIndex(i); 643 assertEquals("mbcBand preGain is different in channel " + i + " band " + 644 TEST_BAND_INDEX, TEST_GAIN2, mbcTest.getBand(TEST_BAND_INDEX).getPreGain(), 645 EPSILON); 646 647 Eq postEqTest = config.getPostEqByChannelIndex(i); 648 assertEquals("postEQBand gain is different in channel " + i + " band " + 649 TEST_BAND_INDEX, TEST_GAIN2, postEqTest.getBand(TEST_BAND_INDEX).getGain(), 650 EPSILON); 651 652 limiterTest = config.getLimiterByChannelIndex(i); 653 assertEquals("limiter gain is different in channel " + i, 654 TEST_GAIN2, limiterTest.getPostGain(), EPSILON); 655 } 656 } 657 658 @Test test2_2ConfigChannel_perStage()659 public void test2_2ConfigChannel_perStage() throws Exception { 660 if (!hasAudioOutput()) { 661 return; 662 } 663 664 DynamicsProcessing.Config config = getBuilderWithValues(TEST_CHANNEL_COUNT).build(); 665 666 // Per Stage 667 config.setInputGainAllChannelsTo(TEST_GAIN1); 668 669 Eq preEq = config.getPreEqByChannelIndex(TEST_CHANNEL_INDEX); 670 EqBand preEqBand = preEq.getBand(TEST_BAND_INDEX); 671 preEqBand.setGain(TEST_GAIN1); 672 preEq.setBand(TEST_BAND_INDEX, preEqBand); 673 config.setPreEqAllChannelsTo(preEq); 674 675 Mbc mbc = config.getMbcByChannelIndex(TEST_CHANNEL_INDEX); 676 MbcBand mbcBand = mbc.getBand(TEST_BAND_INDEX); 677 mbcBand.setPreGain(TEST_GAIN1); 678 mbc.setBand(TEST_BAND_INDEX, mbcBand); 679 config.setMbcAllChannelsTo(mbc); 680 681 Eq postEq = config.getPostEqByChannelIndex(TEST_CHANNEL_INDEX); 682 EqBand postEqBand = postEq.getBand(TEST_BAND_INDEX); 683 postEqBand.setGain(TEST_GAIN1); 684 postEq.setBand(TEST_BAND_INDEX, postEqBand); 685 config.setPostEqAllChannelsTo(postEq); 686 687 Limiter limiter = config.getLimiterByChannelIndex(TEST_CHANNEL_INDEX); 688 limiter.setPostGain(TEST_GAIN1); 689 config.setLimiterAllChannelsTo(limiter); 690 691 for (int i = 0; i < TEST_CHANNEL_COUNT; i++) { 692 Channel channelTest = config.getChannelByChannelIndex(i); 693 assertEquals("inputGain is different in channel " + i, TEST_GAIN1, 694 channelTest.getInputGain(), EPSILON); 695 696 Eq preEqTest = new Eq(config.getPreEqByChannelIndex(i)); 697 EqBand preEqBandTest = preEqTest.getBand(TEST_BAND_INDEX); 698 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 699 TEST_GAIN1, preEqBandTest.getGain(), EPSILON); 700 701 Mbc mbcTest = new Mbc(config.getMbcByChannelIndex(i)); 702 MbcBand mbcBandTest = mbcTest.getBand(TEST_BAND_INDEX); 703 assertEquals("mbcBand preGain is different in channel " + i + " band " + 704 TEST_BAND_INDEX, TEST_GAIN1, mbcBandTest.getPreGain(), EPSILON); 705 706 Eq postEqTest = new Eq(config.getPostEqByChannelIndex(i)); 707 EqBand postEqBandTest = postEqTest.getBand(TEST_BAND_INDEX); 708 assertEquals("postEQBand gain is different in channel " + i + " band " + 709 TEST_BAND_INDEX, TEST_GAIN1, postEqBandTest.getGain(), EPSILON); 710 711 Limiter limiterTest = new Limiter(config.getLimiterByChannelIndex(i)); 712 assertEquals("limiter gain is different in channel " + i, 713 TEST_GAIN1, limiterTest.getPostGain(), EPSILON); 714 715 // change by Stage 716 config.setInputGainByChannelIndex(i, TEST_GAIN2); 717 assertEquals("inputGain is different in channel " + i, TEST_GAIN2, 718 config.getInputGainByChannelIndex(i), EPSILON); 719 720 preEqBandTest.setGain(TEST_GAIN2); 721 preEqTest.setBand(TEST_BAND_INDEX, preEqBandTest); 722 config.setPreEqByChannelIndex(i, preEqTest); 723 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 724 TEST_GAIN2, config.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 725 EPSILON); 726 727 mbcBandTest.setPreGain(TEST_GAIN2); 728 mbcTest.setBand(TEST_BAND_INDEX, mbcBandTest); 729 config.setMbcByChannelIndex(i, mbcTest); 730 assertEquals("mbcBand preGain is different in channel " + i + " band " + 731 TEST_BAND_INDEX, TEST_GAIN2, 732 config.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), EPSILON); 733 734 postEqBandTest.setGain(TEST_GAIN2); 735 postEqTest.setBand(TEST_BAND_INDEX, postEqBandTest); 736 config.setPostEqByChannelIndex(i, postEqTest); 737 assertEquals("postEQBand gain is different in channel " + i + " band " + 738 TEST_BAND_INDEX, TEST_GAIN2, 739 config.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), EPSILON); 740 741 limiterTest.setPostGain(TEST_GAIN2); 742 config.setLimiterByChannelIndex(i, limiterTest); 743 assertEquals("limiter gain is different in channel " + i, 744 TEST_GAIN2, config.getLimiterByChannelIndex(i).getPostGain(), EPSILON); 745 } 746 } 747 748 @Test test2_3ConfigChannel_perBand()749 public void test2_3ConfigChannel_perBand() throws Exception { 750 if (!hasAudioOutput()) { 751 return; 752 } 753 DynamicsProcessing.Config config = getBuilderWithValues(TEST_CHANNEL_COUNT).build(); 754 755 // Per Band 756 EqBand preEqBand = config.getPreEqBandByChannelIndex(TEST_CHANNEL_INDEX, TEST_BAND_INDEX); 757 preEqBand.setGain(TEST_GAIN1); 758 config.setPreEqBandAllChannelsTo(TEST_BAND_INDEX, preEqBand); 759 760 MbcBand mbcBand = config.getMbcBandByChannelIndex(TEST_CHANNEL_INDEX, TEST_BAND_INDEX); 761 mbcBand.setPreGain(TEST_GAIN1); 762 config.setMbcBandAllChannelsTo(TEST_BAND_INDEX, mbcBand); 763 764 EqBand postEqBand = config.getPostEqBandByChannelIndex(TEST_CHANNEL_INDEX, TEST_BAND_INDEX); 765 postEqBand.setGain(TEST_GAIN1); 766 config.setPostEqBandAllChannelsTo(TEST_BAND_INDEX, postEqBand); 767 768 for (int i = 0; i < TEST_CHANNEL_COUNT; i++) { 769 770 EqBand preEqBandTest = new EqBand(config.getPreEqBandByChannelIndex(i, 771 TEST_BAND_INDEX)); 772 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 773 TEST_GAIN1, preEqBandTest.getGain(), EPSILON); 774 775 MbcBand mbcBandTest = new MbcBand(config.getMbcBandByChannelIndex(i, TEST_BAND_INDEX)); 776 assertEquals("mbcBand preGain is different in channel " + i + " band " + 777 TEST_BAND_INDEX, TEST_GAIN1, mbcBandTest.getPreGain(), EPSILON); 778 779 EqBand postEqBandTest = new EqBand(config.getPostEqBandByChannelIndex(i, 780 TEST_BAND_INDEX)); 781 assertEquals("postEQBand gain is different in channel " + i + " band " + 782 TEST_BAND_INDEX, TEST_GAIN1, postEqBandTest.getGain(), EPSILON); 783 784 // change per Band 785 preEqBandTest.setGain(TEST_GAIN2); 786 config.setPreEqBandByChannelIndex(i, TEST_BAND_INDEX, preEqBandTest); 787 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 788 TEST_GAIN2, config.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 789 EPSILON); 790 791 mbcBandTest.setPreGain(TEST_GAIN2); 792 config.setMbcBandByChannelIndex(i, TEST_BAND_INDEX, mbcBandTest); 793 assertEquals("mbcBand preGain is different in channel " + i + " band " + 794 TEST_BAND_INDEX, TEST_GAIN2, 795 config.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), EPSILON); 796 797 postEqBandTest.setGain(TEST_GAIN2); 798 config.setPostEqBandByChannelIndex(i, TEST_BAND_INDEX, postEqBandTest); 799 assertEquals("postEQBand gain is different in channel " + i + " band " + 800 TEST_BAND_INDEX, TEST_GAIN2, 801 config.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), EPSILON); 802 } 803 } 804 805 @Test test2_4Channel_perStage()806 public void test2_4Channel_perStage() throws Exception { 807 if (!hasAudioOutput()) { 808 return; 809 } 810 DynamicsProcessing.Config config = getBuilderWithValues(MIN_CHANNEL_COUNT).build(); 811 812 Channel channel = new Channel(config.getChannelByChannelIndex(TEST_CHANNEL_INDEX)); 813 814 channel.setInputGain(TEST_GAIN1); 815 assertEquals("channel gain is different", TEST_GAIN1, channel.getInputGain(), EPSILON); 816 817 // set by stage 818 Eq preEq = new Eq(channel.getPreEq()); 819 EqBand preEqBand = new EqBand(preEq.getBand(TEST_BAND_INDEX)); 820 preEqBand.setGain(TEST_GAIN1); 821 preEq.setBand(TEST_BAND_INDEX, preEqBand); 822 channel.setPreEq(preEq); 823 assertEquals("preEQBand gain is different in band " + TEST_BAND_INDEX, 824 TEST_GAIN1, channel.getPreEq().getBand(TEST_BAND_INDEX).getGain(), EPSILON); 825 preEqBand.setGain(TEST_GAIN2); 826 preEq.setBand(TEST_BAND_INDEX, preEqBand); 827 channel.setPreEq(preEq); 828 assertEquals("preEQBand gain is different in band " + TEST_BAND_INDEX, 829 TEST_GAIN2, channel.getPreEq().getBand(TEST_BAND_INDEX).getGain(), EPSILON); 830 831 Mbc mbc = new Mbc(channel.getMbc()); 832 MbcBand mbcBand = new MbcBand(mbc.getBand(TEST_BAND_INDEX)); 833 mbcBand.setPreGain(TEST_GAIN1); 834 mbc.setBand(TEST_BAND_INDEX, mbcBand); 835 channel.setMbc(mbc); 836 assertEquals("mbcBand preGain is different in band " + TEST_BAND_INDEX, 837 TEST_GAIN1, channel.getMbc().getBand(TEST_BAND_INDEX).getPreGain(), EPSILON); 838 mbcBand.setPreGain(TEST_GAIN2); 839 mbc.setBand(TEST_BAND_INDEX, mbcBand); 840 channel.setMbc(mbc); 841 assertEquals("mbcBand preGain is different in band " + TEST_BAND_INDEX, 842 TEST_GAIN2, channel.getMbc().getBand(TEST_BAND_INDEX).getPreGain(), EPSILON); 843 844 Eq postEq = new Eq(channel.getPostEq()); 845 EqBand postEqBand = new EqBand(postEq.getBand(TEST_BAND_INDEX)); 846 postEqBand.setGain(TEST_GAIN1); 847 postEq.setBand(TEST_BAND_INDEX, postEqBand); 848 channel.setPostEq(postEq); 849 assertEquals("postEqBand gain is different in band " + TEST_BAND_INDEX, 850 TEST_GAIN1, channel.getPostEq().getBand(TEST_BAND_INDEX).getGain(), EPSILON); 851 postEqBand.setGain(TEST_GAIN2); 852 postEq.setBand(TEST_BAND_INDEX, postEqBand); 853 channel.setPostEq(postEq); 854 assertEquals("postEQBand gain is different in band " + TEST_BAND_INDEX, 855 TEST_GAIN2, channel.getPostEq().getBand(TEST_BAND_INDEX).getGain(), EPSILON); 856 857 Limiter limiter = new Limiter(channel.getLimiter()); 858 limiter.setPostGain(TEST_GAIN1); 859 channel.setLimiter(limiter); 860 assertEquals("limiter gain is different", 861 TEST_GAIN1, channel.getLimiter().getPostGain(), EPSILON); 862 limiter.setPostGain(TEST_GAIN2); 863 channel.setLimiter(limiter); 864 assertEquals("limiter gain is different", 865 TEST_GAIN2, channel.getLimiter().getPostGain(), EPSILON); 866 867 } 868 869 @Test test2_5Channel_perBand()870 public void test2_5Channel_perBand() throws Exception { 871 if (!hasAudioOutput()) { 872 return; 873 } 874 DynamicsProcessing.Config config = getBuilderWithValues(MIN_CHANNEL_COUNT).build(); 875 876 Channel channel = new Channel(config.getChannelByChannelIndex(TEST_CHANNEL_INDEX)); 877 878 channel.setInputGain(TEST_GAIN1); 879 assertEquals("channel gain is different", TEST_GAIN1, channel.getInputGain(), EPSILON); 880 881 // set by band 882 EqBand preEqBand = new EqBand(channel.getPreEqBand(TEST_BAND_INDEX)); 883 preEqBand.setGain(TEST_GAIN1); 884 channel.setPreEqBand(TEST_BAND_INDEX, preEqBand); 885 assertEquals("preEQBand gain is different in band " + TEST_BAND_INDEX, 886 TEST_GAIN1, channel.getPreEqBand(TEST_BAND_INDEX).getGain(), EPSILON); 887 preEqBand.setGain(TEST_GAIN2); 888 channel.setPreEqBand(TEST_BAND_INDEX, preEqBand); 889 assertEquals("preEQBand gain is different in band " + TEST_BAND_INDEX, 890 TEST_GAIN2, channel.getPreEqBand(TEST_BAND_INDEX).getGain(), EPSILON); 891 892 MbcBand mbcBand = new MbcBand(channel.getMbcBand(TEST_BAND_INDEX)); 893 mbcBand.setPreGain(TEST_GAIN1); 894 channel.setMbcBand(TEST_BAND_INDEX, mbcBand); 895 assertEquals("mbcBand preGain is different in band " + TEST_BAND_INDEX, 896 TEST_GAIN1, channel.getMbcBand(TEST_BAND_INDEX).getPreGain(), EPSILON); 897 mbcBand.setPreGain(TEST_GAIN2); 898 channel.setMbcBand(TEST_BAND_INDEX, mbcBand); 899 assertEquals("mbcBand preGain is different in band " + TEST_BAND_INDEX, 900 TEST_GAIN2, channel.getMbcBand(TEST_BAND_INDEX).getPreGain(), EPSILON); 901 902 EqBand postEqBand = new EqBand(channel.getPostEqBand(TEST_BAND_INDEX)); 903 postEqBand.setGain(TEST_GAIN1); 904 channel.setPostEqBand(TEST_BAND_INDEX, postEqBand); 905 assertEquals("postEqBand gain is different in band " + TEST_BAND_INDEX, 906 TEST_GAIN1, channel.getPostEqBand(TEST_BAND_INDEX).getGain(), EPSILON); 907 postEqBand.setGain(TEST_GAIN2); 908 channel.setPostEqBand(TEST_BAND_INDEX, postEqBand); 909 assertEquals("postEqBand gain is different in band " + TEST_BAND_INDEX, 910 TEST_GAIN2, channel.getPostEqBand(TEST_BAND_INDEX).getGain(), EPSILON); 911 } 912 913 @Test test2_6Eq()914 public void test2_6Eq() throws Exception { 915 if (!hasAudioOutput()) { 916 return; 917 } 918 final boolean inUse = true; 919 final boolean enabled = true; 920 final int bandCount = 3; 921 922 Eq eq = new Eq(inUse, enabled, bandCount); 923 assertEquals("eq inUse is different", inUse, eq.isInUse()); 924 assertEquals("eq enabled is different", enabled, eq.isEnabled()); 925 assertEquals("eq bandCount is different", bandCount, eq.getBandCount()); 926 927 // changes 928 eq.setEnabled(!enabled); 929 assertEquals("eq enabled is different", !enabled, eq.isEnabled()); 930 931 // bands 932 for (int i = 0; i < bandCount; i++) { 933 final float frequency = (i + 1) * 100.3f; 934 final float gain = (i + 1) * 10.1f; 935 EqBand eqBand = new EqBand(eq.getBand(i)); 936 937 eqBand.setEnabled(enabled); 938 eqBand.setCutoffFrequency(frequency); 939 eqBand.setGain(gain); 940 941 eq.setBand(i, eqBand); 942 943 // compare 944 assertEquals("eq enabled is different in band " + i, enabled, 945 eq.getBand(i).isEnabled()); 946 assertEquals("eq cutoffFrequency is different in band " + i, 947 frequency, eq.getBand(i).getCutoffFrequency(), EPSILON); 948 assertEquals("eq eqBand gain is different in band " + i, 949 gain, eq.getBand(i).getGain(), EPSILON); 950 951 // EqBand constructor 952 EqBand eqBand2 = new EqBand(enabled, frequency, gain); 953 954 assertEquals("eq enabled is different in band " + i, enabled, 955 eqBand2.isEnabled()); 956 assertEquals("eq cutoffFrequency is different in band " + i, 957 frequency, eqBand2.getCutoffFrequency(), EPSILON); 958 assertEquals("eq eqBand gain is different in band " + i, 959 gain, eqBand2.getGain(), EPSILON); 960 } 961 } 962 963 @Test test2_7Mbc()964 public void test2_7Mbc() throws Exception { 965 if (!hasAudioOutput()) { 966 return; 967 } 968 969 final boolean inUse = true; 970 final boolean enabled = true; 971 final int bandCount = 3; 972 973 Mbc mbc = new Mbc(inUse, enabled, bandCount); 974 assertEquals("mbc inUse is different", inUse, mbc.isInUse()); 975 assertEquals("mbc enabled is different", enabled, mbc.isEnabled()); 976 assertEquals("mbc bandCount is different", bandCount, mbc.getBandCount()); 977 978 // changes 979 mbc.setEnabled(!enabled); 980 assertEquals("enabled is different", !enabled, mbc.isEnabled()); 981 982 // bands 983 for (int i = 0; i < bandCount; i++) { 984 int index = i + 1; 985 final float frequency = index * 100.3f; 986 final float attackTime = index * 3.2f; 987 final float releaseTime = 2 * attackTime; 988 final float ratio = index * 1.2f; 989 final float threshold = index * (-12.8f); 990 final float kneeWidth = index * 0.3f; 991 final float noiseGateThreshold = index * (-20.1f); 992 final float expanderRatio = index * 1.1f; 993 final float preGain = index * 10.1f; 994 final float postGain = index * (-0.2f); 995 MbcBand mbcBand = new MbcBand(mbc.getBand(i)); 996 997 mbcBand.setEnabled(enabled); 998 mbcBand.setCutoffFrequency(frequency); 999 mbcBand.setAttackTime(attackTime); 1000 mbcBand.setReleaseTime(releaseTime); 1001 mbcBand.setRatio(ratio); 1002 mbcBand.setThreshold(threshold); 1003 mbcBand.setKneeWidth(kneeWidth); 1004 mbcBand.setNoiseGateThreshold(noiseGateThreshold); 1005 mbcBand.setExpanderRatio(expanderRatio); 1006 mbcBand.setPreGain(preGain); 1007 mbcBand.setPostGain(postGain); 1008 1009 mbc.setBand(i, mbcBand); 1010 1011 // compare 1012 assertEquals("mbc enabled is different", enabled, mbc.getBand(i).isEnabled()); 1013 assertEquals("mbc cutoffFrequency is different in band " + i, 1014 frequency, mbc.getBand(i).getCutoffFrequency(), EPSILON); 1015 assertEquals("mbc attackTime is different in band " + i, 1016 attackTime, mbc.getBand(i).getAttackTime(), EPSILON); 1017 assertEquals("mbc releaseTime is different in band " + i, 1018 releaseTime, mbc.getBand(i).getReleaseTime(), EPSILON); 1019 assertEquals("mbc ratio is different in band " + i, 1020 ratio, mbc.getBand(i).getRatio(), EPSILON); 1021 assertEquals("mbc threshold is different in band " + i, 1022 threshold, mbc.getBand(i).getThreshold(), EPSILON); 1023 assertEquals("mbc kneeWidth is different in band " + i, 1024 kneeWidth, mbc.getBand(i).getKneeWidth(), EPSILON); 1025 assertEquals("mbc noiseGateThreshold is different in band " + i, 1026 noiseGateThreshold, mbc.getBand(i).getNoiseGateThreshold(), EPSILON); 1027 assertEquals("mbc expanderRatio is different in band " + i, 1028 expanderRatio, mbc.getBand(i).getExpanderRatio(), EPSILON); 1029 assertEquals("mbc preGain is different in band " + i, 1030 preGain, mbc.getBand(i).getPreGain(), EPSILON); 1031 assertEquals("mbc postGain is different in band " + i, 1032 postGain, mbc.getBand(i).getPostGain(), EPSILON); 1033 1034 // MbcBand constructor 1035 MbcBand mbcBand2 = new MbcBand(enabled, frequency, attackTime, releaseTime, ratio, 1036 threshold, kneeWidth, noiseGateThreshold, expanderRatio, preGain, postGain); 1037 1038 assertEquals("mbc enabled is different", enabled, mbcBand2.isEnabled()); 1039 assertEquals("mbc cutoffFrequency is different in band " + i, 1040 frequency, mbcBand2.getCutoffFrequency(), EPSILON); 1041 assertEquals("mbc attackTime is different in band " + i, 1042 attackTime, mbcBand2.getAttackTime(), EPSILON); 1043 assertEquals("mbc releaseTime is different in band " + i, 1044 releaseTime, mbcBand2.getReleaseTime(), EPSILON); 1045 assertEquals("mbc ratio is different in band " + i, 1046 ratio, mbcBand2.getRatio(), EPSILON); 1047 assertEquals("mbc threshold is different in band " + i, 1048 threshold, mbcBand2.getThreshold(), EPSILON); 1049 assertEquals("mbc kneeWidth is different in band " + i, 1050 kneeWidth, mbcBand2.getKneeWidth(), EPSILON); 1051 assertEquals("mbc noiseGateThreshold is different in band " + i, 1052 noiseGateThreshold, mbcBand2.getNoiseGateThreshold(), EPSILON); 1053 assertEquals("mbc expanderRatio is different in band " + i, 1054 expanderRatio, mbcBand2.getExpanderRatio(), EPSILON); 1055 assertEquals("mbc preGain is different in band " + i, 1056 preGain, mbcBand2.getPreGain(), EPSILON); 1057 assertEquals("mbc postGain is different in band " + i, 1058 postGain, mbcBand2.getPostGain(), EPSILON); 1059 } 1060 } 1061 1062 @Test test2_8Limiter()1063 public void test2_8Limiter() throws Exception { 1064 if (!hasAudioOutput()) { 1065 return; 1066 } 1067 1068 final boolean inUse = true; 1069 final boolean enabled = true; 1070 final int linkGroup = 4; 1071 final float attackTime = 3.2f; 1072 final float releaseTime = 2 * attackTime; 1073 final float ratio = 1.2f; 1074 final float threshold = (-12.8f); 1075 final float postGain = (-0.2f); 1076 1077 Limiter limiter = new Limiter(inUse, enabled, linkGroup, attackTime, releaseTime, ratio, 1078 threshold, postGain); 1079 assertEquals("limiter inUse is different", inUse, limiter.isInUse()); 1080 assertEquals("limiter enabled is different", enabled, limiter.isEnabled()); 1081 assertEquals("limiter linkGroup is different", linkGroup, limiter.getLinkGroup()); 1082 1083 // defaults 1084 assertEquals("limiter attackTime is different", 1085 attackTime, limiter.getAttackTime(), EPSILON); 1086 assertEquals("limiter releaseTime is different", 1087 releaseTime, limiter.getReleaseTime(), EPSILON); 1088 assertEquals("limiter ratio is different", 1089 ratio, limiter.getRatio(), EPSILON); 1090 assertEquals("limiter threshold is different", 1091 threshold, limiter.getThreshold(), EPSILON); 1092 assertEquals("limiter postGain is different", 1093 postGain, limiter.getPostGain(), EPSILON); 1094 1095 // changes 1096 final boolean newEnabled = !enabled; 1097 final int newLinkGroup = 7; 1098 final float newAttackTime = attackTime + 10; 1099 final float newReleaseTime = releaseTime + 10; 1100 final float newRatio = ratio + 2f; 1101 final float newThreshold = threshold - 20f; 1102 final float newPostGain = postGain + 3f; 1103 1104 limiter.setEnabled(newEnabled); 1105 limiter.setLinkGroup(newLinkGroup); 1106 limiter.setAttackTime(newAttackTime); 1107 limiter.setReleaseTime(newReleaseTime); 1108 limiter.setRatio(newRatio); 1109 limiter.setThreshold(newThreshold); 1110 limiter.setPostGain(newPostGain); 1111 1112 assertEquals("limiter enabled is different", newEnabled, limiter.isEnabled()); 1113 assertEquals("limiter linkGroup is different", newLinkGroup, limiter.getLinkGroup()); 1114 assertEquals("limiter attackTime is different", 1115 newAttackTime, limiter.getAttackTime(), EPSILON); 1116 assertEquals("limiter releaseTime is different", 1117 newReleaseTime, limiter.getReleaseTime(), EPSILON); 1118 assertEquals("limiter ratio is different", 1119 newRatio, limiter.getRatio(), EPSILON); 1120 assertEquals("limiter threshold is different", 1121 newThreshold, limiter.getThreshold(), EPSILON); 1122 assertEquals("limiter postGain is different", 1123 newPostGain, limiter.getPostGain(), EPSILON); 1124 } 1125 1126 @Test test2_9BandStage()1127 public void test2_9BandStage() throws Exception { 1128 if (!hasAudioOutput()) { 1129 return; 1130 } 1131 1132 final boolean inUse = true; 1133 final boolean enabled = true; 1134 final int bandCount = 3; 1135 1136 BandStage bandStage = new BandStage(inUse, enabled, bandCount); 1137 assertEquals("bandStage inUse is different", inUse, bandStage.isInUse()); 1138 assertEquals("bandStage enabled is different", enabled, bandStage.isEnabled()); 1139 assertEquals("bandStage bandCount is different", bandCount, bandStage.getBandCount()); 1140 1141 // change 1142 bandStage.setEnabled(!enabled); 1143 assertEquals("bandStage enabled is different", !enabled, bandStage.isEnabled()); 1144 } 1145 1146 @Test test2_10Stage()1147 public void test2_10Stage() throws Exception { 1148 if (!hasAudioOutput()) { 1149 return; 1150 } 1151 1152 final boolean inUse = true; 1153 final boolean enabled = true; 1154 final int bandCount = 3; 1155 1156 DynamicsProcessing.Stage stage = new DynamicsProcessing.Stage(inUse, enabled); 1157 assertEquals("stage inUse is different", inUse, stage.isInUse()); 1158 assertEquals("stage enabled is different", enabled, stage.isEnabled()); 1159 1160 // change 1161 stage.setEnabled(!enabled); 1162 assertEquals("stage enabled is different", !enabled, stage.isEnabled()); 1163 } 1164 1165 @Test test2_11BandBase()1166 public void test2_11BandBase() throws Exception { 1167 if (!hasAudioOutput()) { 1168 return; 1169 } 1170 1171 final boolean enabled = true; 1172 final float frequency = 100.3f; 1173 1174 BandBase bandBase = new BandBase(enabled, frequency); 1175 1176 assertEquals("bandBase enabled is different", enabled, bandBase.isEnabled()); 1177 assertEquals("bandBase cutoffFrequency is different", 1178 frequency, bandBase.getCutoffFrequency(), EPSILON); 1179 1180 // change 1181 final float newFrequency = frequency + 10f; 1182 bandBase.setEnabled(!enabled); 1183 bandBase.setCutoffFrequency(newFrequency); 1184 assertEquals("bandBase enabled is different", !enabled, bandBase.isEnabled()); 1185 assertEquals("bandBase cutoffFrequency is different", 1186 newFrequency, bandBase.getCutoffFrequency(), EPSILON); 1187 } 1188 1189 @Test test2_12Channel()1190 public void test2_12Channel() throws Exception { 1191 if (!hasAudioOutput()) { 1192 return; 1193 } 1194 1195 final float inputGain = 3.4f; 1196 final boolean preEqInUse = true; 1197 final int preEqBandCount = 3; 1198 final boolean mbcInUse = true; 1199 final int mbcBandCount = 4; 1200 final boolean postEqInUse = true; 1201 final int postEqBandCount = 5; 1202 final boolean limiterInUse = true; 1203 1204 Channel channel = new Channel(inputGain, preEqInUse, preEqBandCount, mbcInUse, 1205 mbcBandCount, postEqInUse, postEqBandCount, limiterInUse); 1206 1207 assertEquals("channel inputGain is different", inputGain, 1208 channel.getInputGain(), EPSILON); 1209 assertEquals("channel preEqInUse is different", preEqInUse, channel.getPreEq().isInUse()); 1210 assertEquals("channel preEqBandCount is different", preEqBandCount, 1211 channel.getPreEq().getBandCount()); 1212 assertEquals("channel mbcInUse is different", mbcInUse, channel.getMbc().isInUse()); 1213 assertEquals("channel mbcBandCount is different", mbcBandCount, 1214 channel.getMbc().getBandCount()); 1215 assertEquals("channel postEqInUse is different", postEqInUse, 1216 channel.getPostEq().isInUse()); 1217 assertEquals("channel postEqBandCount is different", postEqBandCount, 1218 channel.getPostEq().getBandCount()); 1219 assertEquals("channel limiterInUse is different", limiterInUse, 1220 channel.getLimiter().isInUse()); 1221 } 1222 // ----------------------------------------------------------------- 1223 // 3 - Builder 1224 // ---------------------------------- 1225 1226 @Test test3_0Builder_stagesAllChannels()1227 public void test3_0Builder_stagesAllChannels() throws Exception { 1228 if (!hasAudioOutput()) { 1229 return; 1230 } 1231 1232 DynamicsProcessing.Config config = getBuilderWithValues(MIN_CHANNEL_COUNT).build(); 1233 DynamicsProcessing.Config.Builder builder = getBuilderWithValues(TEST_CHANNEL_COUNT); 1234 1235 // get Stages, apply all channels 1236 Eq preEq = new Eq(config.getPreEqByChannelIndex(TEST_CHANNEL_INDEX)); 1237 EqBand preEqBand = new EqBand(preEq.getBand(TEST_BAND_INDEX)); 1238 preEqBand.setGain(TEST_GAIN1); 1239 preEq.setBand(TEST_BAND_INDEX, preEqBand); 1240 builder.setPreEqAllChannelsTo(preEq); 1241 1242 Mbc mbc = new Mbc(config.getMbcByChannelIndex(TEST_CHANNEL_INDEX)); 1243 MbcBand mbcBand = new MbcBand(mbc.getBand(TEST_BAND_INDEX)); 1244 mbcBand.setPreGain(TEST_GAIN1); 1245 mbc.setBand(TEST_BAND_INDEX, mbcBand); 1246 builder.setMbcAllChannelsTo(mbc); 1247 1248 Eq postEq = new Eq(config.getPostEqByChannelIndex(TEST_CHANNEL_INDEX)); 1249 EqBand postEqBand = new EqBand(postEq.getBand(TEST_BAND_INDEX)); 1250 postEqBand.setGain(TEST_GAIN1); 1251 postEq.setBand(TEST_BAND_INDEX, postEqBand); 1252 builder.setPostEqAllChannelsTo(postEq); 1253 1254 Limiter limiter = new Limiter(config.getLimiterByChannelIndex(TEST_CHANNEL_INDEX)); 1255 limiter.setPostGain(TEST_GAIN1); 1256 builder.setLimiterAllChannelsTo(limiter); 1257 1258 // build and compare 1259 DynamicsProcessing.Config newConfig = builder.build(); 1260 for (int i = 0; i < TEST_CHANNEL_COUNT; i++) { 1261 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 1262 TEST_GAIN1, newConfig.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 1263 EPSILON); 1264 1265 assertEquals("mbcBand preGain is different in channel " + i + " band " + 1266 TEST_BAND_INDEX, TEST_GAIN1, 1267 newConfig.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), 1268 EPSILON); 1269 1270 assertEquals("postEQBand gain is different in channel " + i + " band " + 1271 TEST_BAND_INDEX, TEST_GAIN1, 1272 newConfig.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 1273 EPSILON); 1274 1275 assertEquals("limiter gain is different in channel " + i, 1276 TEST_GAIN1, newConfig.getLimiterByChannelIndex(i).getPostGain(), EPSILON); 1277 } 1278 } 1279 1280 @Test test3_1Builder_stagesByChannelIndex()1281 public void test3_1Builder_stagesByChannelIndex() throws Exception { 1282 if (!hasAudioOutput()) { 1283 return; 1284 } 1285 1286 DynamicsProcessing.Config config = getBuilderWithValues(MIN_CHANNEL_COUNT).build(); 1287 DynamicsProcessing.Config.Builder builder = getBuilderWithValues(TEST_CHANNEL_COUNT); 1288 1289 Eq preEq = new Eq(config.getPreEqByChannelIndex(TEST_CHANNEL_INDEX)); 1290 EqBand preEqBand = new EqBand(preEq.getBand(TEST_BAND_INDEX)); 1291 1292 Mbc mbc = new Mbc(config.getMbcByChannelIndex(TEST_CHANNEL_INDEX)); 1293 MbcBand mbcBand = new MbcBand(mbc.getBand(TEST_BAND_INDEX)); 1294 1295 Eq postEq = new Eq(config.getPostEqByChannelIndex(TEST_CHANNEL_INDEX)); 1296 EqBand postEqBand = new EqBand(postEq.getBand(TEST_BAND_INDEX)); 1297 1298 Limiter limiter = new Limiter(config.getLimiterByChannelIndex(TEST_CHANNEL_INDEX)); 1299 1300 // get Stages, apply per channel 1301 for (int i = 0; i < TEST_CHANNEL_COUNT; i++) { 1302 float gain = i % 2 == 0 ? TEST_GAIN1 : TEST_GAIN2; 1303 1304 builder.setInputGainByChannelIndex(i, gain); 1305 1306 preEqBand.setGain(gain); 1307 preEq.setBand(TEST_BAND_INDEX, preEqBand); 1308 builder.setPreEqByChannelIndex(i, preEq); 1309 1310 mbcBand.setPreGain(gain); 1311 mbc.setBand(TEST_BAND_INDEX, mbcBand); 1312 builder.setMbcByChannelIndex(i, mbc); 1313 1314 postEqBand.setGain(gain); 1315 postEq.setBand(TEST_BAND_INDEX, postEqBand); 1316 builder.setPostEqByChannelIndex(i, postEq); 1317 1318 limiter.setPostGain(gain); 1319 builder.setLimiterByChannelIndex(i, limiter); 1320 } 1321 // build and compare 1322 DynamicsProcessing.Config newConfig = builder.build(); 1323 for (int i = 0; i < TEST_CHANNEL_COUNT; i++) { 1324 float expectedGain = i % 2 == 0 ? TEST_GAIN1 : TEST_GAIN2; 1325 1326 assertEquals("inputGain is different in channel " + i, 1327 expectedGain, 1328 newConfig.getInputGainByChannelIndex(i), 1329 EPSILON); 1330 1331 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 1332 expectedGain, 1333 newConfig.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 1334 EPSILON); 1335 1336 assertEquals("mbcBand preGain is different in channel " + i + " band " + 1337 TEST_BAND_INDEX, expectedGain, 1338 newConfig.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), 1339 EPSILON); 1340 1341 assertEquals("postEQBand gain is different in channel " + i + " band " + 1342 TEST_BAND_INDEX, expectedGain, 1343 newConfig.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 1344 EPSILON); 1345 1346 assertEquals("limiter gain is different in channel " + i, 1347 expectedGain, newConfig.getLimiterByChannelIndex(i).getPostGain(), EPSILON); 1348 } 1349 } 1350 1351 @Test test3_2Builder_setAllChannelsTo()1352 public void test3_2Builder_setAllChannelsTo() throws Exception { 1353 if (!hasAudioOutput()) { 1354 return; 1355 } 1356 1357 DynamicsProcessing.Config config = getBuilderWithValues(MIN_CHANNEL_COUNT).build(); 1358 DynamicsProcessing.Config.Builder builder = getBuilderWithValues(TEST_CHANNEL_COUNT); 1359 1360 Channel channel = new Channel(config.getChannelByChannelIndex(TEST_CHANNEL_INDEX)); 1361 1362 // get Stages, apply all channels 1363 Eq preEq = new Eq(config.getPreEqByChannelIndex(TEST_CHANNEL_INDEX)); 1364 EqBand preEqBand = new EqBand(preEq.getBand(TEST_BAND_INDEX)); 1365 preEqBand.setGain(TEST_GAIN1); 1366 preEq.setBand(TEST_BAND_INDEX, preEqBand); 1367 channel.setPreEq(preEq); 1368 1369 Mbc mbc = new Mbc(config.getMbcByChannelIndex(TEST_CHANNEL_INDEX)); 1370 MbcBand mbcBand = new MbcBand(mbc.getBand(TEST_BAND_INDEX)); 1371 mbcBand.setPreGain(TEST_GAIN1); 1372 mbc.setBand(TEST_BAND_INDEX, mbcBand); 1373 channel.setMbc(mbc); 1374 1375 Eq postEq = new Eq(config.getPostEqByChannelIndex(TEST_CHANNEL_INDEX)); 1376 EqBand postEqBand = new EqBand(postEq.getBand(TEST_BAND_INDEX)); 1377 postEqBand.setGain(TEST_GAIN1); 1378 postEq.setBand(TEST_BAND_INDEX, postEqBand); 1379 channel.setPostEq(postEq); 1380 1381 Limiter limiter = new Limiter(config.getLimiterByChannelIndex(TEST_CHANNEL_INDEX)); 1382 limiter.setPostGain(TEST_GAIN1); 1383 channel.setLimiter(limiter); 1384 1385 builder.setAllChannelsTo(channel); 1386 // build and compare 1387 DynamicsProcessing.Config newConfig = builder.build(); 1388 for (int i = 0; i < TEST_CHANNEL_COUNT; i++) { 1389 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 1390 TEST_GAIN1, newConfig.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 1391 EPSILON); 1392 1393 assertEquals("mbcBand preGain is different in channel " + i + " band " + 1394 TEST_BAND_INDEX, TEST_GAIN1, 1395 newConfig.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), 1396 EPSILON); 1397 1398 assertEquals("postEQBand gain is different in channel " + i + " band " + 1399 TEST_BAND_INDEX, TEST_GAIN1, 1400 newConfig.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 1401 EPSILON); 1402 1403 assertEquals("limiter gain is different in channel " + i, 1404 TEST_GAIN1, newConfig.getLimiterByChannelIndex(i).getPostGain(), EPSILON); 1405 } 1406 } 1407 1408 @Test test3_3Builder_setChannelTo()1409 public void test3_3Builder_setChannelTo() throws Exception { 1410 if (!hasAudioOutput()) { 1411 return; 1412 } 1413 1414 DynamicsProcessing.Config config = getBuilderWithValues(MIN_CHANNEL_COUNT).build(); 1415 DynamicsProcessing.Config.Builder builder = getBuilderWithValues(TEST_CHANNEL_COUNT); 1416 1417 Channel channel = new Channel(config.getChannelByChannelIndex(TEST_CHANNEL_INDEX)); 1418 1419 Eq preEq = new Eq(config.getPreEqByChannelIndex(TEST_CHANNEL_INDEX)); 1420 EqBand preEqBand = new EqBand(preEq.getBand(TEST_BAND_INDEX)); 1421 1422 Mbc mbc = new Mbc(config.getMbcByChannelIndex(TEST_CHANNEL_INDEX)); 1423 MbcBand mbcBand = new MbcBand(mbc.getBand(TEST_BAND_INDEX)); 1424 1425 Eq postEq = new Eq(config.getPostEqByChannelIndex(TEST_CHANNEL_INDEX)); 1426 EqBand postEqBand = new EqBand(postEq.getBand(TEST_BAND_INDEX)); 1427 1428 Limiter limiter = new Limiter(config.getLimiterByChannelIndex(TEST_CHANNEL_INDEX)); 1429 1430 // get Stages, apply per channel 1431 for (int i = 0; i < TEST_CHANNEL_COUNT; i++) { 1432 float gain = i % 2 == 0 ? TEST_GAIN1 : TEST_GAIN2; 1433 1434 preEqBand.setGain(gain); 1435 preEq.setBand(TEST_BAND_INDEX, preEqBand); 1436 channel.setPreEq(preEq); 1437 1438 mbcBand.setPreGain(gain); 1439 mbc.setBand(TEST_BAND_INDEX, mbcBand); 1440 channel.setMbc(mbc); 1441 1442 postEqBand.setGain(gain); 1443 postEq.setBand(TEST_BAND_INDEX, postEqBand); 1444 channel.setPostEq(postEq); 1445 1446 limiter.setPostGain(gain); 1447 channel.setLimiter(limiter); 1448 1449 builder.setChannelTo(i, channel); 1450 } 1451 // build and compare 1452 DynamicsProcessing.Config newConfig = builder.build(); 1453 for (int i = 0; i < TEST_CHANNEL_COUNT; i++) { 1454 float expectedGain = i % 2 == 0 ? TEST_GAIN1 : TEST_GAIN2; 1455 assertEquals("preEQBand gain is different in channel " + i + " band " + TEST_BAND_INDEX, 1456 expectedGain, 1457 newConfig.getPreEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 1458 EPSILON); 1459 1460 assertEquals("mbcBand preGain is different in channel " + i + " band " + 1461 TEST_BAND_INDEX, expectedGain, 1462 newConfig.getMbcBandByChannelIndex(i, TEST_BAND_INDEX).getPreGain(), 1463 EPSILON); 1464 1465 assertEquals("postEQBand gain is different in channel " + i + " band " + 1466 TEST_BAND_INDEX, expectedGain, 1467 newConfig.getPostEqBandByChannelIndex(i, TEST_BAND_INDEX).getGain(), 1468 EPSILON); 1469 1470 assertEquals("limiter gain is different in channel " + i, 1471 expectedGain, newConfig.getLimiterByChannelIndex(i).getPostGain(), EPSILON); 1472 } 1473 } 1474 // ----------------------------------------------------------------- 1475 // private methods 1476 // ---------------------------------- 1477 createDynamicsProcessing(int session)1478 private void createDynamicsProcessing(int session) { 1479 createDynamicsProcessingWithConfig(session, null); 1480 } 1481 createDynamicsProcessingWithConfig(int session, DynamicsProcessing.Config config)1482 private void createDynamicsProcessingWithConfig(int session, DynamicsProcessing.Config config) { 1483 releaseDynamicsProcessing(); 1484 try { 1485 mDP = (config == null ? new DynamicsProcessing(session) 1486 : new DynamicsProcessing(0 /* priority */, session, config)); 1487 } catch (IllegalArgumentException e) { 1488 Log.e(TAG, "createDynamicsProcessingWithConfig() DynamicsProcessing not found" 1489 + "exception: ", e); 1490 } catch (UnsupportedOperationException e) { 1491 Log.e(TAG, "createDynamicsProcessingWithConfig() Effect library not loaded exception: ", 1492 e); 1493 } 1494 assertNotNull("could not create DynamicsProcessing", mDP); 1495 } 1496 releaseDynamicsProcessing()1497 private void releaseDynamicsProcessing() { 1498 if (mDP != null) { 1499 mDP.release(); 1500 mDP = null; 1501 } 1502 } 1503 createDefaultEffect()1504 private void createDefaultEffect() { 1505 DynamicsProcessing.Config config = getBuilderWithValues().build(); 1506 assertNotNull("null config", config); 1507 1508 AudioManager am = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); 1509 assertNotNull("null AudioManager", am); 1510 1511 int session = am.generateAudioSessionId(); 1512 assertTrue("cannot generate new session", session != AudioManager.ERROR); 1513 1514 createDynamicsProcessingWithConfig(session, config); 1515 } 1516 getBuilder(int channelCount)1517 private DynamicsProcessing.Config.Builder getBuilder(int channelCount) { 1518 // simple config 1519 DynamicsProcessing.Config.Builder builder = new DynamicsProcessing.Config.Builder( 1520 DEFAULT_VARIANT /* variant */, 1521 channelCount/* channels */, 1522 DEFAULT_PREEQ_IN_USE /* enable preEQ */, 1523 DEFAULT_PREEQ_BAND_COUNT /* preEq bands */, 1524 DEFAULT_MBC_IN_USE /* enable mbc */, 1525 DEFAULT_MBC_BAND_COUNT /* mbc bands */, 1526 DEFAULT_POSTEQ_IN_USE /* enable postEq */, 1527 DEFAULT_POSTEQ_BAND_COUNT /* postEq bands */, 1528 DEFAULT_LIMITER_IN_USE /* enable limiter */); 1529 1530 return builder; 1531 } 1532 getBuilderWithValues(int channelCount)1533 private DynamicsProcessing.Config.Builder getBuilderWithValues(int channelCount) { 1534 // simple config 1535 DynamicsProcessing.Config.Builder builder = getBuilder(channelCount); 1536 1537 // Set Defaults 1538 builder.setPreferredFrameDuration(DEFAULT_FRAME_DURATION); 1539 builder.setInputGainAllChannelsTo(DEFAULT_INPUT_GAIN); 1540 return builder; 1541 } 1542 getBuilderWithValues()1543 private DynamicsProcessing.Config.Builder getBuilderWithValues() { 1544 return getBuilderWithValues(MIN_CHANNEL_COUNT); 1545 } 1546 1547 } 1548