Class WaveFileBase
java.lang.Object
|
+----WaveFileBase
- public class WaveFileBase
- extends Object
Class representing an audiofile = wavefile.
Basically, a wavefile is defined by these parameters:
- leftwave, rightwave: These are the arrays containing
the data. No matter of the format (8 or 16bit, au or wav), JaWavedit always
stores 16 bit linear pcm. When loading or saving 8bit or a au
file, appropriate conversion takes place. To get these arrays,
use getLeftWave() respectively getRightWave(). The length of the
arrays (= length in samples) is returned by getSize().
- frequency: This determines the frequency that the
audio data is interpreted. This value affects greatly how it
sounds when played. The frequency is stored in the file on disk. Use
getFrequency() and getFrequency() to work with this parameter.
- resolution: This is either 8 or 16 bit. However, this only
affects the format of a saved file. You always treat a wavefile
as 16bit. When the resolution is 8bit, it will be converted when
saving. You get/set the resolution with the methods getResolution() and setResolution(int).
- mono/stereo: Also this parameter only affects saved files.
You always treat wavefiles as stereo. When saving a mono file, leftwave
and rightwave are mixed together. This parameter is set when loading a file.
Use getChannelCount(), setChannelCount(int), isMono(), isStereo() to get/set
this parameter.
- name: This is the filename. It defaults to "new.au" but is set
when loading a file. It also determines the format of saved files: if the
extension is "au", a file is saved as Sun uLaw, otherwise ("wav") in Microsoft
PCM linear format. Use getName(), setName(String), extractFileName() and extractFilePath()
to get/set the name.
- description: This is an information string which is included in the
file when saving. Use getDescription() and setDescription(String) to get/set this String.
This class is made to always be one instance: When you want to clear, or initialize
with new arrays, call initWave(...). Nonetheless you may create your own instances in
a module.
-
ERROR_OPENING_S
-
-
ERROR_SAVING_S
-
-
IS_CORRUPT_S
-
-
NEITHER_WAV_AU_S
-
-
NOT_CREATE
-
-
NOT_SUPPORTED_S
-
-
Wave
- Helper array for simple module type: SimpleModule.
-
WaveFileBase()
- Initializes a Wavefile.
-
createNew()
- Creates an empty wavefile.
-
createNew(int, short[])
- Creates a new mono wavefile with given frequency.
-
createNew(int, short[], short[])
- Creates a new stereo wavefile with given frequency.
-
extractFileName()
- Returns current name without path.
-
extractFilePath()
- Returns path of current name.
-
getChanged()
- Returns whether this wavefile was changed after latest call to save().
-
getChannelCount()
- Returns number of channels (1:mono, 2:stereo).
-
getCoding()
- Returns extension of this wavefile.
-
getDescription()
- Returns the description string.
-
getFrequency()
- Returns frequency (samples per second) of this wavefile.
-
getLeftWave()
- returns array of left wave-data.
-
getName()
- Returns the filename of this wavefile.
-
getResolution()
- Returns resolution (8 or 16 bit).
-
getRightWave()
- returns array of right wave data.
-
getSize()
- returns number of samples in this wavefile.
-
isEmpty()
- Returns whether this wavefile is empty.
-
isMono()
- Returns whether this wavefile is internally mono.
-
isStereo()
- returns whether this wavefile is internally stereo.
-
load(String)
- Loads "file".
The format (Sun muLaw (".au") or Microsoft PCM (".wav")
is recognized automatically.
-
msToSamples(long)
- Returns the sample position when "ms" milliseconds are elapsed.
-
samplesToMs(int)
- Returns time elapsed after "Sample" samples in ms.
-
save()
- Saves current wave.
-
setChanged(boolean)
- Sets state of "changed".
-
setChannelCount(short)
- Sets number of channels (1:mono, 2:stereo).
-
setCoding(String)
- Sets the format, "au" or "wav".
-
setDescription(String)
- Sets description string.
-
setFrequency(int)
- Sets frequency of this wavefile.
-
setName(String)
- Sets the filename of this wavefile.
-
setResolution(short)
- sets resolution of this wavefile.
-
setWaves(short[], short[])
- Sets arrays of left and right data.
NOT_SUPPORTED_S
public static String NOT_SUPPORTED_S
IS_CORRUPT_S
public static String IS_CORRUPT_S
ERROR_OPENING_S
public static String ERROR_OPENING_S
ERROR_SAVING_S
public static String ERROR_SAVING_S
NOT_CREATE
public static String NOT_CREATE
NEITHER_WAV_AU_S
public static String NEITHER_WAV_AU_S
Wave
public short Wave[]
- Helper array for simple module type: SimpleModule.
This array is only valid for this type of modules. It
cannot be used outside a simple Module.
donnees du vieux type.
pour les simple modules: SimpleModule
WaveFileBase
public WaveFileBase()
- Initializes a Wavefile. It is initially empty.
That means, the format is set to 8000Hz, 8bit, mono,
the arrays of the waves are initialized with length=0.
The name defaults to "new.au".
createNew
public void createNew(int freq,
short mono[])
- Creates a new mono wavefile with given frequency.
cree un fichier Wave avec freq et data[] mono.
c'est pour instancier une instance avec des donnees en mono
createNew
public void createNew(int freq,
short left[],
short right[])
- Creates a new stereo wavefile with given frequency.
cree Wave avec freq et donnees left[] et right[].
createNew
public void createNew()
- Creates an empty wavefile.
cree Wave sans donnees.
load
public void load(String file) throws WaveFileException
- Loads "file".
The format (Sun muLaw (".au") or Microsoft PCM (".wav")
is recognized automatically. Frequency, resolution, channelCount,
description and name are set to values found in the file.
Charge le fichier "file".
reconnait automatiquement, si le fichier
est Sun muLaw (".au") ou Microsoft PCM (".wav")
- Throws: WaveFileException
- when "file" doesn't exist,
a read error occured or the file has a unrecognized format.
- Throws: WaveFileException
- quand le fichier "file" n'existe pas, un erreur d'ecriture ou
le fichier a un format non supporte.
save
public void save() throws WaveFileException
- Saves current wave. The name may be set with setName(), but
is normally set when you called load() before.
The format (.au or .wav) is derived from the extension of filename
Sauve le fichier actuel. (nom: name).
Si le nom est *.au, le format est Sun muLaw,
si le nom est *.wav, le format et Microsoft PCM
- Throws: WaveFileException
- when a writing error occurs.
- Throws: WaveFileException
- quand un error d'ecriture se passe
getLeftWave
public short[] getLeftWave()
- returns array of left wave-data.
retourne le tableau des donnees de gauche.
getRightWave
public short[] getRightWave()
- returns array of right wave data.
retourne le tableau des donnees de right.
setWaves
public synchronized void setWaves(short left[],
short right[])
- Sets arrays of left and right data.
This method should be called at the end of any treatment.
Note: both arrays have to have the same length.
change les tableaux de right et left.
getSize
public int getSize()
- returns number of samples in this wavefile.
This equals the size of the arrays leftwave and rightwave.
retourne la taille en echantillons du WaveFile.
getFrequency
public int getFrequency()
- Returns frequency (samples per second) of this wavefile.
retourne la frequence (cvd echantillons par seconde)
du WaveFile.
setFrequency
public int setFrequency(int freq)
- Sets frequency of this wavefile.
Returns the new frequency.
change la frequence.
Utilisable surtout dans les modules.
retourne la nouvelle frequence
getCoding
public String getCoding()
- Returns extension of this wavefile.
Currently supported: "wav" or "au".
Note: The name of this function will be changed !
retourne le format actuelle comme String.
format est egal au extension du nom du ficher (name)
du WaveFile
acteullement supporte : "wav" ,"au"
null si aucune extensin existe.
setCoding
public void setCoding(String exten)
- Sets the format, "au" or "wav". Effectively this method will only
change the extension of the filename, but this is taken into
consideration when calling save().
definit le format actuelle.
format est egal au extension du nom du ficher (name)
du WaveFile
acteullement supporte : "wav" ,"au"
isEmpty
public boolean isEmpty()
- Returns whether this wavefile is empty.
Empty means: either filename is null or "",
the arrays leftwave and rightwave are null or zero-length.
retourne true, si WaveFile ne contien pas de donnees.
getResolution
public short getResolution()
- Returns resolution (8 or 16 bit).
retourne la resolution (8 ou 16 bit) du fichier wave.
setResolution
public short setResolution(short res)
- sets resolution of this wavefile.
Only values of 8 or 16 are supported.
returns the new resolution.
pour changer la resolution (8 ou 16 bit).
retourne la nouvelle resolution
getChannelCount
public short getChannelCount()
- Returns number of channels (1:mono, 2:stereo).
Note, that wavefiles are always treated as
stereo in JaWavedit. That means, a mono wavefile
means only, that it will be saved as a mono file, which
is done by mixing left and right side.
retourne le nb de channels (1=>mono, 2=>stereo).
setChannelCount
public short setChannelCount(short channels)
- Sets number of channels (1:mono, 2:stereo).
Note, that wavefiles are always treated as
stereo in JaWavedit. That means, a mono wavefile
means only, that it will be saved as a mono file, which
is done by mixing left and right side.
change le nb de channels (1=>mono, 2=>stereo).
retourne le nouvel nb de channels
isMono
public boolean isMono()
- Returns whether this wavefile is internally mono.
retourne true, si WaveFile est interne en format mono.
isStereo
public boolean isStereo()
- returns whether this wavefile is internally stereo.
retourne true, si WaveFile est interne en format stereo.
getName
public String getName()
- Returns the filename of this wavefile.
retourne le nom de fichier du WaveFile.
setName
public void setName(String fileName)
- Sets the filename of this wavefile.
change le nom du WaveFile.
getDescription
public String getDescription()
- Returns the description string.
This is only for information purposes, it is
included in wav and au files.
retourne le string de description.
il est inclu dans les fichiers .wav ou .au
setDescription
public void setDescription(String newDescr)
- Sets description string.
This is only for information purposes, it is
included in wav and au files.*
change le string de description.
il est inclu dans les fichiers .wav ou .au
getChanged
public boolean getChanged()
- Returns whether this wavefile was changed after latest call to save().
When changed is true, an asterisk is displayed in the title of
the main window of JaWavedit.
retourne true, si le WaveFile est different compare au fichier sur la disque.
setChanged
public void setChanged(boolean c)
- Sets state of "changed".
You shouldn't use this, as it is updated automatically.
change l'etat de "changed".
samplesToMs
public long samplesToMs(int Sample)
- Returns time elapsed after "Sample" samples in ms.
This takes into consideration the current frequency.
retourne la position "Sample" (en echantillons) en ms.
peut etre utilise dans les modules.
msToSamples
public int msToSamples(long ms)
- Returns the sample position when "ms" milliseconds are elapsed.
It takes into consideration current frequency.
retourne la position "ms" en echantillons.
peut etre utilise dans les modules.
extractFileName
public String extractFileName()
- Returns current name without path.
retourne le nom de fichier Wavefile sans le chemin.
extractFilePath
public String extractFilePath()
- Returns path of current name.
retourne le chemin de fichier Wavefile.