Do I need to close an audio clip?

I have an application that processes real-time data and is supposed to beep when a certain event occurs. The triggering event can occur multiple times per second, and if the beep is already playing when another event triggers the code is just supposed to ignore it (as opposed to interrupting the current beep and starting a new one). Here is the basic code:
    Clip clickClip
    public void prepareProcess() {
        super.prepareProcess();
        clickClip = null;
        try {
            clipFile = new File("C:/WINDOWS/Media/CHIMES.wav");
            ais = AudioSystem.getAudioInputStream(clipFile);
            clickClip = AudioSystem.getClip();
            clickClip.open(ais);
            fileIsLoaded = true;
        } catch (Exception ex) {
            clickClip = null;
            fileIsLoaded = false;
    public void playSound() {
        if (fileIsLoaded) {
            if ((clickClip==null) || (!clickClip.isRunning())) {
                try {
                    clickClip.setFramePosition(0);
                    clickClip.start();
                } catch (Exception ex) {
                    System.out.println("Cannot play click noise");
                    ex.printStackTrace();
        }The prepareProcess method gets run once in the beginning, and the playSound method is called every time a triggering event occurs. My question is: do I need to close the clickClip object? I know I could add an actionListener to monitor for a Stop event, but since the event occurs so frequently I'm worried the extra processing is going to slow down the real-time data collection.
The code seems to run fine, but my worry is memory leaks. The code above is based on an example I found while searching the net, but the example used an actionListener to close the Clip specifically "to eliminate memory leaks that would occur when the stop method wasn't implemented". My program is intended to run for hours so any memory leaks I have will cause problems.
I'll be honest: I have no idea how to verify whether or not I've got a problem. I'm using Netbeans, and running the memory profiler just gave me a huge list of things that I don't know how to read. This is supposed to be the simple part of the program, and I'm spending hours on it. Any help would be greatly appreciated!
Michael

Thanks so much for the reply.
AndrewThompson64 wrote:
Experiment with Clip.isActive()/isRunning().
Alternately add a LineListener and look at the LineEvent.Type. If it is START, set a currentlyPlaying to true, and at STOP set it false. On new invocations of the event that triggers the Clip to start, check the currentlyPlaying member and if true, return without doing anything.
I was worried that adding a listener would slow down the real-time data collection, but I'll experiment with that to see.
>
For better help sooner, post an SSCCE. For SSCCEs to do with Java Sound, I provide some [clips you can hot-link to|http://pscode.org/media/#sound].
I'll remember that for next time
>
clipFile = new File("C:/WINDOWS/Media/CHIMES.wav");
..That will not work at time of deployment. At least, not without jumping through many hoops first. It is better to get used to working with URLs (most Java methods that will accept a File will also accept an URL) & to form the URL using something like..
clipURL = this.getClass().getResource("Media/CHIMES.wav");
I started off using a URL, but was having problems so just dropped it. When you say jumping through hoops, do you mean using the File object or specifically pointing to the wav file I selected? I'm asking because I'm only using the CHIMES wav during development; once the program is finished, the user will be selecting the wav file to be played.
Thanks again for your help.

Similar Messages

  • How do I lock Audio clip at playhead in iMovie

    Hi,
    I have been using iMovie HD for years.  Great program.  Finally had to move on to iMovie 10.  What a total disaster that is.  I have a myriad of issues with it, as does everyone else, but right now I am trying to figure out how to lock an audio clip at the playhead, as one essentially needs to be able to do for even pretty simple home movie edits.  Am I being stupid or has this functionality been entirely removed by some genius Apple programmer?  Why do I get the feeling that what used to be a brilliant and intuitive piece of software has been  completely eviscerated to the point of uselessness?
    Any ideas?  Thanks
    Richard

    Richard Weston-Smith1 wrote:
    Am I being stupid or has this functionality been entirely removed by some genius Apple programmer?
    No, it's not been removed. You just need to drag your audio clip to the right place.
    In your case, you want to drag it directly to the timeline and not to the background music well below the timeline.
    Some more information here:
    http://help.apple.com/imovie/mac/10.0/#mov91a895a64
    Matt

  • Can't Move Audio Clip

    I need to shift and audio clip and I can't move it. There is a gray line a the top of the clip that does not appear on other clips, but I don't know what this means. I can shorten or lengthen the clip, but I can't move it. At the far right top is a button that indicates that I can speed up or slow down the clip and this button doesn't appear on the other clips. Occasionally a box pops up to let me say if this is a custom or a present and it currently is custom at 100 percent. The clip is highlighted in yellow, which would seem to indicate I can move it, but I can't. I'd appreciate help on how to fix this.
    Thanks.

    hmmm... It seems to be a new big problem, I'm having the same issue...
    But with iMovie HD 6
    I'm using Mavericks and I import a movie file into iMovie HD, then an audio file (I've tried mp3 and aiff) and both play, video and audio. Then I have to edit the audio file to sync with the video, and then is when iMovie HD freezes.
    I've deleted the preferences (now iMovie opens only the menu, but the project doesn't appear at all, only that colourful loading icon forever ) I've repaired the permissions   restarted every single time and still nothing...
    IS THERE ANYONE TO help us out, please?
    Rubia

  • Syncing multi audio clips to video

    I need to sync multiple audio clips with a video clip.  I have footage that was shot that had multiple people in the scene so multiple mics boom etc.  However whenever I select the video clip and the 4 audio clips and click syncronize clips it only syncronizes one audio with the clip?
    How do I get all the audio clips synced with the video clip?

    DJ Duke wrote:
    Yeah, I did open the sync clip and the audio files are there ( in a different unique sync timeline), but that doesn't help because I need top open them in the regular timeline I use for editing the project and opnly one audio file shows up.
    Any suggestions how to fix this or work around?
    This is the way it works. The synchronized clip is a compound clip. You add it to your timeline. If necessary, you can open it by double-clicking it in the timeline, make the necessary edits, and hit the back button (the little triangle at the top left of the timeline) to return to the project timeline.
    If you do not want it collapsed that way, but you rather insist on seeing all the connected audio clips directly in your project, then you have two options:
    1) select the compound clip in the timeline and choose "Clip->Break Apart Clip Items"
    or
    2) open the compound clip, select everything, copy; and then paste wherever you want it in your project.

  • I have just opened my brand new Macbook Pro and I'm a first time mac user. I have tried to download flash to enable me to watch you tube clips, but on trying to download it, it says I need to close Safari but after doing so, it still won't respond.

    I have just opened my brand new Macbook Pro and I'm a first time mac user. I have tried to download flash to enable me to watch youtube clips, but on trying to download it, it says I need to close Safari but after doing so, it still won't respond. Any tips? Help?

    Actually you need to quit Safari which is different from closing.  With Safari open go the menu bar for Safari/Quit Safari. 
    Mac 101:  Get Started Using A Mac 

  • Need to move audio clip to primary storyline without disturbing sync

    I had a video clip in the primary storyline from which I detached the audio. I then lifted the clip by selecting it and clicking option-cmd-up arrow. What is the simplest way, preferably with keyboard shortcuts rather than dragging, of putting the audio clip in the primary storyline in sync with the video?
    Here's a screen shot of my timeline after detaching the audio and lifting the video:

    AFAICT you need to have some video clip to make that work. The following workaround is a bit messy, but can do the trick.
    1) Add some short video clip connected below the audio (it can be a placeholder or a gap, or something else)
    2) Select the audio and the dummy video and make that a compound clip (option-G)
    3) Select the compound and command-option-downArrow to overwrite to the primary.
    3) break apart the compound clip (select it and do Clip->Break Apart Clip Items, or Cmd-Shift-G)
    4) delete the dummy video

  • What do you do if you need to adjust the audio mid clip?

    In Final cut X can you adjust the audio in the middle of a clip? It seems that the fades are only at the beginning and end of each clip. What do you do if you need to adjust the audio mid clip?

    Range tool (click R)
    select range
    drag audio line ...

  • My friend has a website that he puts audio clips on, and although I can play them on my computer, I can't play them on my phone. Is there a special app I need?

    My friend has a website that he puts audio clips on, and although I can play them on my computer, I can't play them on my phone. Is there a special app I need?

    see if this app suits your needs http://itunes.apple.com/us/app/imedia-player/id544635606?mt=8

  • PLEASE NEED HELP! CAN'T COMBINE AUDIO CLIPS AS ONE FULL CLIP!

    I am getting very frustrated! I have split two audio clips and want to join them together to create one audio clip (the audio is of the same song, just split) There is other audio before the clip that I split that I got rid of, so now I just have the one song as a full song combined together in imovie 6, but when I take it out of imovie it plays everything! including what I deleted!
    so, is there a way I can transfer what I have in imovie 6 (which are two .wav files) and import it into itunes as an mp3 file?

    I happened to come across this discussion in another forum. Maybe it would help you. Check it out:
    http://discussions.apple.com/thread.jspa?messageID=6888437&#6888437
    Good luck.

  • How do I train Slippery Audio Clips?

    I'm guessing this one has an easy answer. When I have the audio track open and I wish to lay down a piece of audio under video (I've already extracted the audio and it's a stand alone piece of audio), I place the playhead where I want the piece of audio to appear, but when I click "paste" the piece of audio always ends up a few inches (or a few shots) away from the playhead (so I have to "inch" it back to its proper place using the playhead). Why does this happen and how can I paste audio clips exactly where I want them?
    Diana

    Interestingly, today I needed to copy and paste an audio clip, and it pasted quite close to the original. Last night, all the pasted clips ended up near the end of the movie.
    I find that the clips can be dragged fairly quickly if dragged to the edge of the iMovie window, but if you do that too quickly, your clip will suddenly end up far to the left of where you want it.
    It took me several attempts to achieve better control when moving a clip, but it is not the ideal solution.

  • AA3 library of audio clips and saving session

    Either I have lost my mind, or I've changed a setting somehow, or I'm just now noticing something that may have been this way forever. I could swear if you have 5 audio clips in your library and only 3 in the multi-track, when you save the session, all 5 clips should still be in the library when you re-open the session. I have not chosen to "close unused media" at any time.
    In trouble-shooting, I open AA3 with an empty library, import 5 files into the library, save session, close session, attempt to open session (and looking at the "component files" box while in the "open" dialog), I do not see any files in this area. I have "show file info" checked. I can understand if no files are in the multi-track, this list would be empty, but it should still show what files are in the library panel.
    If I go back to where I've imported 5 files into the library, place 1 clip in the multi-track, save session, close it, re-open the session, only 1 file is in the library. This is strange to me because I could swear I've been able to import all the files I might need for that session and keep them in the library until I'm ready to place them in the multi-track and I could save and open as many times as needed (while never choosing to close unused media), and all the files I imported would remain in the library regardless - almost like AA3 is automatically closing unused media and deleting those clips from my library. Is this the way it is and I'm just now noticing this? I've worked with AA3 since it was released...

    My impression is the same as your's but I'm not at my studio PC at the moment to try it.
    You can use this tool to see exactly what files (along with some other useful things) are being used in an AA session once you exit AA.
    http://www.suitespotstudios.com/MediaSweeper.htm

  • Inserting audio clips so that the following clips "shift" over

    In ProTools, it's possible to insert an audio clip at a particular location in a track and the clips behind the inserted one will automatically shift over so that the clip can "fit". Is this possible in Audition? Or do I need to move all my clips to the right first to make room for the clip that I want to insert?
    Also, when I use Ripple delete to close the gaps between edited clips, the clips move around and I have to move them again so that they're not out of order. What am I doing wrong here?
    Thank you!

    LuisaEmmi wrote:
    In ProTools, it's possible to insert an audio clip at a particular location in a track and the clips behind the inserted one will automatically shift over so that the clip can "fit". Is this possible in Audition? Or do I need to move all my clips to the right first to make room for the clip that I want to insert?
    I'm not aware of being able to 'ripple insert', and I couldn't find a way of doing it in CS6 - not that I'd use it, because it's relatively easy to move everything anyway if you're organised, and nothing ends up quite where you want it if you work like this anyway...
    Also, when I use Ripple delete to close the gaps between edited clips, the clips move around and I have to move them again so that they're not out of order. What am I doing wrong here?
    That's the thing about organising things; your friend here is clip grouping. Swipe the clips you want to group, and if you use the right mouse button, you'll get grouping options (also available as keyboard shortcuts). One useful feature of this is that Ctrl-Shift G toggles, so you can selectively ungroup and regroup quickly.
    What usually happens at this point is that somebody comes along and tells you how to do whatever it is that I say you can't do, but if there is a way - well, it's not blatently obvious.

  • Locking Audio Clips etc

    I might be barking up the wrong tree here, but I have this feeling that I'm close to what I want to do, but I'm missing something as it's not quite working as I hoped it would.
    Here's what I want to be able to do:
    The scenario: I'm interviewing someone about, for example, their classic Harley Davidson Motorbike and during the interview I want the speech to remain throughout the whole movie, but I want to be able to "cut away" to shots of the bike, then come back to the person speaking at the exact right moment using editing in iMovie. How would I do this?
    Thanks

    1. Extract the Audio from the the video clip (Advanced/Extract Audio). You will then have an audio clip on the audio line right below your video clip. Leave it there. The original audio in your video clip will be muted. You will be using the extracted audio clip for your audio.
    2. Split the video clip at the point where you want to insert the photo.
    3. Insert the photo at the point of the split.
    4. Subtract (trim back) a time equal to the duration of your photo from the front portion of the split clip following the photo. (You will need first to turn off Show Clip Volume Levels from the View menu.) Your photo is being substituted in the place of that portion of the video that you are trimming back.
    The above procedure will give you a continuous, uninterrupted, voice over for all of the photos that you insert. If you don't want a voice over while the photo is displayed, then just split the video clip without extracting the audio, insert the photo, and after the photo is displayed the the video and the voice will pick up where it left off.

  • Adobe Audition has encountered a problem and needs to close.

    I have been using Audition 2.0 on this computer for quite some time and suddenly now when I open it, I get the cryptic error dialogue:
    "Adobe Audition has encountered a problem and needs to close.  We are sorry for the inconvenience.  If you were in the middle of something, the information you were working on might be lost.  For more information about this error, click here."
    When I click for more information, it's something useless like:
    AppName: audition.exe    AppVer: 2.0.5306.2    ModName: unknown
    ModVer: 0.0.0.0   Offset: 65726168
    Nothing on my computer has changed.  There are no viruses.  I have not added any new audio plug-ins.  I am completely up to date with all critical Windows XP SP3 updates and none have been downloaded and installed recently anyway.
    I searched the knowledgebase and found a document that suggesting many things to try.  I tried them all, including running the Windows hard disk "check disk" tool with options to fix file system errors and recover bad sectors. I also defragmented the hard drive.  Lastly, I completely uninstalled Audition, then  manually deleted any remaining files, including registry entries as suggested in another knowledgebase article.
    I then re-installed Audition 2.0 and it did exactly the same thing!  This it maddening.  Now it gets even more interesting.  I discovered that if I start up the
    Adobe ExtendScript Toolkit that Adobe Audition installed also, then try to launch Audition from the toolkit, IT STARTS CORRECTLY!  I can then close the toolkit and use it like normal.  Weird work-around.
    What the heck could possibly be going on?  Anyone have any ideas?  I've attached the error log file that is generated by the error but I doubt it will be of much help.
    Thanks!
    Steve in Chicago

    stevefoobar2: I may have found a solution for you.
    I had the same thing happen to me today. I was using Audition 2 this morning without any problems. But this afternoon, it started giving me the exact same error with no apparent reason. Nothing on my system had changed.
    So I uninstalled it and installed Audition 3 in its place. Audition 3 continued to have the same problem that Audition 2 had, so we can assume that this is not something that was changed between versions.
    But my attention was brought to the fact that you and I are both running Windows XP SP3 fully up-to-date. So I thought I'd try seeing it from the angle of a problem with Windows instead of Audition, and see if I didn't get a better result -
    First, I logged on to Windows as Administrator. This may or may not be required, but you'll probably want to do it just in case (you'll see what I mean later). At this point, Audition still crashed the same way when I opened it, so I moved on to my next troubleshooting strategy -
    Instead of opening Audition directly, I right-clicked the Audition icon and selected "Run as..." This may seem odd since I was already logged in as Administrator, but it proved to be the solution in my case.
    In the "Run As" diolog, there are two main options: run as current user, or run as another user.
    Since I was already logged in as Administrator, I could safely select the first option (run as current user). But here's the catch: selecting the first option allowed me to UNcheck the box underneath that says "Protect my computer and data from unauthorized program activity" (see the attached picture)
    Audition opened without any problems when I did this.
    This makes me think that one of the Windows security features suddenly decided to block something that Audition was trying to do, crashing the program in the process. By turning off this security feature, the problem was solved. And I only had to do it once. Every time afterwards, Audition has opened without any problems when I simply open it from my desktop. Perhaps Windows now remembers not to block Audition in the future.
    However, I have not restarted my computer yet, or logged off as Administrator. You may need to tweak this solution if you plan to do either of these things. You may end up having to "Run as" Audition every time you restart your computer or log off. You may even need to select the SECOND option, and run the program as Administrator with the appropriate password.
    Anyway, this was the only post I could find on Adobe.com concerning this problem, so I thought I'd post my solution in case it helped someone else.

  • InterVideo WinDVR Application has encountered a problem and needs to close.

    My TV Anywhere has suddenly stopoed working and the message "InterVideo WinDVR Application has encountered a problem and needs to close.  We are sorry for the inconvenience." appears each time I try to open the program.  MSI Radio works fine.  I have uninstalled and re-installed the programe (originally MSIPVS now MSIPVS3). I did try to download the new Beta drivers just to try, but the zip file shows 0 bytes!
    Has anyone come across this, or can anyone suggest what I can try to resolve the issue?
    Many thanks in anticipation
    Gareth

    Jeremy:
    I should point out that I am much more confident with software issues.  I am not a hardware person and  have never attempted to open up the box!
    Realtek is the card on the motherboard. 
    I hope this is the information required:
    OS Information:
    Property   Value
    OS Name       Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1
    Service Pack       2.0
    OS Manufacturer       Microsoft Corporation
    Windows Directory       C:\WINDOWS
    Processor:
    Property   Value
    Current Clock Speed       3000
    Description       x86 Family 15 Model 2 Stepping 9
    Manufacturer       GenuineIntel
    Name        Intel(R) Pentium(R) 4 CPU 3.00GHz
    Memory (RAM):
    Property   Value
    Bank Label       RAS 0 & 1
    Capacity       536870912
    Bank Label       RAS 2 & 3
    Capacity       536870912
    Total Memory Deteced in Hardware: ~1024 MB
    Memory Reported to Operating System: 1023MB
    Disk Drives:
    Property   Value
    Description       Disk drive
    Manufacturer       (Standard disk drives)
    Model       Maxtor 6Y160M0
    Media Type       Fixed hard disk media
    Size       163921605120 (~153 GB)
    Number of Partitions       2
    Description       Disk drive
    Manufacturer       (Standard disk drives)
    Model       Canon MP Memory Card USB Device
    Media Type      
    Number of Partitions      
    Description       Disk drive
    Manufacturer       (Standard disk drives)
    Model       IC35L060 AVV207-0 USB Device
    Media Type       Fixed hard disk media
    Size       61492193280 (~57 GB)
    Number of Partitions       1
    Installed Printers:
    Property   Value
    Name       PaperPort Color Image
    Port Name       BIPORT
    Default       False
    Driver Name       PaperPort Color Printer Driver
    Name       PaperPort Black & White Image
    Port Name       BIPORT
    Default       False
    Driver Name       PaperPort Mono Printer Driver
    Name       Microsoft Office Document Image Writer
    Port Name       Microsoft Document Imaging Writer Port:
    Default       False
    Driver Name       Microsoft Office Document Image Writer Driver
    Name       Generic / Text Only
    Port Name       LPT1:
    Default       False
    Driver Name       Generic / Text Only
    Name       Canon MP370 Series Printer
    Port Name       USB001
    Default       True
    Driver Name       Canon MP370 Series Printer
    Name       Auto Microsoft Office Document Image Writer on GARETH-14ETIB74
    Port Name       \\GARETH-14ETIB74\Printer
    Default       False
    Driver Name       Microsoft Office Document Image Writer Driver
    Motherboard:
    Property   Value
    Manufacturer       MICRO-STAR INC.
    Model      
    Name       Base Board
    Part Number      
    Product       MS-6758
    Serial Number       00000000
    Version       2.00
    BIOS:
    Property   Value
    Manufacturer       American Megatrends Inc.
    Name       Version 1.00
    Release Date       20040324000000.000000+000
    Version       AMIINT - 10
    Monitor:
    Property   Value
    Description        SyncMaster 173V/172V/173S/173B
    Name        SyncMaster 173V/172V/173S/173B
    Screen Height       768
    Screen Width       1024
    Keyboard:
    Property   Value
    Description       Easy Internet Keyboard
    Pointing Device:
    Property   Value
    Manufacturer       Logitech
    Name       HID-compliant Wheel Mouse
    Sound Card:
    Property   Value
    Manufacturer       Creative Technology, Ltd.
    Description       Creative EMU10K1 Audio Processor (WDM)
    Device ID       PCI\VEN_1102&DEV_0002&SUBSYS_80661102&REV_0A\4&1F7DBC9F&0&08F0
    Manufacturer       Realtek
    Description       Realtek AC'97 Audio
    Device ID       PCI\VEN_8086&DEV_24D5&SUBSYS_75851462&REV_02\3&13C0B0C5&0&FD
    Video Card:
    Property   Value
    Adapter Compatibility       NVIDIA
    Adapter RAM       268435456
    Description       NVIDIA GeForce FX 5600XT
    Installed Display Drivers       nv4_disp.dll
    Driver Version       6.14.10.6693
    Driver Date       29/10/2004 16:50:00
    Video Mode Description       1024 x 768 x 4294967296 colors
    DirectX Installation:
    Property   Value
    Version       6.03.01.0146
    Modem:
    Property   Value
    Network Adapters:
    Property   Value
    Description       Intel(R) PRO/1000 CT Network Connection - Packet Scheduler Miniport
    Description       Packet Scheduler Miniport
    Description       Microsoft TV/Video Connection
    Description       1394 Net Adapter
    Description       1394 Net Adapter
    External Ports:
    Property   Value
    External Reference Designator       Def
    External Reference Designator       Sanjoy
    Expansion Slots:
    Property   Value
    Slot Designation       PCI1
    Slot Designation       PCI2
    Slot Designation       PCI3
    Slot Designation       PCI4
    Slot Designation       PCI5
    Slot Designation       AGP
    Copy To Clipboard
    I do very much appreciate the help from you all!
    Gareth

Maybe you are looking for