Re: [Audacity-nyquist] RE: Freeing Global "s" Reduces Memory Use
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
|
From: Alex S. B. <ale...@al...> - 2005-04-03 17:40:35
|
Roger, Congratulations on discovering a new design pattern. I think this new approach is critical to writing a good Audacity Nyquist plug-in, if you want to analyze a long sound. Before, I was accumulating around 80 MB of memory to analyze a 3-minute passage. Memory use increased with passage length, until Audacity basically froze due to memory swapping. Now, memory use stays around 20 MB, even when analyzing a multiple-hour recording. For reference, Audacity by itself typically takes 10 to 15 MB on my system, so the difference is HUGE. WOW! I found that this method works well: (let (my-s) (setq my-s (s2 (s1 s))) ;; copies the value of s (set s nil) ;; don't need s anymore (dotimes (n 100) (snd-fetch my-s) ) Also, you can simply transform s and process it without causing memory problems: (setq s (my-s-function s)) (dotimes (n 100) (snd-fetch s)) However, if you try to keep s in memory while iterating through any transformation of s, you get enormous memory use that grows with the length of s. This will cause memory problems: (let (my-s) (setq my-s (s2 (s1 s))) ;; copies the value of s (dotimes (n 100) (snd-fetch my-s) ) Interestingly, setting a different, local variable to s before freeing s will still cause memory problems: (let (my-s s-original) (setq my-s (s2 (s1 s))) ;; copies the value of s (set s-original s) ;; copy s to a local variable (set s nil) ;; don't need s anymore, release the global variable (dotimes (n 100) (snd-fetch my-s) ) I think that this method will be useful for analysis functions, where you want to return a list of labels. Unfortunately, I think it will NOT be useful for processing sound. Sorry to those of you who want to find and trim passages of long silence. By discarding "s" or transforming "s" for processing, you would loose your original input file. Thanks for your help. I think we now have a pretty effective silence finder. I will post the plug-in in a separate e-mail. --Alex Quoting "Roger B. Dannenberg" <rb...@cs...>: > Now that you tell me my "solution" doesn't work, I can > see (I think) what the problem is. At any point, even when you exit the do > loop, you could write another expression using "s" and you'd get the > original input signal, so Nyquist has to keep "s" around with all its > samples. But you don't need "s", so try this, which sets "s" to nil before > starting to fetch samples. > > (let (my-s) > (setq my-s (s2 (s1 s))) ;; copies the value of s > (set s nil) ;; don't need s anymore > (dotimes (n 100) (snd-fetch my-s)) > ) > > I've never done anything like this before, so this is a new "design pattern" > for Nyquist plug-ins that take sound in and put labels out. I hope it works. > > -Roger ---------------------- Alex S. Brown, PMP ale...@al... http://www.alexsbrown.com/ |