/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.fmod3;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import org.lwjgl.BufferUtils;
import org.lwjgl.fmod3.callbacks.FSoundCloseCallback;
import org.lwjgl.fmod3.callbacks.FSoundDSPCallback;
import org.lwjgl.fmod3.callbacks.FSoundMetaDataCallback;
import org.lwjgl.fmod3.callbacks.FSoundOpenCallback;
import org.lwjgl.fmod3.callbacks.FSoundReadCallback;
import org.lwjgl.fmod3.callbacks.FSoundSeekCallback;
import org.lwjgl.fmod3.callbacks.FSoundStreamCallback;
import org.lwjgl.fmod3.callbacks.FSoundTellCallback;
/**
* $Id$
*
* Remarks
* This also closes down the sample management system, freeing all MANAGED samples loaded (unless they were allocated with the FSOUND_UNMANAGED flag).
* Streams are not freed. You must close them yourself.
* CD Tracks are stopped.
*
* Remarks
* Memory loader FMOD functions are not affected, such as FMUSIC_LoadSongMemory etc.
* WARNING : This function is dangerous in the wrong hands. You must return the right values, and each command must work properly, or FMOD will not function, or it may even crash if you give it invalid data.
* You must support SEEK_SET, SEEK_CUR and SEEK_END properly, or FMOD will not work properly. See standard I/O help files on how these work under fseek().
* Read the documentation in REMARKS and do exactly what it says. See the "simple" example for how it is used properly.
* The MIDI loader does not support user file callbacks. For WAD type data structures with embedded MIDI files FMUSIC_LoadSongMemory will have to be used.
* --------------
* PlayStation 2 NOTE! This function takes IOP function pointers, not EE pointers! It is for custom IOP file systems not EE based ones.
* This function can only be called after FSOUND_Init on PlayStation 2, not before
*
* Remarks
* You do not have control over how many hardware channels are available to you. In a lot of
* cases it may be 0 (the sound card does not have the ability to supply hardware channels).
* This is why it is usually a good idea to supply FSOUND_Init with a good number of software
* channels to fall back onto, for example 32.
* Hardware channels are 3D hardware channels only. There is no benefit in supporting hardware
* for 2d playback of sound effects. With todays machines and FMOD's superior mixing routines,
* FMOD's software engine can sometimes be faster than the driver's hardware support!
*
* @param mixrate Output rate in hz between 4000 and 65535. Any thing outside this will cause
* the function to fail and return false.
* PS2 Note. Only rates of 24000 and 48000 are supported.
* SmartPhone Note. Use 22050 or the operating system may crash outside of the control of fmod.
* @param channels Maximum number of SOFTWARE channels available.
* The number of HARDWARE channels is autodetected. The total number of channels available (hardware and software) after initialization can be found with FSOUND_GetMaxChannels.
* Having a large number of maxchannels does not adversely affect cpu usage, but it means it has the POTENTIAL to mix a large number of channels, which can have an adverse effect on cpu usage.
* 1024 is the highest number that can be set. Anything higher will return an error.
* @param flags See FSOUND_INIT_FLAGS. Controls some global or initialization time aspects of playback
* @return On success, true is returned. On failure, false is returned
*/
public static native boolean FSOUND_Init(int mixrate, int channels, int flags);
/**
* Sets the FMOD internal mixing buffer size.
* It is configurable because low buffersizes use less memory, but are more instable.
* More importantly, increasing buffer size will increase sound output stability, but
* on the other hand increases latency, and to some extent, CPU usage.
* FMOD chooses the most optimal size by default for best stability, depending on the
* output type - and if the drivers are emulated or not (NT).
* It is not recommended changing this value unless you really need to. You may get worse
* performance than the default settings chosen by FMOD.
*
* Remarks
* This function cannot be called after FMOD is already activated with FSOUND_Init.
* It must be called before FSOUND_Init, or after FSOUND_Close.
* ---------
* The buffersize seting defaults to 50ms if it is not called for DSOUND.
* It defaults to 200ms for Windows Multimedia wave-out or for emulated DirectSound drivers (such as NT drivers).
* When the output is FSOUND_OUTPUT_ASIO the buffersize is ignored. The buffersize should be configured using the ASIO driver which can be done with the supplied asioconfig.exe in the FMOD SDK.
* ---------
* Buffer sizes lower than 50 are clamped at 50.
* Buffer sizes are also rounded DOWN to the nearest multiple of 25. This is because FMOD mixes in blocks of 25ms.
* Due to this buffersize command latency on software channels will be between 25 and 50ms on average (37.5ms) when the buffersize is set to 50.
* ---------
* Macintosh, PlayStation 2 and GameCube do not support this as they already achieve minimal latency and are forced to 25ms.
*
* @param len_ms buffer size in milliseconds.
* @return On success, true is returned. On failure, (ie if FMOD is already active) false is returned
*/
public static native boolean FSOUND_SetBufferSize(int len_ms);
/**
* Selects a soundcard driver.
* It is used when an output mode has enumerated more than one output device, and you need to select between them.
*
* Remarks
* This function cannot be called after FMOD is already activated with FSOUND_Init.
* It must be called before FSOUND_Init, or after FSOUND_Close.
*
* Remarks
* This function cannot be called after FMOD is already activated with FSOUND_Init.
* It must be called before FSOUND_Init, or after FSOUND_Close.
* ---------
* FMOD uses GetForegroundWindow if this function is not called.
* @return On success, TRUE is returned. On failure, FALSE is returned.
*/
//public static native boolean FSOUND_SetHWND();
/**
* This sets the maximum allocatable channels on a hardware card. FMOD automatically
* detects and allocates the maximum number of 3d hardware channels, so calling this
* will limit that number if it becomes too much
*
* Remarks
* This function cannot be called after FMOD is already activated with FSOUND_Init.
* It must be called before FSOUND_Init, or after FSOUND_Close.
* ---------
* This function has nothing to do with FSOUND_SetMinHardwareChannels, in that this is not a function that forces FMOD into software mixing if a card has a certain number of channels.
* This function only sets a limit on hardware channels, so if you card has 96 hardware channels, and you set FSOUND_SetMaxHardwareChannels(10), then you will only have 10 hardware channels to use.
* @param max maximum number of hardware channels to allocate, even if the soundcard supports more
* @return On success, TRUE is returned. On failure, FALSE is returned
*/
public static native boolean FSOUND_SetMaxHardwareChannels(int max);
//public static native boolean FSOUND_FSOUND_SetMemorySystem(FSoundCallback callback);
/**
* This sets the minimum allowable hardware channels before FMOD drops back to 100 percent software.
* This is helpful for minimum spec cards, and not having to guess how many hardware channels
* they might have. This way you can guarantee and assume a certain number of channels for
* your application and place them all in FSOUND_HW3D without fear of the playsound failing
* because it runs out of channels on a low spec card.
*
* Remarks
* As an example, if you set your minimum to 16, you can now safely guarantee that 16 sounds can be played at once that are created with FSOUND_HW3D.
* This way if you do come across a card that only supports 4 channels, it will just drop back to playing ALL sounds in software mode.
* It may sound worse, but at least it doesnt fail on the playsound. (which could sound even worse!)
* ---------
* @param min minimum number of hardware channels allowable on a card before it uses the software engine 1004562604f the time
* @return On success, TRUE is returned. On failure, FALSE is returned
*/
public static native boolean FSOUND_SetMinHardwareChannels(int min);
/**
* Sets a digital mixer type.
*
* Remarks
* This function cannot be called after FMOD is already activated with FSOUND_Init.
* It must be called before FSOUND_Init, or after FSOUND_Close.
* This function does not nescessarily need to be called, autodetection will select the
* fastest mixer for your machine. It is here if you need to test all mixer types for
* debugging purposes, or a mixer has a feature that the autodetected one doesnt.
* (ie low quality mixers or volume ramping)
* @param mixer mixer type, see FSOUND_MIXERTYPES for valid parameters and descriptions
* @return On success, TRUE is returned. On failure, (ie if FMOD is already active) FALSE is returned
*/
public static native boolean FSOUND_SetMixer(int mixer);
/**
* Sets up the soundsystem output mode
*
* Remarks
* This function cannot be called after FMOD is already activated with FSOUND_Init.
* It must be called before FSOUND_Init, or after FSOUND_Close.
* -------
* Under Windows NT - Waveout is FASTER than DirectSound, achieves LOWER latency, AND
* is LESS buggy. DirectSound under NT is achieved by emulating waveout, and therefore is
* inferior to waveout. Use WAVEOUT under NT.
* Under Windows 9x and W2K - DirectSound is faster than waveout and can achieve lower latency.
* Use DIRECTSOUND under Win9x and W2K.
* -------
* If you dont call FSOUND_SetOutput, FMOD will now autodetect DSOUND or WINMM based on the operating system.
*
* Remarks
* Note - Only reliably works with FSOUND_OUTPUT_DSOUND or FSOUND_OUTPUT_XBOX output modes. Other output modes will only interpret FSOUND_SPEAKERMODE_MONO and set everything else to be stereo.
* ----------------------------------
* To get true 5.1 dolby digital or DTS output you will need a soundcard that can encode it, and a receiver that can decode it.
* If not the results can be unpredictable.
* ----------------------------------
* Calling this will reset the pan separation setting. It sets it to 0 if FSOUND_SPEAKERMODE_MONO is chosen, and 1 otherwise.
* You will need to reset the pan separation if required afterwards.
* Note that some soundcard drivers may ignore this call.
* ----------------------------------
* XBOX only - This function MUST be called before FSOUND_Init to change the default speaker mode. To change on the fly, you must close down FMOD with FSOUND_Close then re-initialize it with FSOUND_Init.
* If it is called after FSOUND_Init, only headphone speakermode is interpreted to switch headphone mode on and off.
* ----------------------------------
* PlayStation 2 only - This function must be called before playing sounds. Calling this after playing a sound will not make that existing sound work in Prologic 2.
*
* @param speakermode enum describing the users speaker setup
*/
public static native void FSOUND_SetSpeakerMode(int speakermode);
/**
* This updates the 3d sound engine and DMA engine (only on some platforms), and should be called once a game frame.
* This function will also update the software mixer if you have selected FSOUND_OUTPUT_NOSOUND_NONREALTIME as your output mode
*/
public static native void FSOUND_Update();
// -------------------------------------------------------------
// Global runtime informaton functions
// =============================================================
/**
* Returns in percent of cpu time the amount of cpu usage that FSOUND/FMUSIC mixing is taking
*
* Remarks
* This value represents the cpu usage used by streams, the software mixer, and subsequent calls to dsound waveout etc.
* MIDI playback is not counted as it is performed by directx.
*
* Remarks
* If no driver is selected, the default driver is used.
*
* Remarks
* Note that if using FSOUND_SetMemorySystem, the memory usage will be slightly higher than without it, as fmod has to have a small amount of memory overhead to manage the available memory.
*
* Remarks
* Use this to compare the header you are using against the compiled DLL version to make sure your
* DLL is up to date.
*
* Remarks
* FMOD has a sample management system that holds onto any samples loaded or allocated, and
* frees them all when you call FSOUND_Close. It takes the hassle out of having to keep hold
* of a lot of sample handles and remember to free them all at the end of your application.
* It is basically an expandle array of handles that holds each sample until FMOD closes down where it does
* a cleanup. FSOUND_UNMANAGED can be used NOT to use the sample management system.
* ------------
* FSOUND_Sample_Alloc is only nescessary for lower level operations with sample data. Usually
* FSOUND_Load does the work for you. lower level operations mean such things as uploading data from memory or
* your own compressed data for example.
* You can create a new sample from scratch by doing the following operations
* 1. Allocate a new sample with FSOUND_Sample_Alloc
* 2. Write data to the sample buffer with FSOUND_Sample_Lock and FSOUND_Sample_Unlock, or
* FSOUND_Sample_Upload.
* Note FSOUND_Sample_Lock only returns a pointer to the sample data, whereas
* FSOUND_Sample_Upload does a copy from data you give it, with format conversion to the
* correct format.
*
* @param index Sample pool index. See remarks for more on the sample pool.
* 0 or above - The absolute index into fsounds sample pool. The pool will grow as
* the index gets larger. If a slot is already used it will be replaced.
* FSOUND_FREE - Let FSOUND select an arbitrary sample slot.
* FSOUND_UNMANAGED - Dont have fsound free this sample upon FSOUND_Close
* @param length The length in of the sample buffer in SAMPLES
* @param mode Bitfield describing various characteristics of the sample. Valid parameters are
* described in FSOUND_MODES
* @param deffreq Default frequency for this sample
* @param defvol Default volume for this sample
* @param defpan Default pan for this sample
* @param defpri Default priority for this sample
* @return On success, a reference to an allocated sample is returned. On failure, NULL is returned
*/
public static FSoundSample FSOUND_Sample_Alloc(int index, int length, int mode, int deffreq, int defvol, int defpan, int defpri) {
long result = nFSOUND_Sample_Alloc(index, length, mode, deffreq, defvol, defpan, defpri);
return (result != 0) ? new FSoundSample(result) : null;
}
private static native long nFSOUND_Sample_Alloc(int index, int length, int mode, int deffreq, int defvol, int defpan, int defpri);
/**
* Removes a sample from memory and makes its slot available again
* @param sample sample definition to be freed
*/
public static void FSOUND_Sample_Free(FSoundSample sample) {
nFSOUND_Sample_Free(sample.sampleHandle);
}
private static native void nFSOUND_Sample_Free(long sample);
/**
* Returns a reference to a managed sample based on the index passed
*
* Remarks
* Samples that are not created with FSOUND_UNMANAGED are stored in a table inside FMOD.
* This way when FMOD can free all samples when FSOUND_Close is called and the user doesnt have to worry about cleaning up memory.
*
* @param sampno index in the sample management pool of the requested sample
* @return Reference to a sample
*/
public static FSoundSample FSOUND_Sample_Get(int sampno) {
long result = nFSOUND_Sample_Get(sampno);
return (result != 0) ? new FSoundSample(result) : null;
}
private static native long nFSOUND_Sample_Get(int sampno);
/**
* Returns the default volume, frequency, pan and priority values for the specified sample
*
* Remarks
* Passing NULL in any of these parameters will result in the value being ignored
*
* Remarks
* Passing NULL in any of these parameters will result in the value being ignored
*
* Remarks
* Passing NULL in any of these parameters will result in the value being ignored.
* @param sample sample to get the loop point information from
* @param loopstart IntBuffer to be filled with the sample loop start point. Can be NULL
* @param loopend IntBuffer to be filled with the sample loop end point. Can be NULL
* @return On success, TRUE is returned. On failure, FALSE is returned
*/
public static int FSOUND_Sample_GetLoopPoints(FSoundSample sample, IntBuffer loopstart, IntBuffer loopend) {
return nFSOUND_Sample_GetLoopPoints(sample.sampleHandle, loopstart, (loopstart == null) ? 0 : loopstart.position(), loopend, (loopend == null) ? 0 : loopend.position());
}
private static native int nFSOUND_Sample_GetLoopPoints(long sample, IntBuffer loopstart, int loopstartOffset, IntBuffer loopend, int loopendOffset);
/**
* Get the minimum and maximum audible distance for a sample
*
* Remarks
* A 'distance unit' is specified by FSOUND_3D_SetDistanceFactor. By default this is set to meters which is a distance scale of 1.0.
* See FSOUND_3D_SetDistanceFactor for more on this.
* The default units for minimum and maximum distances are 1.0 and 1000000000.0f.
* Volume drops off at mindistance / distance.
*
* @param sample sample to get the distance information from
* @param min FloatBuffer to be filled with the sample loop start point. Can be NULL
* @param max FloatBuffer to be filled with the sample loop end point. Can be NULL
* @return On success, TRUE is returned. On failure, FALSE is returned
*/
public static int FSOUND_Sample_GetMinMaxDistance(FSoundSample sample, FloatBuffer min, FloatBuffer max) {
return nFSOUND_Sample_GetMinMaxDistance(sample.sampleHandle, min, (min == null) ? 0 : min.position(), max, (max == null) ? 0 : max.position());
}
private static native int nFSOUND_Sample_GetMinMaxDistance(long sample, FloatBuffer min, int minOffset, FloatBuffer max, int maxOffset);
/**
* Returns a bitfield containing information about the specified sample.
* The values can be bitwise AND'ed with the values contained in FSOUND_MODES to see if certain criteria are true or not.
* Information that can be retrieved from the same in this field are loop type, bitdepth and stereo/mono.
*
* @param sample sample to get the mode information from
* @return On success, the sample mode is returned. On failure, 0 is returned.
*/
public static int FSOUND_Sample_GetMode(FSoundSample sample) {
return nFSOUND_Sample_GetMode(sample.sampleHandle);
}
private static native int nFSOUND_Sample_GetMode(long sample);
/**
* Returns a string containing the sample's name
*
* @param sample sample to get the loop point information from
* @return On success, the name of the sample is returned. On failure, NULL is returned.
*/
public static String FSOUND_Sample_GetName(FSoundSample sample) {
return nFSOUND_Sample_GetName(sample.sampleHandle);
}
private static native String nFSOUND_Sample_GetName(long sample);
/**
* Loads and decodes a static soundfile into memory.
* This includes such files as .WAV, .MP2, .MP3, .OGG, .RAW and others.
*
* Remarks
* FMOD has a sample management system that holds onto any samples loaded or allocated, and frees them all when you call FSOUND_Close.
* It takes the hassle out of having to keep hold of a lot of sample handles and remember to free them all at the end of your application.
* It is basically an expandle array of handles that holds each sample until FMOD closes down where it does a cleanup.
* FSOUND_UNMANAGED can be used so FMOD does NOT use the sample management system. You have to make sure they are freed yourself.
* --------
* Specify FSOUND_LOADMEMORY to load a file from a memory image.
* The pointer you pass to name must be the actual image of the data you want to load.
* The length parameter is to be filled out if FSOUND_LOADMEMORY is specified, otherwise if you do not specify memory loading, can be safely ignored and should be set to 0.
* --------
* Compressed formats are expanded into memory. If the file is quite large, it could take a while to load.
* --------
* If FSOUND_8BITS is specified and the file decodes to 16bit normally, FMOD will downgrade the sample to 8bit.
* --------
* On PlayStation 2, the name_or_data pointer and length variables must be 16 byte aligned, for DMA reasons.
* --------
* Note that FSOUND_NONBLOCKING is NOT supported with this function.
*
* Remarks
* You must always unlock the data again after you have finished with it, using FSOUND_Sample_Unlock.
* For PCM based samples, data must be signed 8 or 16bit. For compressed samples such as those created with FSOUND_IMAADPCM, FSOUND_VAG, FSOUND_GCADPCM, the data must be in its original compressed format.
* On PlayStation 2, with FSOUND_HW2D or FSOUND_HW3D based samples, this function does not return a readable or writable buffer, it returns the SPU2 address of the sample. To send data to it you must call FSOUND_SendData.
* On GameCube, with FSOUND_HW2D or FSOUND_HW3D based samples, this function will not return the data contained within the sample. It is for upload purposes only.
*
* Remarks
* Frequency, volume and pan variation values specify a +/- variation to the
* specified default frequency, volume and pan values i.e. with deffreq=44100,
* varfreq=2000 the actual frequency value used will be in the range 42100 -> 46100.
*
* Remarks
* A 'distance unit' is specified by FSOUND_3D_SetDistanceFactor. By default this is set to meters which is a distance scale of 1.0.
* See FSOUND_3D_SetDistanceFactor for more on this.
* The default units for minimum and maximum distances are 1.0 and 1000000000.0f.
* Volume drops off at mindistance / distance.
*
* Remarks
* Only the following modes are accepted, others will be filtered out.
* FSOUND_LOOP_BIDI, FSOUND_LOOP_NORMAL, FSOUND_LOOP_OFF, FSOUND_2D.
* Normally FSOUND_2D is accepted only if the sound is software mixed. If this is not set, the mode is set for the sample to be 3D processed.
* -------------------
* On Playstation 2, XBox and GameCube, FSOUND_HW2D and FSOUND_HW3D are supported, so you can change between the 2 at runtime.
* -------------------
* On Windows, samples created with FSOUND_HW3D or FSOUND_HW2D do not support FSOUND_LOOP_BIDI. This is a limitation of Direct X. *
* Remarks
* Samples created with FSOUND_HW3D and FSOUND_HW2D under the FSOUND_OUTPUT_DSOUND output mode do not support this function.
* Loop points set on such a sample with be ignored, and the sample will loop in its entirety. This is a limitation of DirectSound.
* On XBOX, GameCube and Playstation 2 hardware voices using compressed data (ie XADPCM, VAG or GCADPCM), these values will not be sample accurate, but will be rounded to the nearest compression block size.
* On PlayStation 2, the loopend is ignored. The hardware cannot change the end address, so the loopend is always equivalent to length - 1 no matter what you set. *
* @param sample sample to have its loop points set
* @param loopstart The starting position of the sample loop
* @param loopend The end position of the sample loop
* @return On success, true is is returned. On failure, false is returned.
*/
public static boolean nFSOUND_Sample_SetLoopPoints(FSoundSample sample, int loopstart, int loopend) {
return nFSOUND_Sample_SetLoopPoints(sample.sampleHandle, loopstart, loopend);
}
private static native boolean nFSOUND_Sample_SetLoopPoints(long sample, int loopstart, int loopend);
/**
* Releases previous sample data lock from FSOUND_Sample_Lock
*
* @param sample sample definition
* @param lock lock object that contains lock info
* @return On success, true is is returned. On failure, false is returned.
*/
public static boolean FSOUND_Sample_Unlock(FSoundSample sample, FSoundSampleLock lock) {
return nFSOUND_Sample_Unlock(sample.sampleHandle, lock.getPtr1(), lock.getPtr2(), lock.getLen1(), lock.getLen2());
}
private static native boolean nFSOUND_Sample_Unlock(long sample, ByteBuffer ptr1, ByteBuffer ptr2, int len1, int len2);
/**
* This function uploads new sound data from memory to a preallocated/existing sample and does conversion based on the specified source mode.
* If sample data already exists at this handle then it is replaced with the new data being uploaded
*
* Remarks
* Note that on PlayStation 2 the source data address is an IOP address not an EE address.
* To get data from EE RAM to the sample you must allocate some IOP memory, dma it to IOP memory then call upload. There are helper functions in fmodps2.h to achieve this.
*
* Remarks
* If you play a FSOUND_HW3D declared sample with this function, then the position and velocity
* are set to those of the listener. Other attributes such as volume, frequency and pan are taken
* from the sample's default volume, frequency, pan etc.
* ----------
* The channel handle :
* The return value is reference counted. This stops the user from updating a stolen channel.
* Basically it means the only sound you can change the attributes (ie volume/pan/frequency/3d position) for are the one you specifically called playsound for. If another sound steals that channel, and you keep trying to change its attributes (ie volume/pan/frequency/3d position), it will do nothing.
* This is great if you have sounds being updated from tasks and you just forget about it.
* You can keep updating the sound attributes and if another task steals that channel, your original task wont change the attributes of the new sound!!!
* The lower 12 bits contain the channel number. (yes this means a 4096 channel limit for FMOD :)
* The upper 19 bits contain the reference count.
* The top 1 bit is the sign bit.
* ie
* S RRRRRRRRRRRRRRRRRRR CCCCCCCCCCCC
* ----------
* Remember if not using FSOUND_FREE, then the channel pool is split up into software and hardware channels.
* Software channels occupy the first n indicies specified by the value passed into FSOUND_Init.
* Hardware channels occupy the next n indicies after this, and can be a variable amount, depending on the hardware.
* Use FSOUND_GetNumHardwareChannels to query how many channels are available in hardware.
*
* Remarks
* FSOUND_ALL is supported. Passing this will cause ALL channels to play. (note this could make things VERY noisy!)
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
* ----------
* The channel handle :
* The return value is reference counted. This stops the user from updating a stolen channel.
* This means the only sound you can change the attributes (ie volume/pan/frequency/3d position) for are the
* one you specifically called playsound for. If another sound steals that channel, and you keep trying to
* change its attributes (ie volume/pan/frequency/3d position), it will do nothing.
* This is great if you have sounds being updated from tasks and you just forget about it.
* You can keep updating the sound attributes and if another task steals that channel, your original task
* wont change the attributes of the new sound!!!
* The lower 12 bits contain the channel number. (yes this means a 4096 channel limit for FMOD :)
* The upper 19 bits contain the reference count.
* The top 1 bit is the sign bit.
* ie
* S RRRRRRRRRRRRRRRRRRR CCCCCCCCCCCC
* ----------
* Remember if not using FSOUND_FREE, then the channel pool is split up into software and hardware channels.
* Software channels occupy the first n indicies specified by the value passed into FSOUND_Init.
* Hardware channels occupy the next n indicies after this, and can be a variable amount, depending on the hardware.
* Use FSOUND_GetNumHardwareChannels to query how many channels are available in hardware.
* ----------
* If you attach a sound to a DSP unit (for grouping purposes), the callback for the DSP unit will be overwritten with fmod's internal mixer callback, so the callback the user supplied is rendered obsolete and is not called.
* Also, do not attach sounds to system DSP units, the assignment will be ignored if you do.
*
* Remarks
* FSOUND_ALL is supported. Passing this will cause ALL channels to stop.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
*
* Remarks
* FSOUND_ALL is supported here. Passing this will set ALL channels to specified frequency.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
* Negative frequencies make the sound play backwards, so FSOUND_SetCurrentPosition would be needed to set the sound to the right position.
*
* Remarks
* FSOUND_ALL is supported. Passing this will set the pan of ALL channels available.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
* ----------
* FSOUND_SYSTEMCHANNEL is supported. You can set the mix levels for the FMOD software engine, and ALL software mixed sounds will be affected. *
* Remarks
* FSOUND_ALL is supported. Passing this will set loop modes for all channels available.
* Note, this does not work for hardware sounds played on hardware channels while they are playing. The function has to be called when the channel is paused.
* Software based sounds do not have this limitation, and can have their loop mode changed during playback, but for compatibility it is best to use the pause method, else you may get different behaviour if hardware voices do not exist.
*
* Remarks
* FSOUND_ALL is supported. Passing this will mute/unmute ALL channels available.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
*
* Remarks
* FSOUND_ALL is supported. Passing this will set the pan of ALL channels available.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
* ----------
* Important : If you are playing a STEREO sample, and using normal middle panning, it will only come out at half the volume
* they are supposed to. To avoid this use FSOUND_STEREO pan.
* Panning works in the following manner:
* full left : 100to left, 0to right
* full right : 0to left, 100to right
* middle : 71to left, 71to right
* FMOD Uses 'constant power' panning. The center position is 71 4738960n each channel as it keeps an even RMS output level when
* moving the sound from left to right. Placing 50 4738960n each channel for a middle position is incorrect.
* The pan graph for constant power panning resembles a curve instead of straight lines. *
* Remarks
* FSOUND_ALL is supported. Passing this will pause/unpause ALL channels available.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
*
* Remarks
* FSOUND_ALL is supported. Passing this will pause/unpause ALL channels available.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
*
* Remarks
* FSOUND_ALL is supported. Passing this will pause/unpause ALL channels available.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
*
* Remarks
* FSOUND_ALL is supported. Passing this will pause/unpause ALL channels available.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
*
* Remarks
* FSOUND_ALL is supported. Passing this will pause/unpause ALL channels available.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
*
* Remarks
* FSOUND_ALL is supported. Passing this will set the absolute volume of ALL channels available.
* If FSOUND_ALL is used the last channel success flag will be returned. This return value is not useful in most circumstances.
* -------------
* A good example of this function being used for a game needing a voice over.
* If all the background sounds were too loud and drowned out the voice over, there is no way to
* feasibly go through all the sfx channels and lower the background noise volumes (some might be allocated by music).
* Simply lower the background noise with FSOUND_SetSFXMasterVolume, and use FSOUND_SetVolumeAbsolute to bring
* up the volume of the voice over to full, and you will get one channel standing out amongst the rest. *
* Remarks
* This is not the same as FSOUND_GetCurrentLevels, as that function takes the actual waveform data into account.
* This function simply gives a final volume based on 3d position and volume settings.
*
* Remarks
* FSOUND treats +X as right, +Y as up, and +Z as forwards.
* ---------
* A 'distance unit' is specified by FSOUND_3D_SetDistanceFactor. By default this is set to meters which is a distance scale of 1.0.
* See FSOUND_3D_SetDistanceFactor for more on this.
* ---------
* FSOUND vectors expect 3 floats representing x y and z in that order. I.e. a typical definition
*
* Remarks
* FSOUND_ALL is supported. Passing this will set the min/max distance on ALL channels available.
* A 'distance unit' is specified by FSOUND_3D_SetDistanceFactor. By default this is set to meters which is a distance scale of 1.0.
* See FSOUND_3D_SetDistanceFactor for more on this.
* The default units for minimum and maximum distances are 1.0 and 1000000000.0f.
* Volume drops off at mindistance / distance.
* To define the min and max distance per sound and not per channel use FSOUND_Sample_SetMinMaxDistance.
*
* Remarks
* FSOUND_ALL is supported. Passing this set the current position for the sound on ALL channels available.
* On XBOX, GameCube and Playstation 2 hardware voices using compressed data (ie XADPCM, VAG or GCADPCM),
* this value will not be sample accurate, but will be rounded to the nearest compression block size.
*
* Remarks
* Note that current sample does not return to NULL when a sound has ended.
*
* Remarks
* By default this function is only point sampled and not latency adjusted (it will appear to trigger ahead of when you hear the sound).
* To fix this and get a 'perfect' set of levels in realtime, use FSOUND_INIT_ACCURATEVULEVELS with FSOUND_Init.
* -------------------
* To get an overall VU reading for all sounds, add all VU values for each channel together, and then clip at 1.0.
* Another (harder) way is to write a dsp unit that reads from the mixbuffer being passed into it.
* Note: A true 'VU' should be smoothed, but in case people were after more accuracy than a smoothed value, it was decided to return the raw amplitude, and let the user smooth the result in their own way.
*
* Remarks
* This works for all channel types, whereas setting it will not work.
*
* Remarks
* A multichannel sound, only possible with the .FSB format, can contain multiple subchannels. When a multichannel sound is played, multiple channels are allocated at the same time.
* For example, a 8 sounds/streams can be interleaved into a multichannel FSB. This function would return 8, as 8 real hardware/software voices are used during playback.
* FSOUND_GetSubChannel can be used to get access to the secondary channels.
*
* Remarks
* This function is useful for games that have a pause mode, and you dont want the sounds
* to continue playing, but you would like them to continue on from where they left off
* when you unpause.
*
* Remarks
* A multichannel sound, only possible with the .FSB format, can contain multiple subchannels. When a multichannel sound is played, multiple channels are allocated at the same time.
* Normally you can just use the parent handle, and things like FSOUND_SetVolume will affect all subchannels at the same time. With this function, you can get access to the raw subchannels to allow manipulation of each voice seperately within the multichannel array.
* For example, a 8 sounds/streams can be interleaved into a multichannel FSB. If you specified a subchannel of 7, it would return a channel handle to the last channel in the multichannel array.
* A subchannel index of 0 is the parent channel, and the same as the voice passed in is a parameter.
* The number of subchannels within a multichannel voice can be determined with FSOUND_GetNumSubChannels.
*
* Remarks
* Surround sound only works on software channels.
*
* Remarks
* A 'distance unit' is specified by FSOUND_3D_SetDistanceFactor. By default this is set to meters which is a distance scale of 1.0.
* See FSOUND_3D_SetDistanceFactor for more on this.
*
* Remarks
* FSOUND treats +X as right, +Y as up, and +Z as forwards. (left handed)
* To map to your own coordinate system, flip and exchange these values. For example if you wanted to use right handed coordinates, you would negate the Z value of your own direction vector.
* Orientation vectors are expected to be of UNIT length. This means the magnitude of the vector should be 1.0f.
* ---------
* A 'distance unit' is specified by FSOUND_3D_SetDistanceFactor. By default this is set to meters which is a distance scale of 1.0.
* See FSOUND_3D_SetDistanceFactor for more on this.
* ---------
* Please remember to use units PER SECOND, NOT PER FRAME as this is a common mistake.
* Do not just use (pos - lastpos) from the last frame's data for velocity, as this is not correct.
* You need to time compensate it so it is given in units per SECOND.
* You could alter your pos - lastpos calculation to something like this.
* vel = (pos-lastpos) / (time taken since last frame in seconds).
* I.e. at 60fps the formula would look like this
* vel = (pos-lastpos) / 0.0166667.
*
* Remarks
* FSOUND treats +X as right, +Y as up, and +Z as forwards. (left handed)
* To map to your own coordinate system, flip and exchange these values. For example if you wanted to use
* right handed coordinates, you would negate the Z value of your own direction vector.
* Orientation vectors are expected to be of UNIT length. This means the magnitude of the vector
* should be 1.0f.
* ---------
* A 'distance unit' is specified by FSOUND_3D_SetDistanceFactor. By default this is set to meters which is a distance scale of 1.0.
* See FSOUND_3D_SetDistanceFactor for more on this.
* ---------
* Please remember to use units PER SECOND, NOT PER FRAME as this is a common mistake.
* Do not just use (pos - lastpos) from the last frame's data for velocity, as this is not
* correct. You need to time compensate it so it is given in units per SECOND.
* You could alter your pos - lastpos calculation to something like this.
* vel = (pos-lastpos) / (time taken since last frame in seconds). Ie at 60fps the formula
* would look like this vel = (pos-lastpos) / 0.0166667.
*
* Remarks
* Only affects FSOUND_3D_Listener_SetAttributes and FSOUND_3D_Listener_GetAttributes.
* Setting more than 1 listener will turn off doppler and cause all panning to be ignored and 3d sound will come from the center (mono).
* -------------
* For WIN32 FSOUND_HW3D based sounds, channels must have their attributes set after this function is called, otherwise unexpected audible results may occur.
* For example you cannot update your channels with FSOUND_3D_SetAttributes, call FSOUND_3D_Listener_SetCurrent, and then call FSOUND_Update and expect all the voices to update correctly.
* The correct order is to call FSOUND_3D_Listener_SetCurrent first, then update all channels with FSOUND_3D_SetAttributes, then call FSOUND_Update.
* This is due to DirectSound not supporting multiple listeners, so FMOD has to do inverse transforms on the positions to simulate it with one listener, at the time FSOUND_3D_SetAttributes is called.
*
* Remarks
* By default this value is set at 1.0, or meters
*
* Remarks
* This is a general scaling factor for how much the pitch varies due to doppler shifting.
* Increasing the value above 1.0 exaggerates the effect, whereas lowering it reduces the effect.
* 0 removes the effect all together.
* FMOD's speed of sound at a DopplerFactor of 1.0 is 340 m/s.
*
* Remarks
* ---------
* A 'distance unit' is specified by FSOUND_3D_SetDistanceFactor.
* By default this is set to meters which is a distance scale of 1.0.
* See FSOUND_3D_SetDistanceFactor for more on this.
* ---------
* The default rolloff factor is 1.0.
*
* Remarks
* WAV support supports windows codec compressed WAV files.
* --------------
* FSOUND_MPEGACCURATE is to be used cautiously. To open a file with this mode turned on, it has to scan the whole MP3 first. This can take several seconds if the file is big, or the harddisk/cpu is slow.
* A way to speed up this process would be to load the compressed mp3 into memory first, and use the FSOUND_LOADMEMORY flag with this function.
* --------------
* NOTE : Internet stream limitations
* - URLs must start with "http://".
* - The only supported formats for HTTP streams are MP3 (must have .mp3 extension) and OggVorbis (must have .ogg extension).
* --------------
* FSB streaming is not supported if the format from FSBank is 'Retain original format'. On PC platforms, only PCM and ADPCM FSB files are allowed.
* --------------
* Note, on PlayStation 2 you cannot use FSOUND_LOADMEMORY, you may use FSOUND_LOADMEMORYIOP though.
* --------------
* When opening with the FSOUND_NONBLOCKING flag, this function always succeeds at the point of being called.
* It will always return a valid channel handle, even though the file might fail to open. To determine any error in non blocking mode use FSOUND_Stream_GetOpenState.
* --------------
* NOTE: CDDA Streaming (Win32 only!)
* To open a CD for CDDA streaming, specify the drive letter of a CD drive e.g. FSOUND_Stream_Open("d:", 0, 0, 0); FSOUND_Stream_Open will create a stream with multiple substreams, one for each CD track. Use FSOUND_Stream_SetSubStream to select which CD track to play.
* A number of options can be passed to FSOUND_Stream_Open along with the drive letter. They are :
* ? e.g. FSOUND_Stream_Open("d:*?", 0, 0, 0); This option will cause a tag field called "CD_DEVICE_INFO" to be attached to the stream. This tag field contains information on the specified CD device.
* ! e.g. FSOUND_Stream_Open("d:*!", 0, 0, 0); This option will cause the stream to be opened in "quick open" mode. When a stream is opened in this mode, calls to FSOUND_Stream_SetSubStream will return immediately making it quick to select each substream in turn and get the length of each CD track. Note that a stream in quick open mode cannot be played! Use quick open mode to get track lengths and then re-open the stream without quick open mode to actually play it.
* j e.g. FSOUND_Stream_Open("d:*j", 0, 0, 0); This option turns jitter correction OFF.
* Options can be combined like so: FSOUND_Stream_Open("d:*?!j", 0, 0, 0);
* If a nonblocking CDDA stream fails to open, a tag field called "CD_ERROR" will be attached to the stream. This tag field contains a textual description of why the stream failed to open.
* NOTE: FMOD will always try to use native NTSCSI support to communicate with CD devices before trying to use ASPI. If FMOD is using ASPI then it can only access the first CD device it finds.
*
* Remarks
* When a stream starts to play, it inherits a special high priority (256).
* It cannot be rejected by other sound effect channels in the normal fashion as the user can never set a priority above 255 normally.
* --------------
* If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready.
* --------------
* FSB streaming is not supported if the format from FSBank is 'Retain original format'. On PC platforms, only PCM and ADPCM FSB files are allowed.
* --------------
* FSOUND_STEREOPAN is recommended for stereo streams if you call FSOUND_SetPan. This puts the left and right channel to full volume.
* Otherwise a normal pan will give half volume for left and right. See FSOUND_SetPan for more information on this.
* --------------
* You can use normal channel based commands (such as FSOUND_SetVolume etc) on the return handle, as it is a channel handle.
*
* Remarks
* The stream is still prepared and sitting in memory ready to go. Use FSOUND_Stream_Close on the stream to completely remove it.
* If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready
*
* Remarks
* If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready.
* The only exception to this rule is for internet streams - this function will successfully close an internet stream that has been opened with FSOUND_NONBLOCKING before that stream is ready.
*
* Remarks
* A stream will stop if this function is called, as it needs to seek and flush the buffer.
* Indicies for this function are generated as user friendly constants when compiling the FSB bank, and are available in the relevant generated header file.
* --------------
* If the stream has been opened with FSOUND_NONBLOCKING, this function will ALWAYS succeed, but puts the stream back into a non-ready state. You then have to poll after calling this to make sure the stream is ready.
* You can either do this by calling FSOUND_Stream_Play repeatedly/once a frame until it is succeeds, or FSOUND_Stream_GetOpenState.
*
* Remarks
* If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready
*
* Remarks
* This method only supports SIGNED RAW streams to be written to the buffer supplied by the callback.
* They can be 8 or 16 bit, mono or stereo.
* 'lenbytes' may be rounded down to the nearest sample alignment in bytes. Ie if you specified 1001 bytes for a 16bit stereo sample stream, len would return 1000 in the callback. (250 samples * 4 bytes per sample)
* PlayStation 2 IMPORTANT! : if FSOUND_SendData is NOT called from the stream callback the IOP will hang because it is waiting for this command to be executed before it can unlock its buffer.
*
* Remarks
* The priority for a stream DSP unit is not related to the priorities specified in fmod.h.
* The priorities are anything fom 0 onwards, and ALWAYS come after data is read/decoded for the stream *
* Remarks
* Position functions for streams work in bytes not samples.
* -----
* This function is not supported for URL based streams over the internet.
*
* Remarks
* FSOUND_MPEGACCURATE will need to be used with mp3 files that use VBR encoding for more accuracy
*
* Remarks
* If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready.
*
* Remarks
* A blocking stream will return NULL from FSOUND_Stream_Open so a return value of -3 is redundant in this case.
* A blocking stream will always return 0 if it is not NULL.
*
* Remarks
* Position functions for streams work in bytes not samples.
* Position information is also based on the current file position, not the actual playing
* position, so if the stream is only updated every 100ms, then the position will only be
* updated every 100ms.
* -----
* This function is not supported for URL based streams over the internet or CDDA streams
*
* Remarks
* Points are loaded in order of offset, so the index will represent the smallest point to the largest. *
* Remarks
* Convert samples to time by dividing the PCM value by the default samplerate. This would give you the value in seconds. Multiply by 1000 to get milliseconds.
* @param point handle to the sync point to retrieve information from
* @param pcmoffset An IntBuffer that will receive the sync point offset in pcm SAMPLES. A value of NULL will be ignored
* @return On success, the name of the syncpoint is returned as a string. On failure, NULL is returned.
*/
public static String FSOUND_Stream_GetSyncPointInfo(FSoundSyncPoint point, IntBuffer pcmoffset) {
return nFSOUND_Stream_GetSyncPointInfo(point.syncpointHandle, pcmoffset, (pcmoffset != null) ? pcmoffset.position() : 0);
}
private static native String nFSOUND_Stream_GetSyncPointInfo(ByteBuffer pointHandle, IntBuffer pcmoffset, int bufferOffset);
/**
* Get a tag field associated with an open stream
*
* Remarks
* If this function returns successfully, "value" will contain a pointer to a piece of tag-field-specific data - do not assume it will always point to a null-terminated ASCII string.
* @param stream The stream to get the tag field from.
* @param num The number of the tag field to retrieve.
* @param field TagField to receive data
* @return On success, TRUE is returned. On failure, FALSE is returned.
*/
public static boolean FSOUND_Stream_GetTagField(FSoundStream stream, int num, FSoundTagField field) {
return nFSOUND_Stream_GetTagField(stream.streamHandle, num, field);
}
private static native boolean nFSOUND_Stream_GetTagField(long streamHandle, int num, FSoundTagField field);
/**
* Returns the current time offset in stream in milliseconds.
*
* Remarks
* FSOUND_MPEGACCURATE will need to be used with mp3 files that use VBR encoding for more accuracy
*
* Remarks
* This function returns the values that will be used for subsequent internet stream opens. Internet streams that already exist may have different values.
*
* Remarks
* The result of this function should be used for informational purposes only.
* This function provides no facility to discover which internet stream the last HTTP status pertains to when there are multiple internet streams open.
*
* Remarks
* Call this function before FSOUND_Stream_Open. This function has no effect on internet streams that are already open
*
* Remarks
* The supplied metadata callback function will be called each time the specified internet stream receives a chunk of metadata.
* Do not do any time-consuming processing in a metadata callback function or network subsystem performance may degrade.
* Do not attempt to modify or free any memory passed to a metadata callback function.
*
* Remarks
* When a stream starts to play, it inherits a special high priority (256).
* It cannot be rejected by other sound effect channels in the normal fashion as the user can never set a priority above 255 normally.
* --------
* FSOUND_STEREOPAN is recommended for stereo streams if you call FSOUND_SetPan. This puts the left and right channel to full volume.
* Otherwise a normal pan will give half volume for left and right. See FSOUND_SetPan for more information on this.
* --------
* You can use normal channel based commands (such as FSOUND_SetVolume etc) on the return handle, as it is a channel handle.
*
* Remarks
* The default setting is 200ms. Under Windows CE it is default to 100ms.
* To calculate memory usage for a stream buffer, it is a simple matter of calculating sizebytes = streambuffersize * sample rate / 1000 * (bitdepth / 8) * numchannels * 2, where numchannels is 1 for mono,
* or 2 for stereo files. It is multiplied by 2 because FSOUND stream buffers are double buffers.
* Note this function does not affect user created streams, as the buffer size is specified in FSOUND_Stream_Create.
*
* Remarks
* Only calls back when a stream stops. (not when a looping stream reaches its end point)
* Note it uses a FSOUND_STREAMCALLBACK function callback. This is normally for user streams but for
* the sake of re-usability this prototype is used. 'buff' and 'length' are NULL and 0 in this case
* when the callback occurs. The return value can be TRUE or FALSE it is ignored.
* -----------
* If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready.
*
* Remarks
* This specifies how many loops, not how many times to play the sound back. Therefore when you specify 0, you will hear the sound once, if you specify 1, you will hear the sound twice, and so on.
*
* Remarks
* For streams, setting looppoints is reasonably accurate but should not be assumed to be perfectly sample accurate in all cases.
* It depends on the compression format in some cases as seek positions need to be rounded to the nearest compression block offset.
* FSOUND_MPEGACCURATE will need to be used with mp3 files that use VBR encoding for more accuracy.
* You cannot call this function wile the stream is playing, it has to be stopped
*
* Remarks
* If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready.
* Only the following modes are accepted, others will be filtered out.
* FSOUND_LOOP_BIDI, FSOUND_LOOP_NORMAL, FSOUND_LOOP_OFF, FSOUND_2D. FSOUND_LOOP_BIDI is treated as FSOUND_LOOP_NORMAL. FSOUND_2D is accepted only if the sound is not hardware.
* On playstation 2, FSOUND_HW3D and FSOUND_HW2D modes are accepted
*
* Remarks
* Position functions for streams talk in bytes and NOT samples.
* The reason for not taking the header into account is people usually want to know the offset to seek to relative to the start of their data (ie as they see it in soundforge or whatever), not from offset 0 which is almost meaningless if you dont know the format.
* --------------
* If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready. *
* @author Brian Matzon
* Remarks * This feature only works with FSB files that have multiple streams stored within it. * To remove any sentence, simply call this function with NULL and 0. * FMOD copies the list from the supplied pointer. Once the pointer is used, the caller can discard the original array. * This function will fail if the stream is playing. The stream must be stopped for it to work. * ------------ * If the stream is opened with FSOUND_NONBLOCKING, and the stream is not ready (it is still opening), then this function will return FALSE. * When it is ready, it will return TRUE, but after this call the stream is put back into a non-ready state, because it is asynchronously seeking again. * You then have to poll after calling this to make sure the stream is ready. * You can either do this by calling FSOUND_Stream_Play repeatedly/once a frame until it is succeeds, or FSOUND_Stream_GetOpenState. *
* * @param stream stream to have its position returned. * @param sentencelist IntBuffer describing a list of substream indicies to play back. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static int FSOUND_Stream_SetSubStreamSentence(FSoundStream stream, IntBuffer sentencelist) { return nFSOUND_Stream_SetSubStreamSentence(stream.streamHandle, sentencelist, sentencelist.position()); } private static native int nFSOUND_Stream_SetSubStreamSentence(long stream, IntBuffer sentencelist, int offset); /** * Sets a callback function for when a stream passes over a WAV tag/marker. These are markers that * a sound editing program such as Sound Forge can drop into the actual wave data. FMOD will * trigger callbacks with these markers when the stream plays, and pass in the string through the callback that the marker contains ** Remarks * Note it uses a FSOUND_STREAMCALLBACK function callback. This is normally for user streams but for * the sake of re-usability this prototype is used. 'buff' is a null terminated string provided by * the marker. 'len' is the offset in samples that the marker was set at. * The return value can be TRUE or FALSE, it is ignored. * ----------- * Note you can save a WAV out using an MP3 wav codec (and then just rename the WAV to MP3 if you like) to get * sync marker support for compressed MP3 files. FMOD will pick up on this and read the markers out. * -------------- * If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready. *
* @param stream to set the SyncCallback callback for * @param callback FSoundStreamCallback callback to attach to this stream * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static boolean FSOUND_Stream_SetSyncCallback(FSoundStream stream, FSoundStreamCallback callback) { FMOD.registerCallback(FMOD.FSOUND_SYNCCALLBACK, stream.streamHandle, stream, callback); return FSOUND_Stream_SetSyncCallback(stream.streamHandle); } private static native boolean FSOUND_Stream_SetSyncCallback(long streamHandle); /** * Sets the current stream's FILE position in MILLISECONDS ** Remarks * If the stream has been opened with FSOUND_NONBLOCKING, this function will not succeed until the stream is ready. * FSOUND_MPEGACCURATE will need to be used with mp3 files that use VBR encoding for more accuracy. *
* * @param stream to have its position set * @param ms Time in milliseconds to seek to. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static int FSOUND_Stream_SetTime(FSoundStream stream, int ms) { return nFSOUND_Stream_SetTime(stream.streamHandle, ms); } private static native int nFSOUND_Stream_SetTime(long stream, int ms); // ---------------------------------------------------------- // CD functions // ========================================================== /** * Opens/Closes the CD tray * * @param drive The drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @param open If open is set to true, the CD tray will be opened. If open is set to false, the CD tray will be closed. * @return On success, true is is returned. On failure, false is returned. */ public static native boolean FSOUND_CD_OpenTray(char drive, boolean open); /** * Returns the number of tracks on the currently inserted CD * * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @return On success, the number of CD tracks on the currently inserted is returned. On failure, 0 is returned */ public static native int FSOUND_CD_GetNumTracks(char drive); /** * Gets the pause status of the current CD audio track * * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @return If the track is currently paused, TRUE is returned. if the track is currently not paused, FALSE is returned. */ public static native boolean FSOUND_CD_GetPaused(char drive); /** * Returns the currently playing CD track number * * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @return On success, the CD track number currently playing is returned. (starts from 1) On failure, 0 is returned */ public static native int FSOUND_CD_GetTrack(char drive); /** * Gets the track length of a CD * * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @param track The CD track number to query the length of. (starts from 1) * @return On success, the length of the current track in milliseconds is returned. On failure, 0 is returned. */ public static native int FSOUND_CD_GetTrackLength(char drive, int track); /** * Returns the current track time playing on a CD ** Remarks * This is easily one of the slowest functions in the FMOD API. Please use it sparingly. * It seems like it shouldnt take long, but because of windows MCI API it does, and not just a little bit of time, it takes a LOT. * It seems to poll the CD driver and cause a large delay upon completion of the command. * Different algorithms were used to try and emulate this function such as simply using a timer, but this was very inaccurate, especially when pausing/unpausing a lot. *
* * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @return On success, the position of the current playing track in milliseconds is returned. On failure, 0 is returned */ public static native int FSOUND_CD_GetTrackTime(char drive); /** * Plays a CD Audio track ** Remarks * See FSOUND_CD_SetPlayMode for information on how to control playback of a CD track. * FSOUND's CD Playback system, is a non intrusive, non polling system. * This may not mean much to a lot of people, but a polling player (take the windows default CD player) will consistantly poll the CD device to update its status, which causes other applications to jerk, or pause consistantly. * This would be inexcusable in a game, to have the game halt or jerk every second to few seconds or so. * FSOUND uses timing and prediction to loop tracks and update the status of the CD, and never touches the CD device during playback, for TRUE 0% cpu usage. *
* @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @param track The CD track number to query the length of. (starts from 1) * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_CD_Play(char drive, int track); /** * Sets the pause status of the currently playing CD audio track * * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @param paused TRUE to pause track, FALSE to unpause track * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_CD_SetPaused(char drive, boolean paused); /** * Sets the playback mode of the CD * * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @param mode See FSOUND_CDPLAYMODES for a list of valid parameters to send to this function */ public static native void FSOUND_CD_SetPlayMode(char drive, int mode); /** * Performs a seek within a track specified by milliseconds ** Remarks * This function will start the track if it is not playing *
* * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @param ms Time to seek into the current track in milliseconds * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_CD_SetTrackTime(char drive, int ms); /** * Sets the volume of the playing CD audio * * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @param volume An integer value from 0-255. 0 being the lowest volume, 255 being the highest (full). * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_CD_SetVolume(char drive, int volume); /** * Stops the currently playing CD audio track * * @param drive the drive ID to use. 0 is the default CD drive. Using D or E in single quotes would be D: or E: for example. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_CD_Stop(char drive); // ---------------------------------------------------------- // DSP functions // ========================================================== /** * Clears the mixbuffer, especially handy if you are doing a large file operation which * halts the system. * You might try and stop all the sounds, but if you do your file operation straight after * this, it will not have a chance to flush the mixbuffer normally, so this function is called. * It stops the effect of stuttering looping sound while your file operation happens. ** Remarks * The best way to do it is like this. Turn off the sfx and music DSP units, clear the mix buffer, * then when the operation that halts the machine is done, just re-enable the sfx and music DSP units. * Disabling these units stops the timer trying to get 1 or 2 more mixes in during the file operation, * which will cause more stuttering. * ie. * FSOUND_DSP_SetActive(FSOUND_DSP_GetSFXUnit(), FALSE); * FSOUND_DSP_SetActive(FSOUND_DSP_GetMusicUnit(), FALSE); * FSOUND_DSP_ClearMixBuffer(); * // * // maching halting operation here * // * FSOUND_DSP_SetActive(FSOUND_DSP_GetSFXUnit(), TRUE); * FSOUND_DSP_SetActive(FSOUND_DSP_GetMusicUnit(), TRUE); *
*/ public static native void FSOUND_DSP_ClearMixBuffer(); /** * Creates a DSP unit, and places it in the DSP chain position specified by the priority * parameter. Read the remarks section carefully for issues regarding DSP units. * DSP units are freed with FSOUND_DSP_Free ** Remarks * A dsp unit is NOT ACTIVE by default. You have to activate it with FSOUND_DSP_SetActive * --------------------------------------------------------------------------------------- * Priorities and default system units. * --------------------------------------------------------------------------------------- * A note on priorities. FSOUND processes DSP units in order of priority. A 0 priority * unit gets processed first, a 1 priority unit gets processed next, and so on. * FSOUND actually uses these DSP units to mix its sound effects and music! Yes, you have * access to them (be careful!). It is possible to totally remove, replace or deactivate * all of FSOUND's system units so that it does nothing at all! * FSOUND has preinstalled default system units at the following priority locations: * FSOUND_DSP_DEFAULTPRIORITY_CLEARUNIT (priority 0) - Clear Unit. This unit clears out * the mixbuffer for the next units to mix into. You can disable this unit and replace * it with something other than a clearer, such as a scaler, which fades down the mix * buffer instead of clearing it, to produce a very rough echo effect. * FSOUND_DSP_DEFAULTPRIORITY_SFXUNIT (priority 100) - SFX Unit. This unit mixes sound * effect channels into the mix buffer, which was previously cleared with the Clear * Unit. * FSOUND_DSP_DEFAULTPRIORITY_MUSICUNIT (priority 200) - Music Unit. This unit mixes all * music channels into the mix buffer, which was previously mixed into with the SFX * Unit. * FSOUND_DSP_DEFAULTPRIORITY_CLIPANDCOPYUNIT (priority 1000) - Clip and Copy Unit. This * unit takes the finally mixed buffer, and clips it to the output stream size (if it * needs to), and then sends it off to the sound device. It is done last. If this is * disabled you will hear no sound. * --------------------------------------------------------------------------------------- * Buffer Lengths. * --------------------------------------------------------------------------------------- * The 'length' value of the DSP callback is roughly 20ms worth of data. * Use FSOUND_DSP_GetBufferLength to get the exact callback length. * --------------------------------------------------------------------------------------- * Buffer Widths * --------------------------------------------------------------------------------------- * Remember that FSOUND uses different buffer types depending on what type of mixer it is. * You will have to compensate for this by writing different routines depending on the * mixer type (ie mmx or non mmx), just like FSOUND does. * Currently there are the 3 types of mixers and their buffer sizes. * You can get the type of mixer being used by calling the FSOUND_GetMixer function. * You may want to check on this inside your callback, or set up a function pointer system, * whatever you think is suitable (it costs nothing to do a FSOUND_GetMixer every time). * - FSOUND_MIXER_BLENDMODE : This buffer is a stereo, signed 32bit buffer (8 bytes per * sample). The data is in integer format. * Data written to this buffer is not clipped and passed to the output stream until the * very end of the chain (the clip and copy unit). For this type of mixer, you dont * have to worry about clipping becuase FSOUND does this for you. * - FSOUND_MIXER_QUALITY_FPU / FSOUND_MIXER_QUALITY_FPU_VOLUMERAMP: This buffer is also a * stereo, signed 32bit buffer (8 bytes per sample). This data is in floating point * format. * The same clip and copy rules apply here as for the above mixer. * - Any MMX based mixer : This buffer is a stereo, signed 16bit buffer (4 bytes per sample). * When writing to this buffer, you must make sure the result does not overflow this * signed 16bit range. * If you add data into to this buffer, make sure it is clipped to a signed 16bit range * before writing it back. FSOUND only copies this data to the output stream, it does * not clip it. * --------------------------------------------------------------------------------------- * Speed * --------------------------------------------------------------------------------------- * DSP Units are processed then and there, inside the mixing routine. Remember to make * your process as FAST as possible, or the output device's play cursor will catch up to * FSOUND's write cursor while your routine takes its time to complete, and make it start * to break up. * So basically, if it isnt fast, then FSOUND will not be able to send the data to the * output device in time for the next mixer update, and the result will be corrupted sound. * FSOUND_DSP_MixBuffers is available now, so if you need to mix some raw data into the output * buffer quickly, you can use FSOUND's own optimized mixer directly to do it! * Finally, you can see how your routine affects cpu usage, by using FSOUND_GetCPUUsage. * The cpu usage returned by this function includes any time spent in DSP units as well. * (this function times everything). If you are really bored, you can see how much FSOUND's * system units take cpu-wise, by turning them on and off and seeing how they affect * performance. *
* @param callbackHandler This is a reference to your DSP Unit callback, of type FSOUND_DSPCALLBACK. * The prototype for a callback is declared in the following fashion. * Callbacks must return a pointer to the buffer you work on, so that * the next dsp unit can work on it. * See the definition of FSOUND_DSPCALLBACK for more. * @param priority Order in the priority chain. Valid numbers are 0 to 1000, 0 being * highest priority (first), with 1000 being lowest priority (last). * Note that FSOUNDs soundeffects mixers and copy routines are considered * part of this DSP unit chain which you can play with. * @return On success, a new valid DSP unit is returned. On failure, NULL is returned. */ public static FSoundDSPUnit FSOUND_DSP_Create(FSoundDSPCallback callbackHandler, int priority) { FSoundDSPUnit dspUnit = null; ByteBuffer handle = nFSOUND_DSP_Create(priority); if(handle != null) { ByteBuffer dspID = (ByteBuffer) BufferUtils.createByteBuffer(8).putLong(FSoundDSPUnit.getNextId()).flip(); dspUnit= new FSoundDSPUnit(handle, dspID); FMOD.registerCallback(FMOD.FSOUND_DSPCALLBACK, dspID.getLong(0), dspUnit, callbackHandler); } return dspUnit; } private static native ByteBuffer nFSOUND_DSP_Create(int priority); /** * Frees and removes a DSP unit from the DSP chain * * @param unit DSP unit to be freed */ public static void FSOUND_DSP_Free(FSoundDSPUnit unit) { nFSOUND_DSP_Free(unit.dspHandle); FMOD.registerCallback(FMOD.FSOUND_DSPCALLBACK, unit.dspTrackingID.get(0), unit, null); } private static native void nFSOUND_DSP_Free(ByteBuffer dspUnitHandle); /** * Allows the user to toggle a DSP unit on or off ** Remarks * It is possible to toggle on and off FSOUNDs internal DSP units, though not recommended *
* @param unit DSP unit to have its active flag changed * @param active Flag to say whether DSP unit should be rendered active or inactive. valid values are TRUE or FALSE */ public static void FSOUND_DSP_SetActive(FSoundDSPUnit unit, boolean active) { nFSOUND_DSP_SetActive(unit.dspHandle, active); } private static native void nFSOUND_DSP_SetActive(ByteBuffer dspUnitHandle, boolean active); /** * Returns if a DSP unit is active or not ** Remarks * It is possible to toggle on and off FSOUNDs internal DSP units, though not recommended *
* @param unit DSP unit to have its active flag returned * @return On success, TRUE is returned. On failure, FALSE is returned */ public static boolean FSOUND_DSP_GetActive(FSoundDSPUnit unit) { return nFSOUND_DSP_GetActive(unit.dspHandle); } private static native boolean nFSOUND_DSP_GetActive(ByteBuffer dspUnitHandle); /** * Returns the buffer lenth passed by the DSP system to DSP unit callbacks, so you can allocate memory etc * using this data ** Remarks * Remember this is samples not bytes. To convert to bytes you * will have to multiply by 4 for mmx mixers, 8 for other mixers. * (a stereo 16bit sample = 4 bytes, and a stereo 32bit sample (ie fpu) = 8 bytes) *
* @return The size of the DSP unit buffer in SAMPLES (not bytes) */ public static native int FSOUND_DSP_GetBufferLength(); /** * This is the total size in samples (not bytes) of the FSOUND mix buffer. This is affected * by FSOUND_SetBufferSize. ** Remarks * Remember this is samples not bytes. To convert to bytes you * will have to multiply by 4 for mmx mixers, 8 for other mixers. * (a stereo 16bit sample = 4 bytes, and a stereo 32bit sample (ie fpu) = 8 bytes) *
* @return The size of the FSOUND mixing buffer in SAMPLES (not bytes). */ public static native int FSOUND_DSP_GetBufferLengthTotal(); /** * Changes a DSP Unit's priority position in the DSP chain ** Remarks * DSP units with the same priority as a previous unit already in the chain will be placed * AFTER all like priority units *
* @param unit DSP unit to have its priority changed * @param priority Order in the priority chain. Valid numbers are 0 to 1000, 0 being highest priority (first), with 1000 being lowest priority (last). */ public static void FSOUND_DSP_SetPriority(FSoundDSPUnit unit, int priority) { nFSOUND_DSP_SetPriority(unit.dspHandle, priority); } private static native void nFSOUND_DSP_SetPriority(ByteBuffer dspUnitHandle, int priority); /** * Returns the priority status in the DSP chain, of a specified unit. ** Remarks * DSP units with the same priority as a previous unit already in the chain will be placed * AFTER all like priority units *
* @param unit DSP unit to get priority value from * @return On success, the priority of the unit, from 0 to 1000. On failure, -1 is returned. */ public static int FSOUND_DSP_GetPriority(FSoundDSPUnit unit) { return nFSOUND_DSP_GetPriority(unit.dspHandle); } private static native int nFSOUND_DSP_GetPriority(ByteBuffer dspUnitHandle); /** * Returns a reference to FSOUND's system DSP clear unit ** Remarks * The FSOUND clear DSP unit simply sets the mix buffer to 0, silencing it *
* @return reference to the DSP unit */ public static FSoundDSPUnit FSOUND_DSP_GetClearUnit() { if(FMOD.fmodClearUnit == null) { FMOD.fmodClearUnit = new FSoundDSPUnit(nFSOUND_DSP_GetClearUnit()); } return FMOD.fmodClearUnit; } private static native ByteBuffer nFSOUND_DSP_GetClearUnit(); /** * Returns a reference to FSOUND's system Clip and Copy DSP unit ** Remarks * The FSOUND ClipAndCopy DSP unit clips the 32bit buffer down to fit the soundcard's 16bit stereo output, and sends it off to the hardware. *
* @return reference to the DSP unit */ public static FSoundDSPUnit FSOUND_DSP_GetClipAndCopyUnit() { if(FMOD.fmodClipAndCopyUnit == null) { FMOD.fmodClipAndCopyUnit = new FSoundDSPUnit(nFSOUND_DSP_GetClipAndCopyUnit()); } return FMOD.fmodClipAndCopyUnit; } private static native ByteBuffer nFSOUND_DSP_GetClipAndCopyUnit(); /** * Returns a reference to FSOUND's system DSP Music mixer unit ** Remarks * The FSOUND Music DSP executes the FMUSIC engine and mixes the sounds spawned by the music player *
* @return reference to the DSP unit */ public static FSoundDSPUnit FSOUND_DSP_GetMusicUnit() { if(FMOD.fmodMusicUnit == null) { FMOD.fmodMusicUnit = new FSoundDSPUnit(nFSOUND_DSP_GetMusicUnit()); } return FMOD.fmodMusicUnit; } private static native ByteBuffer nFSOUND_DSP_GetMusicUnit(); /** * Returns a reference to FSOUND's system DSP SFX mixer unit ** Remarks * The FSOUND SFX DSP unit mixes sound effects together spawned by the user *
* @return reference to the DSP unit */ public static FSoundDSPUnit FSOUND_DSP_GetSFXUnit() { if(FMOD.fmodSFXUnit == null) { FMOD.fmodSFXUnit = new FSoundDSPUnit(nFSOUND_DSP_GetSFXUnit()); } return FMOD.fmodSFXUnit; } private static native ByteBuffer nFSOUND_DSP_GetSFXUnit(); /** * Returns a reference to FSOUND's system DSP FFT processing unit ** Remarks * The FSOUND FFT DSP executes the FFT engine to allow FSOUND_DSP_GetSpectrum to be used. * The FFT unit is off by default, due to the cpu expense incurred in running. Turn it on to use FSOUND_DSP_GetSpectrum *
* @return reference to the DSP unit */ public static FSoundDSPUnit FSOUND_DSP_GetFFTUnit() { if(FMOD.fmodFFTUnit == null) { FMOD.fmodFFTUnit = new FSoundDSPUnit(nFSOUND_DSP_GetFFTUnit()); } return FMOD.fmodFFTUnit; } private static native ByteBuffer nFSOUND_DSP_GetFFTUnit(); /** * Function to return a FloatBuffer to the current spectrum buffer. The buffer contains 512 floating * point values that represent each frequency band's amplitude for the current FMOD SoundSystem * mixing buffer. The range of frequencies covered by the spectrum is 1 to the nyquist frequency * or half of the output rate. So if the output rate is 44100, then frequencies provided are up * to 22050. (entry 511) ** Remarks * Note that hardware sounds, MIDI, files do not register on the spectrum graph as they are not run through FMODs DSP system. * Note that to use this you have to turn on the FSOUND FFT DSP unit. This is achieved by calling FSOUND_DSP_GetFFTUnit, then using FSOUND_DSP_SetActive to turn it on. *
* @return FloatBuffer containing 512 floats */ public static FloatBuffer FSOUND_DSP_GetSpectrum() { return nFSOUND_DSP_GetSpectrum().order(ByteOrder.nativeOrder()).asFloatBuffer(); } private static native ByteBuffer nFSOUND_DSP_GetSpectrum(); /** * Allows the user to mix their own data from one buffer to another, using FSOUNDs optimized * mixer routines. This was mainly provided for DSP routines, though it can be used for * anything. ** Remarks * 'destbuffer' should always the format of the mixing output buffer, as it will use the mixer * currently running to do the mixing. * For MMX it is 16bit stereo, so it is 4 bytes per output sample (word left, word right) * For Standard Blend mode it is 32bit stereo, so it is 8 bytes per output sample (left dword, right dword) * For FPU mixer it is 32bit float stereo, so it is 8 bytes per output sample (left float, right float) * FSOUND_GetMixer can be used to determine which mixer is being used. *
* @param destbuffer Pointer to a buffer to have the data mixed into. * @param srcbuffer Pointer to the source buffer to be mixed in. * @param len Amount to mix in SAMPLES. * @param freq Speed to mix data to output buffer. Remember if you mix at a rate * different than the output rate, the buffer lengths will have to be * different to compensate. Ie if the output rate is 44100 and you supply * a value of 88200 to FSOUND_DSP_MixBuffers, you will only need a destbuffer * that is half the size of srcbuffer. If you supply a value of 22050 then * you will need a destbuffer that is twice as big as srcbuffer. If they * are both the same size then it will only mix half of the data. * @param vol volume scalar value of mix. Valid values are 0 (silence) to 255 * (full volume). See FSOUND_SetVolume for more information. * @param pan pan value for data being mixed. Valid values are 0 (full left), 128 * (middle), 255 (full right) and FSOUND_STEREOPAN. See FSOUND_SetPan for * more information. * @param mode Bit settings to describe the source buffer. Valid values are found in * FSOUND_MODES, but only 8/16bit and stereo/mono flags are interpreted, other flags are ignored. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static boolean FSOUND_DSP_MixBuffers( ByteBuffer destbuffer, ByteBuffer srcbuffer, int len, int freq, int vol, int pan, int mode) { return nFSOUND_DSP_MixBuffers( destbuffer, destbuffer.position(), srcbuffer, srcbuffer.position(), len, freq, vol, pan, mode); } private static native boolean nFSOUND_DSP_MixBuffers( ByteBuffer destbuffer, int destBufferOffset, ByteBuffer srcbuffer, int srcBufferOffset, int len, int freq, int vol, int pan, int mode); // ---------------------------------------------------------- // FX functions // ========================================================== /** * Disables effect processing for ALL effects on the specified channel ** Remarks * FSOUND_ALL is supported. Passing this will disable fx on ALL channels available. * This command can only be issued while the channel is paused or stopped. *
* * @param channel Channel number/handle to disable all fx for * @return On success, TRUE is returned. On failure, FALSE is returned */ public static native boolean FSOUND_FX_Disable(int channel); /** * Enables effect processing for the specified channel. This command continues to add effects to a channel (up to 16) until FSOUND_FX_Disable is called. ** Remarks * FSOUND_ALL is supported. Passing this will enable fx on ALL channels available. * This command can only be issued while the channel is paused. * If an effect is not enabled, then it will not be affected by its corresponding FSOUND_FX_Set functions. * This function must be played after a paused PlaySoundEx (ie FSOUND_PlaySoundEx(FSOUND_FREE, sound, NULL, TRUE)), and before * the FSOUND_SetPaused(FALSE) so that the hardware can get the resource before it starts playing. * A total of 16 FX per channel is allowed, any more will result in an error. FX are reset to 0 after a sound is stopped or played. (but as above, before the unpausing of a play-paused sound). * Warning : This function is expensive to call as it has to set up fx buffers etc. It is best to call it once, reserve the channel then reuse the channel index when calling playsound without calling it again. * Note : Channels with FX enabled sounds cannot have their frequency changed. *
* * @param channel Channel number/handle to disable all fx for * @param fxtype A single fx enum value to enable certain effects. * @return On success, an FX id is returned. On failure, -1 is returned */ public static native int FSOUND_FX_Enable(int channel, int fxtype); /** * Sets the parameters for the chorus effect on a particular channel ** Remarks * Make sure you have enabled this effect with FSOUND_FX_CHORUS before using this function. *
* * @param fxid fx handle generated by FSOUND_FX_Enable, to set chorus parameters for. * @param WetDryMix Ratio of wet (processed) signal to dry (unprocessed) signal. Must be in the range from 0 through 100 (all wet). * @param Depth Percentage by which the delay time is modulated by the low-frequency oscillator, in hundredths of a percentage point. Must be in the range from 0 through 100. The default value is 25. * @param Feedback Percentage of output signal to feed back into the effects input, in the range from -99 to 99. The default value is 0. * @param Frequency Frequency of the LFO, in the range from 0 to 10. The default value is 0. * @param Waveform Waveform of the LFO. Defined values are 0 triangle. 1 sine. By default, the waveform is a sine. * @param Delay Number of milliseconds the input is delayed before it is played back, in the range from 0 to 20. The default value is 0 ms. * @param Phase Phase differential between left and right LFOs, in the range from 0 through 4. Possible values are defined as follows: * 0 -180 degrees * 1 - 90 degrees * 2 0 degrees * 3 90 degrees * 4 180 degrees * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_FX_SetChorus( int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase); /** * Sets the parameters for the compressor effect on a particular channel ** Remarks * Make sure you have enabled this effect with FSOUND_FX_COMPRESSOR before using this function *
* * @param fxid fx handle generated by FSOUND_FX_Enable, to set compressor parameters for. * @param Gain Output gain of signal after compression, in the range from -60 to 60. The default value is 0 dB. * @param Attack Time before compression reaches its full value, in the range from 0.01 to 500. The default value is 0.01 ms. * @param Release Speed at which compression is stopped after input drops below fThreshold, in the range from 50 to 3000. The default value is 50 ms. * @param Threshold Point at which compression begins, in decibels, in the range from -60 to 0. The default value is -10 dB. * @param Ratio Compression ratio, in the range from 1 to 100. The default value is 10, which means 10:1 compression. * @param Predelay Time after lThreshold is reached before attack phase is started, in milliseconds, in the range from 0 to 4. The default value is 0 ms. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_FX_SetCompressor( int fxid, float Gain, float Attack, float Release, float Threshold, float Ratio, float Predelay); /** * Sets the parameters for the distortion effect on a particular channel ** Remarks * Make sure you have enabled this effect with FSOUND_FX_DISTORTION before using this function *
* * @param fxid fx handle generated by FSOUND_FX_Enable, to set distortion parameters for. * @param Gain Amount of signal change after distortion, in the range from -60 through 0. The default value is 0 dB. * @param Edge Percentage of distortion intensity, in the range in the range from 0 through 100. The default value is 50 percent. * @param PostEQCenterFrequency Center frequency of harmonic content addition, in the range from 100 through 8000. The default value is 4000 Hz. * @param PostEQBandwidth Width of frequency band that determines range of harmonic content addition, in the range from 100 through 8000. The default value is 4000 Hz. * @param PreLowpassCutoff Filter cutoff for high-frequency harmonics attenuation, in the range from 100 through 8000. The default value is 4000 Hz. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_FX_SetDistortion( int fxid, float Gain, float Edge, float PostEQCenterFrequency, float PostEQBandwidth, float PreLowpassCutoff); /** * Sets the parameters for the echo effect on a particular channel ** Remarks * Make sure you have enabled this effect with FSOUND_FX_Enable and FSOUND_FX_ECHO before using this function. *
* * @param fxid fx handle generated by FSOUND_FX_Enable, to set echo parameters for. * @param WetDryMix Ratio of wet (processed) signal to dry (unprocessed) signal. Must be in the range from 0 through 100 (all wet). * @param Feedback Percentage of output fed back into input, in the range from 0 through 100. The default value is 0. * @param LeftDelay Delay for left channel, in milliseconds, in the range from 1 through 2000. The default value is 333 ms. * @param RightDelay Delay for right channel, in milliseconds, in the range from 1 through 2000. The default value is 333 ms. * @param PanDelay Value that specifies whether to swap left and right delays with each successive echo. The default value is FALSE, meaning no swap. Possible values are defined as TRUE or FALSE. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_FX_SetEcho( int fxid, float WetDryMix, float Feedback, float LeftDelay, float RightDelay, int PanDelay); /** * Sets the parameters for the echo effect on a particular channel ** Remarks * Make sure you have enabled this effect with FSOUND_FX_Enable and FSOUND_FX_FLANGER before using this function. *
* * @param fxid fx handle generated by FSOUND_FX_Enable, to set flanger parameters for. * @param WetDryMix Ratio of wet (processed) signal to dry (unprocessed) signal. Must be in the range from 0 through 100 (all wet). * @param Depth Percentage by which the delay time is modulated by the low-frequency oscillator (LFO), in hundredths of a percentage point. Must be in the range from 0 through 100. The default value is 25. * @param Feedback Percentage of output signal to feed back into the effects input, in the range from -99 to 99. The default value is 0. * @param Frequency Frequency of the LFO, in the range from 0 to 10. The default value is 0. * @param Waveform Waveform of the LFO. By default, the waveform is a sine. Possible values are defined as follows: * 0 - Triangle. * 1 - Sine. * @param Delay Number of milliseconds the input is delayed before it is played back, in the range from 0 to 4. The default value is 0 ms. * @param Phase Phase differential between left and right LFOs, in the range from 0 through 4. Possible values are defined as follows: * 0 -180 degrees * 1 - 90 degrees * 2 0 degrees * 3 90 degrees * 4 180 degrees * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_FX_SetFlanger( int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase); /** * Sets the parameters for the echo effect on a particular channel ** Remarks * Make sure you have enabled this effect with FSOUND_FX_Enable and FSOUND_FX_GARGLE before using this function. *
* * @param fxid fx handle generated by FSOUND_FX_Enable, to set gargle parameters for. * @param RateHz Rate of modulation, in Hertz. Must be in the range from 1 through 1000. * @param WaveShape Shape of the modulation wave. The following values are defined. * 0 - Triangular wave. * 1 - Square wave. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_FX_SetGargle(int fxid, int RateHz, int WaveShape); /** * Sets the parameters for the I3DL2 Reverb effect on a particular channel ** Remarks * Make sure you have enabled this effect with FSOUND_FX_Enable and FSOUND_FX_I3DL2REVERB before using this function. *
* * @param fxid fx handle generated by FSOUND_FX_Enable, to set I3DL2 Reverb parameters for. * @param Room Attenuation of the room effect, in millibels (mB), in the range from -10000 to 0. The default value is -1000 mB. * @param RoomHF Attenuation of the room high-frequency effect, in mB, in the range from -10000 to 0. The default value is 0 mB. * @param RoomRolloffFactor Rolloff factor for the reflected signals, in the range from 0 to 10. The default value is 0.0. The rolloff factor for the direct path is controlled by the listener. * @param DecayTime Decay time, in seconds, in the range from .1 to 20. The default value is 1.49 seconds. * @param DecayHFRatio Ratio of the decay time at high frequencies to the decay time at low frequencies, in the range from 0.1 to 2. The default value is 0.83. * @param Reflections Attenuation of early reflections relative to lRoom, in mB, in the range from -10000 to 1000. The default value is -2602 mB. * @param ReflectionsDelay Delay time of the first reflection relative to the direct path, in seconds, in the range from 0 to 0.3. The default value is 0.007 seconds. * @param Reverb Attenuation of late reverberation relative to lRoom, in mB, in the range from -10000 to 2000. The default value is 200 mB. * @param ReverbDelay Time limit between the early reflections and the late reverberation relative to the time of the first reflection, in seconds, in the range from 0 to 0.1. The default value is 0.011 seconds. * @param Diffusion Echo density in the late reverberation decay, in percent, in the range from 0 to 100. The default value is 100.0 percent. * @param Density Modal density in the late reverberation decay, in percent, in the range from 0 to 100. The default value is 100.0 percent. * @param HFReference Reference high frequency, in hertz, in the range from 20 to 20000. The default value is 5000.0 Hz. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_FX_SetI3DL2Reverb( int fxid, int Room, int RoomHF, float RoomRolloffFactor, float DecayTime, float DecayHFRatio, int Reflections, float ReflectionsDelay, int Reverb, float ReverbDelay, float Diffusion, float Density, float HFReference); /** * Sets the parameters for the I3DL2 Reverb effect on a particular channel ** Remarks * Make sure you have enabled this effect with FSOUND_FX_Enable and FSOUND_FX_PARAMEQ before using this function. *
* * @param fxid fx handle generated by FSOUND_FX_Enable, to set ParamEQ parameters for. * @param Center Center frequency, in hertz, in the range from 80 to 16000. This value cannot exceed one-third of the frequency of the buffer. Default is 8000. * @param Bandwidth Bandwidth, in semitones, in the range from 1 to 36. Default is 12. * @param Gain Gain, in the range from -15 to 15. Default is 0. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_FX_SetParamEQ(int fxid, float Center, float Bandwidth, float Gain); /** * Sets the parameters for the Waves Reverb effect on a particular channel ** Remarks * Make sure you have enabled this effect with FSOUND_FX_Enable and FSOUND_WAVES_REVERB before using this function. *
* * @param fxid fx handle generated by FSOUND_FX_Enable, to set ParamEQ parameters for. * @param InGain Input gain of signal, in decibels (dB), in the range from -96 through 0. The default value is 0 dB. * @param ReverbMix Reverb mix, in dB, in the range from -96 through 0. The default value is 0 dB. * @param ReverbTime Reverb time, in milliseconds, in the range from .001 through 3000. The default value is 1000. * @param HighFreqRTRatio In the range from .001 through .999. The default value is 0.001. * @return On success, TRUE is returned. On failure, FALSE is returned. */ public static native boolean FSOUND_FX_SetWavesReverb(int fxid, float InGain, float ReverbMix, float ReverbTime, float HighFreqRTRatio); // ---------------------------------------------------------- // Recording functions // ========================================================== /** * Returns the currently selected recording driver number. Drivers are enumerated when selecting a driver * with FSOUND_Record_SetDriver or other driver related functions such as FSOUND_Record_GetNumDrivers or * FSOUND_Record_GetDriverName * * @return Currently selected driver id */ public static native int FSOUND_Record_GetDriver(); /** * Returns the name of the selected recording driver. Drivers are enumerated when selecting a driver with * FSOUND_Record_SetDriver or other driver related functions such as FSOUND_Record_GetNumDrivers or FSOUND_Record_GetDriver * * @param id Enumerated driver ID. This must be in a valid range delimited by FSOUND_Record_GetNumDrivers, * @return On success, a string containing the name of the specified device is returned. * The number of drivers enumerated can be found with FSOUND_Record_GetNumDrivers. On failure, NULL is returned */ public static native String FSOUND_Record_GetDriverName(int id); /** * Returns the number of sound cards or devices enumerated for the current input type. (Direct * Sound, WaveOut etc.) * * @return Total number of enumerated sound devices */ public static native int FSOUND_Record_GetNumDrivers(); /** * Gets the position in the sample buffer that has been recorded to ** Remarks * Note. This is not the 'recording cursor', but rather the latest point that the input has been copied to your sample *
* * @return On success, the offset in SAMPLES, for the record buffer that the input device has just written up to is returned. * On failure (recording device hasnt been started), -1 is returned. */ public static native int FSOUND_Record_GetPosition(); /** * Returns the name of the selected recording driver. Drivers are enumerated when selecting a driver with * FSOUND_Record_SetDriver or other driver related functions such as FSOUND_Record_GetNumDrivers or FSOUND_Record_GetDriver * * @param driverno Recording driver number to select. >=0 will select the DEFAULT recording sound driver. <0 Selects other valid drivers that can be listed with FSOUND_Record_GetDriverName. * @return On success, TRUE is returned. On failure, FALSE is returned */ public static native boolean FSOUND_Record_SetDriver(int driverno); /** * Starts recording into a predefined sample using the sample's default playback rate as the recording rate ** Remarks * If you want to play back the sample at the same time is is recording, you will have to play the sound and try and keep it just behind the recording cursor. * Under FSOUND_OUTPUT_OSS mode, it is single duplex, so playback will stop when recording is in progress! Try FSOUND_OUTPUT_ALSA for full duplex as they have better drivers in this respect. * ------------- * The recording/playback rates are slightly innacurate and are not identical (ie 44100.0 for playback, 44100.1 for recording), so one could possibly be faster or slower than the other. In this case the recording and the playback cursor could overlap, and the output will sound corrupted. * To counter this you might adjust the playback frequency of the channel you are playing the record sample on while it plays, using FSOUND_GetCurrentPosition and FSOUND_Record_GetPosition as calibration points. * In the recording sample there is an example of trying to play back sound as it records, and the mechanism to try and keep the 2 cursors a safe distance from each other is employed. *
* @param sample The sample to record into. * @param loop TRUE or FALSE flag whether the recorder should keep recording once it has hit the end, * and start from the start again, therefore creating a continuous recording session into that * sample buffer. Looping the recording buffer is good for realtime processing of recorded * information, as you can record and playback the sample at the same time. * @return TRUE or FALSE flag whether the recorder should keep recording once it has hit the end, * and start from the start again, therefore creating a continuous recording session into that * sample buffer. Looping the recording buffer is good for realtime processing of recorded * information, as you can record and playback the sample at the same time */ public static boolean FSOUND_Record_StartSample(FSoundSample sample, boolean loop) { return nFSOUND_Record_StartSample(sample.sampleHandle, loop); } private static native boolean nFSOUND_Record_StartSample(long sampleHandle, boolean loop); /** * Halts recording to the specified sample * * @return On success, TRUE is returned. On failure, FALSE is returned */ public static native boolean FSOUND_Record_Stop(); // ---------------------------------------------------------- // Reverb functions // ========================================================== /** * Sets hardware reverb parameters for advanced tuning. * The best way to modify these is to set everything to use pre-defined presets given in the header, and then start modifying values ** Remarks * You must be using FSOUND_OUTPUT_DSOUND as the output mode for this to work. * In dsound, the reverb will only work if you have an EAX compatible soundcard such as the SBLive, and your sample/stream was created with the FSOUND_HW3D flag. * For GameCube, use FSOUND_AUXFX_xxx api *
* @param reverb reference to a FSoundReverbProperties. * @return On success, TRUE is returned. On failure, FALSE is returned */ public static boolean FSOUND_Reverb_SetProperties(FSoundReverbProperties reverb) { return nFSOUND_Reverb_SetProperties(reverb.reverbHandle); } private static native boolean nFSOUND_Reverb_SetProperties(long reverbHandle); /** * Returns the current hardware reverb environment. * The best way to modify these is to set everything to use pre-defined presets given in the header, and then start modifying values ** Remarks * These values are only relevant if you are in DSOUND mode with an EAX3 compatible soundcard, or XBOX and PS2 *
* @param reverb reference to a FSoundReverbProperties. * @return On success, TRUE is returned. On failure, FALSE is returned */ public static boolean FSOUND_Reverb_GetProperties(FSoundReverbProperties reverb) { return nFSOUND_Reverb_GetProperties(reverb.reverbHandle); } private static native boolean nFSOUND_Reverb_GetProperties(long reverbHandle); /** * Sets the channel specific reverb properties for hardware, including wet/dry mix (room size), and things like obstruction and occlusion properties ** Remarks * FSOUND_ALL is supported here. Passing this will set ALL channels to specified reverb properties. * If FSOUND_ALL is used the last channel success flag will be returned. This return value not useful in most circumstances. * ----------------- * Under Win32, you must be using FSOUND_OUTPUT_DSOUND as the output mode for this to work. * In DSound, the reverb will only work if you have an EAX compatible soundcard such as the SBLive, and your sample/stream was created with the FSOUND_HW3D flag. * ----------------- * On PlayStation2, the 'Room' parameter is the only parameter supported. The hardware only allows 'on' or 'off', so the reverb will be off when 'Room' is -10000 and on for every other value. * ----------------- * On XBox, it is possible to apply reverb to 2d voices using this function. By default reverb is turned off for 2d voices. * If this 2d voice was being positioned in a 5.1 array with the xbox only function FSOUND_SetLevels, then calling this function will disable that capability in favour of enabling reverb for the 2d voice. * It is a limitation of the xbox hardware that only one of the other of these features can be executed at one time. *
* @param channel The channel to have its reverb properties changed. FSOUND_ALL can also be used (see remarks) * @param reverb reference to a FSoundReverbChannelProperties. * @return On success, TRUE is returned. On failure, FALSE is returned */ public static boolean FSOUND_Reverb_SetChannelProperties(int channel, FSoundReverbChannelProperties reverb) { return nFSOUND_Reverb_SetChannelProperties(channel, reverb.reverbHandle); } private static native boolean nFSOUND_Reverb_SetChannelProperties(int channel, long reverbHandle); /** * This function gets the current reverb properties for this channel * @param channel The channel to have its reverb mix returned * @param reverb reference to a FSoundReverbChannelProperties. * @return On success, TRUE is returned. On failure, FALSE is returned */ public static boolean FSOUND_Reverb_GetChannelProperties(int channel, FSoundReverbChannelProperties reverb) { return nFSOUND_Reverb_GetChannelProperties(channel, reverb.reverbHandle); } private static native boolean nFSOUND_Reverb_GetChannelProperties(int channel, long reverbHandle); // ---------------------------------------------------------- // Callbacks // ========================================================== /** * This is the callback rutine called by the native implementation whenever a * register callback is notified. * * @param handle Handle to native object being monitored * @param param parameter passed to callback */ private static ByteBuffer dsp_callback(long dsp_id, ByteBuffer originalbuffer, ByteBuffer newbuffer, int length) { // we got a callback - notify everybody ArrayList handlers = FMOD.getCallbacks(FMOD.FSOUND_DSPCALLBACK, dsp_id); FMOD.WrappedCallback wCallback = (FMOD.WrappedCallback) handlers.get((int)0); FSoundDSPCallback callback = (FSoundDSPCallback) wCallback.callback; return callback.FSOUND_DSPCALLBACK(originalbuffer, newbuffer, length); } /** * This is the callback rutine called by the native implementation whenever a * register callback is notified. * * @param handle Handle to native object being monitored * @param param parameter passed to callback */ private static void stream_callback(long streamHandle, ByteBuffer buff, int length) { // we got a callback - notify everybody ArrayList handlers = FMOD.getCallbacks(FMOD.FSOUND_STREAMCALLBACK, streamHandle); for(int i=0; i