< GeeXLab Reference Guide />

> Back to Reference Guide Index


gh_audio library

Description

gh_audio is the module that manages sounds: creation, destruction, playing. The audio module is based on FMOD and is availablew for Windows, Linux and macOS platforms. For Raspberry Pi platform, look at the gh_av library.


Number of functions: 19

  1. gh_audio.sound_create (Lua - Python)
  2. gh_audio.sound_create_from_zip (Lua - Python)
  3. gh_audio.sound_create_from_buffer (Lua - Python)
  4. gh_audio.sound_create_from_sqlite3_blob (Lua - Python)
  5. gh_audio.sound_get_duration_ms (Lua - Python)
  6. gh_audio.sound_get_open_state (Lua - Python)
  7. gh_audio.sound_get_position_ms (Lua - Python)
  8. gh_audio.sound_get_volume (Lua - Python)
  9. gh_audio.sound_is_playing (Lua - Python)
  10. gh_audio.sound_kill (Lua - Python)
  11. gh_audio.sound_play (Lua - Python)
  12. gh_audio.sound_set_loop_state (Lua - Python)
  13. gh_audio.sound_set_paused (Lua - Python)
  14. gh_audio.sound_set_volume (Lua - Python)
  15. gh_audio.sound_spectrum_get_num_values (Lua - Python)
  16. gh_audio.sound_spectrum_get_value (Lua - Python)
  17. gh_audio.sound_spectrum_read (Lua - Python)
  18. gh_audio.sound_spectrum_read_v2 (Lua - Python)
  19. gh_audio.update (Lua - Python)



sound_create

Description

Creates a sound.


Syntax

sound = gh_audio.sound_create(
 filename,
 is_absolute_path,
 stream
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
filename = demo_dir .. "audio/sound01.mp3"
local is_absolute_path = 0
sound = gh_audio.sound_create(filename, is_absolute_path, 1)
            


sound_create_from_zip

Description

Creates a sound from a filename stored a in zip archive.


Syntax

sound = gh_audio.sound_create_from_zip(
 zip_filename,
 filename,
 stream
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
zip_filename = demo_dir .. "data.zip"
sound = gh_audio.sound_create_from_zip(zip_filename, "audio/sound01.wav", 0)
            


sound_create_from_buffer

Description

Creates a sound from a memory buffer.


Syntax

sound = gh_audio.sound_create_from_buffer(
 buffer_ptr,
 buffer_size,
 stream
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
buffer, buffer_size = gh_utils.file_buffer_create(audio_filename)
sound = gh_audio.sound_create_from_buffer(buffer, buffer_size, 0)
gh_utils.file_buffer_kill(buffer)
            


sound_create_from_sqlite3_blob

Description

Creates a sound from raw data stored a in a SQLite3 blob.


Syntax

sound = gh_audio.sound_create_from_sqlite3_blob(
 dbid,
 column,
 stream
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
sound = gh_audio.sound_create_from_sqlite3_blob_v1(dbid, column, 0)
            


sound_get_duration_ms

Description

Gets the duration of a sound in milli-seconds.


Syntax

duration = gh_audio.sound_get_duration_ms(
 sound
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
duration = gh_audio.sound_get_duration_ms(sound)
            


sound_get_open_state

Description

Gets the open status of a sound.


Syntax

open_state, percentbuffered = gh_audio.sound_get_open_state(
 sound
)

Languages

Lua - Python


Parameters


Return Values


Code sample


-- Possible states
FMOD_OPENSTATE_READY = 0   -- Opened and ready to play.
FMOD_OPENSTATE_LOADING = 1 -- Initial load in progress.
FMOD_OPENSTATE_ERROR = 2  -- Failed to open - file not found, out of memory etc.
FMOD_OPENSTATE_CONNECTING = 3   -- Connecting to remote host (internet sounds only).
FMOD_OPENSTATE_BUFFERING = 4 -- Buffering data.
FMOD_OPENSTATE_SEEKING = 5 -- Seeking to subsound and re-flushing stream buffer.
FMOD_OPENSTATE_PLAYING = 6 -- Ready and playing, but not possible to release at this time without stalling the main thread.
FMOD_OPENSTATE_SETPOSITION = 7  -- Seeking within a stream to a different position.
            
open_state, percentbuffered = gh_audio.sound_get_open_state(sound)
            


sound_get_position_ms

Description

Gets the current position in a sound instance in milli-seconds.


Syntax

position = gh_audio.sound_get_position_ms(
 sound,
 channel
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
position = gh_audio.sound_get_position_ms(sound, channel)
            


sound_get_volume

Description

Gets the volume level of a particular sound instance.


Syntax

volume = gh_audio.sound_get_volume(
 sound,
 channel
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
volume = gh_audio.sound_get_volume(sound, channel)
            


sound_is_playing

Description

Checks if a sound is currently playing.


Syntax

is_playing = gh_audio.sound_is_playing(
 sound,
 channel
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
is_playing = gh_audio.sound_is_playing(sound, channel)
            


sound_kill

Description

Destroys a sound.


Syntax

gh_audio.sound_kill(
 sound
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample

    
gh_audio.sound_kill(sound)
            


sound_play

Description

Plays a sound.


Syntax

channel = gh_audio.sound_play(
 sound
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
channel = gh_audio.sound_play(sound)
            


sound_set_loop_state

Description

Sets the loop state.


Syntax

gh_audio.sound_set_loop_state(
 sound,
 state
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample

    
gh_audio.sound_set_loop_state(sound, 1)
            


sound_set_paused

Description

Sets the paused state of a particular sound instance.


Syntax

gh_audio.sound_set_paused(
 sound,
 channel,
 state
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample

    
gh_audio.sound_set_paused(sound, channel, 1)
            


sound_set_volume

Description

Sets the volume level of a particular sound instance.


Syntax

gh_audio.sound_set_volume(
 sound,
 channel,
 volume
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample

    
gh_audio.sound_set_volume(sound, channel, 0.5)
            


sound_spectrum_get_num_values

Description

Gets the number of entries in the audio buffer.


Syntax

num_values = gh_audio.sound_spectrum_get_num_values(
 sound,
 channel
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
num_values = gh_audio.sound_spectrum_get_num_values(sound, channel)
            


sound_spectrum_get_value

Description

Gets a particular value from the audio buffer.


Syntax

value = gh_audio.sound_spectrum_get_value(
 sound,
 channel,
 value_index
)

Languages

Lua - Python


Parameters


Return Values


Code sample

    
local value = gh_audio.sound_spectrum_get_value(sound, channel, value_index)
            


sound_spectrum_read

Description

Reads the audio buffer.


Syntax

gh_audio.sound_spectrum_read(
 sound,
 channel
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample

    
gh_audio.sound_spectrum_read(sound, channel)
            


sound_spectrum_read_v2

Description

Reads the audio buffer.


Syntax

gh_audio.sound_spectrum_read_v2(
 sound,
 channel,
 fft_window_type
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample

    
-- Possible window types:
"window_rect"
"window_triangle"
"window_hamming" -- Default value
"window_hanning"
"window_blackman"
"window_blackmanharris"
           
fft_window_type =  "window_hamming"
gh_audio.sound_spectrum_read_v2(sound, channel, fft_window_type)
            


update

Description

Updates the sound system. Must be called once per frame.


Syntax

gh_audio.update()

Languages

Lua - Python


Parameters

This function has no input parameter(s).


Return Values

This function has no return value(s).


Code sample

    
gh_audio.update()
            






GeeXLab Rootard Guide | Downloads | Contact | Newsletter