AudioFile

The AudioFile allows reading and writing of sound files. It can operate both on a RandomAccessFile created from a File instance, or on an kind of InputStream (not every codec will support this though, and functionality might be limited, for example seeking is not possible with a plain InputStream).

The codecs are registered with AudioFileType. The codecs that come with AudioFile are found in the impl package.

Reading and writing data requires a user-buffer which holds de-interleaved floating point data, that is a two dimensional Array which holds Double data. A type alias Frames is provided for this, and two helper methods buffer: one static to construct an arbitrary user-buffer, one in class AudioFile which creates a buffer with the appropriate channel number.

See also:

AudioFileType

Todo:

the copyTo method uses a user-buffer. it should check for the possibility to directly transfer data if input and output are compatible.

Companion:
class
class Object
trait Matchable
class Any

Type members

Types

type Frames = Array[Array[Double]]

Value members

Concrete methods

def buffer(numChannels: Int, bufFrames: Int): Frames
@throws(scala.Predef.classOf[java.io.IOException])
def identify(dis: DataInputStream): Option[CanIdentify]
@throws(scala.Predef.classOf[java.io.IOException])
def openRead(is: InputStream): AudioFile
@throws(scala.Predef.classOf[java.io.IOException])
def openReadAsync(uri: URI)(implicit executionContext: ExecutionContext): Future[AsyncAudioFile]

Opens an audio file for asynchronous reading.

Opens an audio file for asynchronous reading.

Value parameters:
uri

the path name of the file

Returns:

a future AsyncAudioFile object whose header is already parsed when the future completes, and that can be obtained through the spec method.

Throws:
java.io.IOException

if the file was not found, could not be reader or has an unknown or unsupported format

@throws(scala.Predef.classOf[java.io.IOException])
def openReadAsync(ch: AsyncReadableByteChannel)(implicit ec: ExecutionContext): Future[AsyncAudioFile]
@throws(scala.Predef.classOf[java.io.IOException])
def openWrite(os: OutputStream, spec: AudioFileSpec): AudioFile
@throws(scala.Predef.classOf[java.io.IOException])
def openWriteAsync(uri: URI, spec: AudioFileSpec)(implicit executionContext: ExecutionContext): Future[AsyncAudioFile]
@throws(scala.Predef.classOf[java.io.IOException])
def openWriteAsync(ch: AsyncWritableByteChannel, spec: AudioFileSpec)(implicit ec: ExecutionContext): Future[AsyncAudioFile]
@throws(scala.Predef.classOf[java.io.IOException])
def readSpec(dis: DataInputStream): AudioFileSpec

Note that this method advances in the provided input stream, its previous position is not reset.

Note that this method advances in the provided input stream, its previous position is not reset.

@throws(scala.Predef.classOf[java.io.IOException])
def readSpecAsync(uri: URI)(implicit executionContext: ExecutionContext): Future[AudioFileSpec]

Inherited methods

@throws(scala.Predef.classOf[java.io.IOException])
def identify(path: String): Option[AudioFileType]
Inherited from:
AudioFilePlatform
@throws(scala.Predef.classOf[java.io.IOException])
def identify(f: File): Option[CanIdentify]

Determines the type of audio file.

Determines the type of audio file.

Value parameters:
f

the pathname of the file

Returns:

the type code as defined in AudioFileInfo, e.g. TYPE_AIFF. Returns TYPE_UNKNOWN if the file could not be identified.

Throws:
java.io.IOException

if the file could not be reader

Inherited from:
AudioFilePlatform
@throws(scala.Predef.classOf[java.io.IOException])
def openRead(f: File): AudioFile

Opens an audio file for reading.

Opens an audio file for reading.

Value parameters:
f

the path name of the file

Returns:

a new AudioFile object whose header is already parsed and can be obtained through the spec method.

Throws:
java.io.IOException

if the file was not found, could not be reader or has an unknown or unsupported format

Inherited from:
AudioFilePlatform
@throws(scala.Predef.classOf[java.io.IOException])
final def openRead(path: String): AudioFile
Inherited from:
ReaderFactoryPlatform
@throws(scala.Predef.classOf[java.io.IOException])
def openWrite(path: String, spec: AudioFileSpec): AudioFile
Inherited from:
AudioFilePlatform
@throws(scala.Predef.classOf[java.io.IOException])
def openWrite(f: File, spec: AudioFileSpec): AudioFile

Opens an audio file for reading/writing. The pathname is determined by the file field of the provided AudioFileInfo. If a file denoted by this path already exists, it will be deleted before opening.

Opens an audio file for reading/writing. The pathname is determined by the file field of the provided AudioFileInfo. If a file denoted by this path already exists, it will be deleted before opening.

Note that the initial audio file header is written immediately. Special tags for the header thus need to be set in the AudioFileInfo before calling this method, including markers and regions. It is not possible to writer markers and regions after the file has been opened (since the header size has to be constant).

Value parameters:
f

the path name of the file.

spec

format and resolution of the new audio file. the header is immediately written to the hard-disc

Throws:
java.io.IOException

if the file could not be created or the format is unsupported

Inherited from:
AudioFilePlatform
@throws(scala.Predef.classOf[java.io.IOException])
def readSpec(path: String): AudioFileSpec
Inherited from:
AudioFilePlatform
@throws(scala.Predef.classOf[java.io.IOException])
def readSpec(f: File): AudioFileSpec
Inherited from:
AudioFilePlatform

Concrete fields

val KEY_DIRECT_MEMORY: String

System property key. The boolean property can be set to true or false. It will only be read once, the first time a buffer is allocated. The default is false. When true, ByteBuffer.allocateDirect is used instead of allocate, possibly using faster direct memory.

System property key. The boolean property can be set to true or false. It will only be read once, the first time a buffer is allocated. The default is false. When true, ByteBuffer.allocateDirect is used instead of allocate, possibly using faster direct memory.

val log: Logger