ddf / Minim

A Java audio library, designed to be used with Processing.
http://code.compartmental.net/tools/minim
GNU Lesser General Public License v3.0
670 stars 137 forks source link

Deleting recorder files on exit #113

Closed markcosmic closed 3 years ago

markcosmic commented 3 years ago

Greetings all, Question: Is there a way to have minin release the use of the recorder created without creating a a new recorder under the same name? Explain: So I’ve written a recording sketch using minim examples. My sketch checks for existing files in the data folder starting with the prefix “MaxRecordings” (after my son) with an added incremental index (1,2,3 and so on). This is done in a while() loop until the file does not exist. Then increments the suffix by 1. (Example: “MaxRecordings9”) because it found 8 previous files. This works no issue. Here’s the issue: I use recorder.createRecorder(“MaxRecordings” + index). This works as it should. If I don’t want to keep the recorded file or just don’t actually record and exit the sketch. The file still exist. I’ve written the code to delete the unused or unwanted file to delete it onexit(), (easy to do). But the delete() method returns “false” and the file remains. Even if I save the recording first it still remains. All the code I wrote works even the delete() method which returns “false”. No errors. I believe that that minin doesn’t release the use of the “recorder” created until another is created using the same name (“recorder”). Thus, not allowing the delete() method to delete the file. Is there a way to have minin release the use of the recorder created without creating a new recorder under the same name?

markcosmic commented 3 years ago

No takers? Oh well thanks anyway

ddf commented 3 years ago

Hi, apologies for not responding sooner, I am not really actively maintaining Minim right now, so I don't often check in here. With questions like these you might get a faster response from the community by posting in the Processing forum.

That said, I looked into the code and I believe what's going on is that the version of createRecorder that you are using results in a "streaming" recording being created that records directly to a file that is opened when the recorder is created. The only way to close that file stream is to call save() on the recorder (and you'll also want to call close() on the recording returned from save(). So you'd need to do that before deleting the file. This code is not well written (my fault) and lots of people have had issues with it over the years.

Another option would be to use the version of createRecorder that takes a boolean buffered argument. If buffered is true, then you'll get back a recorder that records into an in-memory array and doesn't actually write to disk until you call save(). So, in that case, if you discard the recorder without ever saving, you won't wind up with open file handles or extra files on disk that you want to delete. But this buffered version may not be appropriate if you are making longer recordings. In particular, the longer that you record, the slower it gets, which is why the streaming version is the default.

markcosmic commented 3 years ago

Thank you so much for your helpful response. In the forums I always recommend minim over the processing 3 sound library which doesn't work well with all versions of windows 10. Minim seems to work excellent with all versions of windows. Would you have plans to make it usable in processing for android? I had to use the android media player api. At this time there is no audio library in processing that works in android mode. You don't need to respond but it might make a good covid-19 project. Thanks again for your assistance. Stay healthy

On 2021-02-11 22:57, Damien Quartz wrote:

Hi, apologies for not responding sooner, I am not really actively maintaining Minim right now, so I don't often check in here. With questions like these you might get a faster response from the community by posting in the Processing forum.

That said, I looked into the code and I believe what's going on is that the version of createRecorder that you are using results in a "streaming" recording being created that records directly to a file that is opened when the recorder is created. The only way to close that file stream is to call save() on the recorder (and you'll also want to call close() on the recording returned from save(). So you'd need to do that before deleting the file. This code is not well written (my fault) and lots of people have had issues with it over the years.

Another option would be to use the version of createRecorder that takes a boolean buffered argument. If buffered is true, then you'll get back a recorder that records into an in-memory array and doesn't actually write to disk until you call save(). So, in that case, if you discard the recorder without ever saving, you won't wind up with open file handles or extra files on disk that you want to delete. But this buffered version may not be appropriate if you are making longer recordings. In particular, the longer that you record, the slower it gets, which is why the streaming version is the default.

-- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub [1], or unsubscribe [2].

Links:

[1] https://github.com/ddf/Minim/issues/113#issuecomment-777952364 [2] https://github.com/notifications/unsubscribe-auth/AMMOXUWRMVN7AI6OHJSTERDS6SRKBANCNFSM4W3UFAZA

ddf commented 3 years ago

Many years ago I had aspirations to do that, but never got around to it.