O1Library Docs
Fall 2023
Docs API

# Sound

o1.sound.sampled.Sound
See the Sound companion object
trait Sound

Each instance of this trait represents a recorded sound sample.

You create `Sound`s with the methods on the companion object: `Sound("my_sound_file.wav")`. The supported formats are WAV, AIFF, AU, AIFC, and SND.

This trait has an alias in the top-level package o1, so it’s accessible to students simply via `import o1.*`.

This type is essentially a wrapper around the key functionality in `javax.sound.sampled`, especially its Clip class.

## Attributes

Companion
  object
Graph
Supertypes
  class Object
  trait Matchable
  class Any

## Members list

### Value members

#### Abstract methods

def isDefined: Boolean

whether the `Sound` object represents a successfully loaded sound sample. This will be `true` if the methods on the companion object successfully loaded the sound from a file or a URL, and `false` if there was a problem

whether the `Sound` object represents a successfully loaded sound sample. This will be `true` if the methods on the companion object successfully loaded the sound from a file or a URL, and `false` if there was a problem

## Attributes

def play(repeats: Int, volume: Float): Unit

Plays the sound sample, possibly multiple times in sequence.

Plays the sound sample, possibly multiple times in sequence.

## Parameters

repeats

  how many additional times the sound should play after being played once; if you pass in `KeepRepeating`, the sound will repeat indefinitely unless stop is called

volume

  you may pass in a number to override the sounds’s default volume adjustment

## Attributes

def stop(): Unit

Stops the playing of the sound sample, previously started with play.

Stops the playing of the sound sample, previously started with play.

## Attributes

def withVolume(differentVolume: Float): Sound

Returns an other `Sound` otherwise identical to this one but with the given volume adjustment.

Returns an other `Sound` otherwise identical to this one but with the given volume adjustment.

## Attributes

#### Concrete methods

override def toString: String

A `String` representation of the sound; equals description.

A `String` representation of the sound; equals description.

## Attributes

Definition Classes
  Any

#### Abstract fields

val description: String

A description of the sound’s origin. Examples:

A description of the sound’s origin. Examples:

- `"../../../../../O1Library/doc"`
- `"http://www.aalto.fi/does_not_exist.wav (failed to create)"`

## Attributes

val volume: Float

an adjustment to the loaded sound sample’s volume: a positive number makes it louder a negative one quieter. A value equal to `Mute` means the sound is completely silent.

an adjustment to the loaded sound sample’s volume: a positive number makes it louder a negative one quieter. A value equal to `Mute` means the sound is completely silent.

## Attributes