Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sound {
- private int[] samples;
- public int limitAmplitude(int limit) {
- int cnt = 0;
- for (int i = 0; i < samples.length; i++) {
- if(samples[i] > limit) {
- cnt += 1;
- samples[i] = limit;
- }
- else if (samples[i] < -limit) {
- cnt +=1;
- samples[i] = -(limit);
- }
- }
- return cnt;
- }
- public void trimSilenceFromBeginning() {
- int cnt = 0;
- for (int i = 0; i < samples.length; i++) {
- if (samples[i] != 0) {
- break;
- }
- else {
- cnt += 1;
- }
- }
- int[] change = new int[samples.length - cnt];
- for (int i =0; i < change.length; i++) {
- change[i] = samples[cnt + i];
- }
- samples = change;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement