Help optimizing a function

What do you mean by "a long time"? It should take no longer than a millisecond or so to determine the min and max values of an array of just a few elements. (5 elements? -- as suggested by the declaration "const int recording_time = 5;" ?)

If you want to tell where your program is stuck, sprinkle some serial.print statements throughout the code, saying "I'm here" and print out the current time using millis().