Source Code Cross Referenced for SourceDataLine.java in  » 6.0-JDK-Core » sound » javax » sound » sampled » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » sound » javax.sound.sampled 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1999-2003 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package javax.sound.sampled;
027
028        /**
029         * A source data line is a data line to which data may be written.  It acts as
030         * a source to its mixer. An application writes audio bytes to a source data line,
031         * which handles the buffering of the bytes and delivers them to the mixer.
032         * The mixer may mix the samples with those from other sources and then deliver
033         * the mix to a target such as an output port (which may represent an audio output    
034         * device on a sound card).
035         * <p>
036         * Note that the naming convention for this interface reflects the relationship
037         * between the line and its mixer.  From the perspective of an application,
038         * a source data line may act as a target for audio data.
039         * <p>
040         * A source data line can be obtained from a mixer by invoking the 
041         * <code>{@link Mixer#getLine getLine}</code> method of <code>Mixer</code> with 
042         * an appropriate <code>{@link DataLine.Info}</code> object.
043         * <p>
044         * The <code>SourceDataLine</code> interface provides a method for writing 
045         * audio data to the data line's buffer. Applications that play or mix 
046         * audio should write data to the source data line quickly enough to keep the 
047         * buffer from underflowing (emptying), which could cause discontinuities in 
048         * the audio that are perceived as clicks.  Applications can use the 
049         * <code>{@link DataLine#available available}</code> method defined in the
050         * <code>DataLine</code> interface to determine the amount of data currently
051         * queued in the data line's buffer.  The amount of data which can be written
052         * to the buffer without blocking is the difference between the buffer size
053         * and the amount of queued data.  If the delivery of audio output 
054         * stops due to underflow, a <code>{@link LineEvent.Type#STOP STOP}</code> event is 
055         * generated.  A <code>{@link LineEvent.Type#START START}</code> event is generated
056         * when the audio output resumes. 
057         *
058         * @author Kara Kytle
059         * @version 1.27 07/05/05
060         * @see Mixer
061         * @see DataLine
062         * @see TargetDataLine
063         * @since 1.3
064         */
065        public interface SourceDataLine extends DataLine {
066
067            /**
068             * Opens the line with the specified format and suggested buffer size,
069             * causing the line to acquire any required
070             * system resources and become operational.
071             * <p>
072             * The buffer size is specified in bytes, but must represent an integral 
073             * number of sample frames.  Invoking this method with a requested buffer 
074             * size that does not meet this requirement may result in an 
075             * IllegalArgumentException.  The actual buffer size for the open line may 
076             * differ from the requested buffer size.  The value actually set may be 
077             * queried by subsequently calling <code>{@link DataLine#getBufferSize}</code>.  
078             * <p>
079             * If this operation succeeds, the line is marked as open, and an 
080             * <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the 
081             * line's listeners.
082             * <p>
083             * Invoking this method on a line which is already open is illegal
084             * and may result in an <code>IllegalStateException</code>.
085             * <p>
086             * Note that some lines, once closed, cannot be reopened.  Attempts
087             * to reopen such a line will always result in a 
088             * <code>LineUnavailableException</code>.
089             *
090             * @param format the desired audio format
091             * @param bufferSize the desired buffer size
092             * @throws LineUnavailableException if the line cannot be
093             * opened due to resource restrictions
094             * @throws IllegalArgumentException if the buffer size does not represent
095             * an integral number of sample frames,
096             * or if <code>format</code> is not fully specified or invalid
097             * @throws IllegalStateException if the line is already open
098             * @throws SecurityException if the line cannot be
099             * opened due to security restrictions
100             *
101             * @see #open(AudioFormat)
102             * @see Line#open
103             * @see Line#close
104             * @see Line#isOpen
105             * @see LineEvent
106             */
107            public void open(AudioFormat format, int bufferSize)
108                    throws LineUnavailableException;
109
110            /**
111             * Opens the line with the specified format, causing the line to acquire any 
112             * required system resources and become operational.  
113             *   
114             * <p>
115             * The implementation chooses a buffer size, which is measured in bytes but 
116             * which encompasses an integral number of sample frames.  The buffer size 
117             * that the system has chosen may be queried by subsequently calling 
118             * <code>{@link DataLine#getBufferSize}</code>.
119             * <p>
120             * If this operation succeeds, the line is marked as open, and an 
121             * <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the 
122             * line's listeners.
123             * <p>
124             * Invoking this method on a line which is already open is illegal
125             * and may result in an <code>IllegalStateException</code>.
126             * <p>
127             * Note that some lines, once closed, cannot be reopened.  Attempts
128             * to reopen such a line will always result in a 
129             * <code>LineUnavailableException</code>.
130             *
131             * @param format the desired audio format
132             * @throws LineUnavailableException if the line cannot be
133             * opened due to resource restrictions
134             * @throws IllegalArgumentException if <code>format</code>
135             * is not fully specified or invalid
136             * @throws IllegalStateException if the line is already open
137             * @throws SecurityException if the line cannot be
138             * opened due to security restrictions
139             *
140             * @see #open(AudioFormat, int)
141             * @see Line#open
142             * @see Line#close
143             * @see Line#isOpen
144             * @see LineEvent
145             */
146            public void open(AudioFormat format)
147                    throws LineUnavailableException;
148
149            /**
150             * Writes audio data to the mixer via this source data line.  The requested 
151             * number of bytes of data are read from the specified array, 
152             * starting at the given offset into the array, and written to the data 
153             * line's buffer.  If the caller attempts to write more data than can 
154             * currently be written (see <code>{@link DataLine#available available}</code>), 
155             * this method blocks until the requested amount of data has been written.  
156             * This applies even if the requested amount of data to write is greater 
157             * than the data line's buffer size.  However, if the data line is closed, 
158             * stopped, or flushed before the requested amount has been written,
159             * the method no longer blocks, but returns the number of bytes 
160             * written thus far. 
161             * <p>
162             * The number of bytes that can be written without blocking can be ascertained
163             * using the <code>{@link DataLine#available available}</code> method of the
164             * <code>DataLine</code> interface.  (While it is guaranteed that
165             * this number of bytes can be written without blocking, there is no guarantee
166             * that attempts to write additional data will block.)
167             * <p>
168             * The number of bytes to write must represent an integral number of
169             * sample frames, such that:
170             * <br>
171             * <center><code>[ bytes written ] % [frame size in bytes ] == 0</code></center>
172             * <br>
173             * The return value will always meet this requirement.  A request to write a 
174             * number of bytes representing a non-integral number of sample frames cannot 
175             * be fulfilled and may result in an <code>IllegalArgumentException</code>.
176             *
177             * @param b a byte array containing data to be written to the data line
178             * @param len the length, in bytes, of the valid data in the array 
179             * (in other words, the requested amount of data to write, in bytes)
180             * @param off the offset from the beginning of the array, in bytes
181             * @return the number of bytes actually written
182             * @throws IllegalArgumentException if the requested number of bytes does
183             * not represent an integral number of sample frames,
184             * or if <code>len</code> is negative
185             * @throws ArrayIndexOutOfBoundsException if <code>off</code> is negative,
186             * or <code>off+len</code> is greater than the length of the array
187             * <code>b</code>.
188             *
189             * @see TargetDataLine#read
190             * @see DataLine#available
191             */
192            public int write(byte[] b, int off, int len);
193
194            /**
195             * Obtains the number of sample frames of audio data that can be written to 
196             * the mixer, via this data line, without blocking.  Note that the return 
197             * value measures sample frames, not bytes. 
198             * @return the number of sample frames currently available for writing
199             * @see TargetDataLine#availableRead
200             */
201            //public int availableWrite();
202        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.