I have an audio input stream which takes in the current volume level of playing music. Then over a certain windows size (which can range from 5 to 40), of the latest volumes, I want to keep track of the highest and lowest values inside the window. so on each iteration the oldest value that was added is removed and the newest volume level reading is added.
so say if i ran the program for 8 iterations with a window of 5 and this would result. with only the low and high values being of importance.
add 2
2
add 4
2 4
add 3
2 3 4
add 2
2 2 3 4
add 7
2 2 3 4 7
-first 2 removed from list add 9
2 3 4 7 9
4 removed , add 5
2 3 5 7 9
3 removed , add 2
2 2 5 7 9
etc
what would be the most efficient way to do this and using what type of collections?
edit note that this loop is being run constantly on a separate thread
values are floats