Advertisement
Guest User

Benjamin Kooey

a guest
Oct 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public class Sound {
  2.  
  3. private int[] samples;
  4.  
  5. public int limitAmplitude(int limit) {
  6. int cnt = 0;
  7. for (int i = 0; i < samples.length; i++) {
  8. if(samples[i] > limit) {
  9. cnt += 1;
  10. samples[i] = limit;
  11. }
  12. else if (samples[i] < -limit) {
  13. cnt +=1;
  14. samples[i] = -(limit);
  15. }
  16.  
  17. }
  18. return cnt;
  19. }
  20.  
  21. public void trimSilenceFromBeginning() {
  22. int cnt = 0;
  23. for (int i = 0; i < samples.length; i++) {
  24. if (samples[i] != 0) {
  25. break;
  26. }
  27. else {
  28. cnt += 1;
  29. }
  30. }
  31. int[] change = new int[samples.length - cnt];
  32. for (int i =0; i < change.length; i++) {
  33. change[i] = samples[cnt + i];
  34. }
  35. samples = change;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement