SourceDataLine.write () and TargetDataLine.read () mask interruptions?

I come back to an old problem and decided to fully understand before you continue using my workaround solution. I have a loop that reads from a TDL in a dedicated Thread. To complete the audio capture, I would like to interrupt this Thread causing Cleanup (narrow lines, etc.) and put an end to this Thread. I've found that the interruption works only intermittently. Adding diagnostics to the loop, I see that the interruption indicator is set before the call to TDL.read (), and then immediately after his return from TDL.read () is not defined. (I use the Thread.currentThread () .isInterrupted () way to do not to clear the flag with the actual query)
  while (true) {
    Thread.currentThread().interrupt(); // sets interrupt flag
    System.out.println("Interrupt flag is " + (Thread.currentThread().isInterrupted()?"":"not ") + "set before read()"); // does not modify interrupt flag
    mySourceDataLine.read(buffer,0,length);
    System.out.println("Interrupt flag is " + (Thread.currentThread().isInterrupted()?"":"not ") + "set after read()");  // does not modify interrupt flag
    if (Thread.interrupted()) { // clears interrupt flag if set
      System.out.println("I was interrupted");
    }
}
Based on the intermittent behavior, I concluded that I did something wrong (or it's always false - like interrupting the wrong Thread or by querying the wrong thread to see if it is paused). I'm guessing that in the method of reading, if the SDL buffer playback is blocked, read waits until notification that there is data to read. I wonder if the interruption occurs during the wait, if it is deleted? That would explain the behavior that I've seen (the only pausible explanation) I can get). If that's true, surely others have encountered this problem before; Looks like a common template to use (and not obvious and frustrating!)

My solution is to use my own 'flag' interrupt and test it in the loop. I did this month, when under pressure of the calendar, I came across the same problem with TDL.write (). I want to understand the exact cause of this to be sure that I am not wrong in thinking that my code works correctly when it actually isn't and not bad bites me more later. I looked for the source to test my hypothesis, but since TDL/SDL/DL are interfaces I can't seem to find the source. I attribute this to the fact that the implementation is machine / his specific card.

I prefer to use the method of interrupt his mind that it would be cleaner and more consistent by using features existing, supported by the implementation of Java.

Thank you.

Published by: ags on 23 April 2012 17:32

I found this in com.sun.media.sound.MixerSourceLine extends AbstractDataLine implements SourceDataLine:

         if (totalBytesWritten < totalBytesToWrite) {

          synchronized(lock) {
              try {
               // $$kk: 08.17.99: need to make sure we never block forever here!
               //
               // ivg: Well, it does hang in some cases.
               //      I can reproduce that with JMF by starting and closing
               //      DataLines.  I suspect this lock is not released when
               //      the DataLine is closed.  This is highly timing sensitive.
               //     It doesn't look like we have a good case of concurrent
               //      programming here.  I put in a time out value in the
               //      wait so it will wake up itself to check.  Not optimal.
               lock.wait(2000);
              } catch (InterruptedException e) {
              }
          }
         }

Shocking work, but it seems to take into account at least part of your problem. Is there something similar in com.sun.media.sound.DirectAudioDevice.

Looks like you can mitigate by using a smaller buffer, so (totalBytesWritten< totalbytestowrite)="" happens="" less="" often.="" i="" was="" going="" to="" recommend="" doing="" that="" anyway;="" it="" means="" that="" you="" will="" spend="" more="" time="" in="" your="" own="" loop="" code="" rather="" than="" inside="" this="" thing,="" which="" gives="" you="" more="" opportunity="" to="" catch="" interruptedexception="">

Tags: Java

Similar Questions

  • where can I get the application of the excell and writer and pdf reader

    Where can I get reading apps, is calculating as in Mobile Android (pdf etc.)

    Hi marvelouse,.

    Unfortunately, it is not possible to install Android .apk on Firefox OS.

    If, however, the application has a web - app or the mobile version of its Web site available, you can access these services and pin them to your home screen of Firefox for the operating system.

    Alternatively, you can contact the developers and ask that they create a version compatible with Firefox OS and the open Web.

    -Ralph

  • Help? the source volume is read-write and can not be disassembled...

    I use 10.11.5 on an iMac 21.5 ", end of 2009 and I want to restore the OS X 10.11.5 to HD on an external drive but I get this message" Source volume is read = write and cannot be disassembled, so it cannot be copied from block. "  I can find answers do not address El Capitan.  Help would be greatly appreciated.

    .. .Goldie

    You use disk utility's restore feature?

    If the HD has a recovery partition, you can make starting in place of the recovery.

    Or you can use SuperDuper! (the basic version is free and can copy the entire disk, the paid version allows "smart updates", which copies only files that are different, saving time) running on externally to perform the copy.

  • Enter a share with read rights and have read/write rights

    I have a folder with my photos on my Mac. In this folder, I have all my photos in subfolders and will add new pictures once I created the share. I want to make them accessible to my family there own PC/Mac. But only with READ ONLY. My problem is that a user (account to share on my Mac) with reading rights can access my shared with read/write rights.

    I have my Mac with 10.11.2 the following users/groups:

    • (Jens) My Admin account
    • (Erika) Account sharing
    • (Family) A group

    Group of members of the family are:

    • Jens
    • Erika

    My folder permissions to "/ Volumes/ExtHD/Bilder" are:

    • Family: read
    • Jens: Read/write
    • everyone: read

    I enabled file sharing in the system settings and the 'Pictures' folder added to the share list.

    Now I go to another Mac with Yosemite, go to network in the Finder, select the computer with the share, connect to the "Erika" and open the folder "pictures". I can generate records or files, delete files, so I have read/write rights. Why?

    Finder don't show me no option 'Erika' should have rights to write to this folder. Why is she able to delete files?

    If get you information on the drive, it is the checkbox ignore verified property?

    What is the format of the disc?

  • Why are there at - it such a delay, write and read a PWM signal to digital input?

    Hello!  I am trying to read and take action on a PWM signal.  The equiptment I'll have access to: 9201, 9425 and cDAQ-9172 chassis of NOR.

    That's kind of what I'm experimenting with now (I have tested with a device USB 6211).  Someone at - it a better idea how to do that?

    The problems that I encounter:

    (1) it seems there be then buffering of questions?

    (2) it takes too long.

    My vi is attached.

    Thanks in advance for any help you can give.

    Also, in my final application, I will not have to create the PWM signal - this is just to test the acquisition currently.

    Try to use functions DAQmx directly rather than the DAQ Assistant.  They are a little more work to learn but are more effective.  Your 6211 can generate a PWM signal in hardware, so use it (see examples of LabVIEW).  Finally, of course there will be some delay in your code.  You read to 1.5 k samples to 1 k/second, so each loop cycle will be 1.5 s.

    EDIT: also, why you write 1 k samples and then read 1.5 k, both 1 k per second?  This means that your output will not generate any signal for long periods of time...

  • error timeout on write and read VISA

    I'm having problems of error timeout with a VI who just writes and reads the necessary data and will be eventually added as a Subvi. Everything is set up the same as my camera. I tried to increase the timeout for the session, but it does not work and I don't know what else to try.

    Any help would be appreciated!

    The \r is the termination character (carriage return) and YOU set the constant/control channel for------display Codes. It is a right click option.

    The driver is located by help > find the instrument Drivers. The driver page main has links on what makes a driver is and how to use a.

    http://www.NI.com/downloads/instrument-drivers/

  • NEITHER the 6602 write and read frequency

    Hi all

    I have NEITHER 6602 calendar card and I am trying to use it to write and read from the

    DAQmxWriteCtrFreq (taskHandle1, 0, 1, 10.0, DAQmx_Val_GroupByChannel, & freq, & duty, & writtenVal, 0);

    and

    You should have the following sample installed on your PC that can help you in this task: DigPulseTrain - Cont.prj (it could be found in \program files\National Instruments\CVIx\samples\daqmx\counter\generate pulse folder)

  • I have PC toshiba laptop, my cd/dvd. writer does not read the CD software and not able to write the media__

    itshow msg

    Insert the disc pls

    Hello

    Step 1: Please do all the same underneath if you did some before as is often total
    a process that solves the problem.

    Try this - Panel - Device Manager - CD/DVD - double click on the device - driver tab.
    Click on update drivers (this will probably do nothing) - RIGHT click ON the drive - uninstall.
    RESTART this will refresh the default driver stack. Even if the reader does not appear to continue
    below.

    Then, work your way through these - don't forget the drive might be bad, could be a coward
    cable or slight corrosion on the contacts (usually for a laptop) and other issues.

    Your CD or DVD drive is missing or is not recognized by Windows or other programs
    http://support.microsoft.com/kb/314060 - a Mr Fixit

    Try this fix manually if the Fixit 314060 does not work
    http://www.pchell.com/hardware/cd_drive_error_code_39.shtml

    Your CD or DVD drive is missing or is not recognized by Windows or other programs-
    a Mr Fixit
    http://support.Microsoft.com/kb/982116

    The CD drive or the DVD drive does not work as expected on a computer that you upgraded to
    for Windows Vista
    http://support.Microsoft.com/kb/929461

    When you insert a CD or a DVD, Windows Vista may not recognize the disc
    http://support.Microsoft.com/kb/939052

    Your CD or DVD drive cannot read or write media - A Mr Fixit
    http://support.Microsoft.com/GP/cd_dvd_drive_problems

    CD/DVD drive does not appear in Windows Vista, or you receive this error in Windows
    Vista installation after booting from the DVD (AHCI)
    http://support.Microsoft.com/kb/952951
    Drive CD - R or CD - RW Drive is not recognized as a recordable device
    http://support.Microsoft.com/kb/316529/

    Hardware devices not detected or not working - A Mr Fixit
    http://support.Microsoft.com/GP/hardware_device_problems

    Another possibility is that the cables are loose. Remove ALL power, then make sure that the cables in both
    ends. Remove and replace, do not just tight. For laptops, you can often clean power and
    contacts data with a pencil eraser.

    Some DVD players do not use the Windows default drivers so check with the manufacturer of system and
    manufacturer of device to see if there is a firmware or drivers for your drive if necessary.

    ===============================

    Step 2: You have disc problems as the CD/DVD is actually 4 discs in 1 case (CD & DVD
    Burn and CD and DVD read). So it is not unusual for 1 or 2 operational so that other parts
    do it right.

    Did you follow the Troubleshooting Guide for the reader who still does not work? There are
    the entries in registry that the troubleshooter does not solve and those who "might" be the cause.

    Check with your Maker system and a device for the two possible firmware updates and
    the correct registry entries for your car.

    Here are the keys that I of course are those in question - for the subkeys of the CD/DVD drive
    as there will be other subkeys in these keys. Do not forget to ask specific keys involved as well as
    the parameters.

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\0001\System\CurrentControlSet\Enum\IDE

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\ {4D36E965-E325-11CE-BFC1-08002BE10318}

    -----------------------------------------------------------------------

    You can probably find more info here and maybe even the exact registry for your CD/DVD settings
    drive from someone with the same model.

    Forums - a lot of expert real help
    http://Club.myce.com/

    CD/DVD units
    http://www.myce.com/storage/

    Use DevManView to locate the CD/DVD in the registry (be careful and do a prior Restore Point)
    nothing change) - find the DevManView device and then make a right click on it free in RegEdit.

    DevManView - free - an alternative to the standard Windows Device Manager, which displays all the
    devices and their properties in flat table, instead of the tree viewer
    http://www.NirSoft.NET/utils/device_manager_view.html

    ===============================================================

    Check with Toshiba support, their drivers online (update or reinstall) and their forums.

    Toshiba - Forums
    http://laptopforums.Toshiba.com/

    Toshiba - Contacts
    http://www.CSD.Toshiba.com/cgi-bin/TAIS/support/JSP/navShell.jsp?CF=su_contact

    Toshiba - drivers - access your model
    http://www.CSD.Toshiba.com/cgi-bin/TAIS/support/JSP/home.jsp?NAV=download

    Toshiba - Support
    http://www.CSD.Toshiba.com/cgi-bin/TAIS/support/JSP/home.jsp

    I hope this helps.

    Rob Brown - MS MVP - Windows Desktop Experience: Bike - Mark Twain said it right.

  • Write and read files 8859_1 but miss char

    Hi all!
    I tried to write heart (♥) tank in a text file on Windows, but to re-read when the return was a question mark (?).

    I wrote and read with codes like:
    String iso = "8859_1";
    
    [...]
    BufferedWriter bufferedWriter = null;
    try {
         bufferedWriter = new BufferedWriter(
              new BufferedWriter(new OutputStreamWriter(new DataOutputStream(new FileOutputStream(file)), iso));
    } catch (FileNotFoundException e) {}
    
    [...]
    BufferedReader bufferedReader = null;
    try {
         bufferedReader = new BufferedReader(
              new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(file)), iso))
    } catch (FileNotFoundException e) {}
    What is wrong with him?

    I'm worried because I want to write the encrypted text in the future... and so I'm worried I may lose some data if encrypted text includes characters that are not written / read in the right track to be decripted!

    Patcha wrote:
    Hello.
    Sorry to get back to.
    I want just one last question (somewhat strange)...

    Is there a way to simulate a write and read entry and exit flows without actually writing a file?

    The javadocs are your friend, you know. If you check out the javadoc for InputStream for example:

    http://docs.Oracle.com/javase/7/docs/API/Java/IO/InputStream.html

    Check out the "direct known subclasses. I'm sure you're smart enough to not need more than information to determine what your options are. You just need to know where to get information!

    And of course, there is no one stopping you to create your own stream of input/output 'false' when there is no option :)

  • SourceDataLine.isActive () and SourceDataLine.isRunning () do not work

    Hi all

    In the code snippet below, the SourceDataLine.isActive () and the SourceDataLine.isRunning () always return true, even though the sound has already finished playing.

    I tested this code in the following platforms: Windows XP x 86, Windows Vista x 86, x86_64 of Windows 7, Linux x 86, and Linux x86_64. I've only had the behavior than I expected (exit the while loop after completing playback of the audio file) on Linux x86_64.
    What's wrong with this code? I'm abusing the API somehow?

    Thank you

    Alex

    import java.io.File;
    Javax.sound.sampled import. *;

    public class Test1 {}

    Public Shared Sub main (String [] args) throws Exception {}
    change this path to a WAV file in your system *.
    Sound of the file file = new File("/arquivo/dados/workspace_3.6.1/test/src/campainha.wav");

    AudioStream AudioInputStream = AudioSystem.getAudioInputStream (soundFile);
    AudioFormat, format = audioStream.getFormat ();

    Line SourceDataLine = AudioSystem.getSourceDataLine (format);
    Line.Open (format);
    Line.Start ();

    data from Byte [] = new ubyte [128000];
    int bytesRead;
    While ((bytesRead = audioStream.read (data))! = - 1) {}
    Line.Write (data, 0, bytesRead);
    }

    While (Line.IsActive () & & line.isRunning ()) {}
    System.out.println ("IsActive () and isRunning() return true.'");
    Thread.Sleep (1000);
    }

    System.out.println ("never gets here...");

    {if (Line.isRunning ())}
    Line.Stop ();
    }
    Line.Close ();

    audioStream.close ();
    }

    }

    In the code snippet below, the SourceDataLine.isActive () and the SourceDataLine.isRunning () always return true, even though the sound has already finished playing.

    isRunning
    boolean isRunning()Indicates whether the line is running. The default is false. An open line begins running when the first data is presented in response to an invocation of the start method, and continues until presentation ceases in response to a call to stop or because playback completes. 
    

    The "complete reading" would be for a Clip and not a normal line, so in this case, the line will continue to return "isRunning" until you close.

    boolean isActive()Indicates whether the line is engaging in active I/O (such as playback or capture). When an inactive line becomes active, it sends a START event to its listeners. Similarly, when an active line becomes inactive, it sends a STOP event. 
    

    Yet once, even case. The line remains active until you call stop on this...

    Looks like you're just trying to detect when the line is running out of data? More than likely, you probably want to base on the amount of data that the line says that it is played.

    int bytesRead;
    long endingPosition = line.getLongFramePosition();
    
    while((bytesRead = audioStream.read(data)) != -1) {
      endingposition += line.write(data, 0, bytesRead);
    }
    
    while(line.getLongFramePosition() < endingPosition) {
    System.out.println("Line is still working");
    Thread.sleep(1000);
    }
    
  • Passing a unique structure through the functions of customer/ServerTCPRead/write and making sure that all data is transferred

    I use the CVI TCP media kit at my request and I am curious about the following code:

    ClientTCPRead

    char * buffer;
    int messageSize;
    int bytesToRead;
    int
    bytesRead;

    / * Find messageSize and allocate a buffer properly... * /.

    bytesToRead = messageSize;

    While (bytesToRead > 0)

    {

    bytesRead = ClientTCPRead (connection handle,
    (& buffer [messageSize - bytesToRead], bytesToRead, 0);

    bytesToRead = bytesRead;

    }

    OK, this works if you tank elements of the array, but what happens if you pass a structure of arbitrary size?  If you read/write the bytes read or written and that you get all the data that you have asked, what do you do at this point to get the rest of subsequent data?  For example, replace the "buffer" of type char with a structure of a type defined by the user with a size of 100 bytes or something to that extent.  You make a request for read/write and read/wrote less than 100 bytes.  How do you get the rest of the data?  ICB doing something in the background?  I could use this code with several structures, but then again, a particular Member of a structure is not the size of a byte as a tank.

    Much appreciated,

    Chris

    The solution is to use a pointer to char sunk to allocate the data transmitted.  The only problem is that this buffer must be a pointer to the data type of the structure before a tank troop can be used for a successful program compilation. Thank you for your help.

    Chris

  • DVD drive will burn discs and not read the content

    my dvd player will be only burn discs... any time I put in a cd of software or audio CDs, it won't let me veiw content... When I put in a cd of software says "Please insert the disk" and ejects the cd. When I put a CD audo (burned) it gives me just the ability to add files to a cd. thinking it was a problem with the drive its self, I bought an external dvd drive and it does the same thing. I can't understand why he won't let me see or install any content of a cd, any help or point in the right direction would be really useful thanks.

    Hello

    You have disk problems as the CD/DVD is actually 4 discs in 1 case (CD & DVD burn
    and CD and DVD read). So it is not unusual for 1 or 2 operational so that other parts
    do it right.

    CD have a tolerance + - and you can read on the edge outside their tolerance. They
    may be released but it is usually more economical to replace the disk.

    Several good info here:
    http://Club.myce.com/

    Notes on the troubleshooting and repair of readers of compact disks and CD-ROM Drives
    http://www.repairfaq.org/repair/F_cdfaq7.html#CDFAQ_014

    -----------------------------------------------------------------------

    Try this troubleshooting:

    Try this - Panel - Device Manager - CD/DVD - double click on the device - driver tab.
    Click on update drivers (this will probably do nothing) - RIGHT click ON the drive - uninstall.
    RESTART this will refresh the default driver stack. Even if the reader does not appear to continue
    below.

    Then, work your way through these - don't forget the drive might be bad, could be a coward
    cable or slight corrosion on the contacts (usually for a laptop) and other issues.

    Your CD or DVD drive is missing or is not recognized by Windows or other programs
    http://support.microsoft.com/kb/314060 - a Mr Fixit

    The CD drive or the DVD drive does not work as expected on a computer that you upgraded to
    for Windows Vista
    http://support.Microsoft.com/kb/929461

    When you insert a CD or a DVD, Windows Vista may not recognize the disc
    http://support.Microsoft.com/kb/939052

    Your CD or DVD drive cannot read or write media - A Mr Fixit
    http://support.Microsoft.com/GP/cd_dvd_drive_problems

    CD/DVD drive does not appear in Windows Vista, or you receive this error in Windows
    Vista installation after booting from the DVD (AHCI)
    http://support.Microsoft.com/kb/952951
    Drive CD - R or CD - RW Drive is not recognized as a recordable device
    http://support.Microsoft.com/kb/316529/

    Hardware devices not detected or not working - A Mr Fixit
    http://support.Microsoft.com/GP/hardware_device_problems

    Another possibility is that the cables are loose. Remove ALL power, then make sure that the cables in both
    ends. Remove and replace, do not just tight. For laptops, you can often clean power and
    contacts data with a pencil eraser.

    Hope these helps.
    Rob - bicycle - Mark Twain said it is good.

  • DC to Acrobat and Acrobat Reader DC - Option to 'Send comment' back to initiator review is missing?

    Recently reinstalled the software from scratch, including Acrobat Pro DC.

    Receipt by e-mail review request to another writer - when I opened the document, I don't have an option in the upper part of the pdf file to 'Send comment' to the initiator. I know that this was in XI'AN and previous, don't know if it was in DC earlier. Thought that maybe the other writer had just registered as player extended with commenting.

    Now, when I sent today a review by e-mail to an SME that is currently running Acrobat Reader DC, he also had the opportunity to send your comments. I checked with another SME that he always * fact * appear in XI player.

    I hope it's just hidden somewhere in the menus. Does anyone know if the option in a menu somewhere, or if the feature has been removed, or if it is a bug?

    It's like teeth pulling sometimes to get people to make comments, so adding in a smaller dam (forcing them to save the pdf file, and then manually create an email and attach, and then send) only adds to the frustration :-)

    Thank you!

    FOR INFO. 'Send feedback' functions now correctly with the update of DC Acrobat (for Acrobat and Acrobat Reader):

    DC October 2016 (2015.020.20039)

  • I made a video on the iPhone 5 is and it reads at high speed?

    I made a video on the iPhone 5 is and it reads at high speed?

    have you done a video time?

  • I'm trying to import my IE Favorites and have read the instructions on how to do it, but the import button in the file in gray and will not let me import. Any ideas?

    I'm trying to import my IE Favorites and have read the instructions, but the import button in the file in gray and will not let me import. Any ideas?

    Try using the import option in the Bookmark Manager (also known as the name of the library)

    1. In Firefox, select the bookmarks menu, then "organize bookmarks" open library
    2. In the library, select "Import and backup" then "Import HTML.
    3. You should get I hope that the ability to import from Internet Explorer.

Maybe you are looking for

  • LaserJet CP1525nw #CE875A: Color LaserJet CP1525 paper jam.

    Although there is no paper jammed anywhere in the machine, it is blocked in an alert of "paper in the output tray jam." A series of clicks can be heard when the machine is started, until the jam alert lights. This noise is new. The printer is two or

  • 'The unattend answer file contains an invalid product key' cannot install Windows 7

    'The unattend answer file contains an invalid product key' appears during installation of Windows 7 Edition Home Premium with a 3 user license. Cannot complete the installation of the operating system. Suggestions for how to find this answer file?

  • Blue screen Windows 7 32-bit

    I recently started having blue screens on my 32-bit Windows 7 computer.  There is nothing new, other than windows updates.  At first I thought it was the Intel graphics driver which I removed.  Then, I read something on Skype so I removed that.  Alwa

  • NonPersistableObjectException

    Hi people, I get this error on the subject, when I try to open an httpconnection, strange isn't? rsrs... under my PersistenceClass: [code] package mypackage;import net.rim.device.api.system.PersistentObject; import net.rim.device.api.system.Persisten

  • Buy an activation code for Win 7 32 Pro online?

    I tried Win 7 64 RC and loved. I bought Windows 7 Pro at Best Buy. It cam with a version for 32 & 64 bit. 64-bit is on new construction. I installed the 32 bit on an old Sony VAIO VGN A170P running XP Pro. This requires pulling and formatting the har