The state shall file formal charges on defendants in custody by information, or indictment, or in the case of alleged misdemeanors by whatever documents constitute a formal charge, within 30 days from the date on which defendants are arrested or from the date of the service of capiases upon them. If the defendants remain uncharged, the court on the 30th day and with notice to the state shall:
(1) Order that the defendants automatically be released on their own recognizance on the 33rd day unless the state files formal charges by that date; or
(2) If good cause is shown by the state, order that the defendants automatically be released on their own recognizance on the 40th day unless the state files formal charges by that date.
In no event shall any defendants remain in custody beyond 40 days unless they have been formally charged with a crime.