SWILIB API (SG)    
Loading...
Searching...
No Matches
Sound

Detailed Description

Functions for playing and controlling sound-related stuff.

This function is mainly used for audio hooks or playing short sounds/tones. See OBS_* functions for playing audio in the normal way.

Usage: #include <swilib.h> or #include <swilib/sound.h>

Data Structures

struct  PLAY_VOLUME
 Volume of a play object (NSG/ELKA), passed by value to PlayMelody_ChangeVolume. More...
 
struct  GBS_PSOUND_MSG
 GBS event (MSG_PLAYFILE_REPORT) for the PlayFile or PlayMelodyInMem. More...
 
struct  PLAYFILE_OPT
 Options for the PlayFile. More...
 

Typedefs

typedef struct GBS_PSOUND_MSG GBS_PSOUND_MSG
 
typedef struct PLAYFILE_OPT PLAYFILE_OPT
 
typedef struct PLAY_VOLUME PLAY_VOLUME
 

Enumerations

enum  PlaySoundEventID {
  M_SAE_EVENT_STARTED = 0 ,
  M_SAE_EVENT_STOPPED = 1 ,
  M_SAE_EVENT_DONE = 2 ,
  M_SAE_EVENT_ERROR = 3 ,
  M_SAE_PLAYBACK_STARTED = 4 ,
  M_SAE_PLAYBACK_ERROR = 5 ,
  M_SAE_PLAYBACK_NEXTCYCLE = 6 ,
  M_SAE_PLAYBACK_DONE = 7 ,
  M_SAE_VOLUME_UPDATED = 8 ,
  M_SAE_VOLUME_ERROR = 9 ,
  M_SAE_PLAYTIME_UPDATED = 0xA ,
  M_SAE_PLAYTIME_ERROR = 0xB ,
  M_SAE_HANDSFREE_UPDATED = 0xC ,
  M_SAE_HANDSFREE_ERROR = 0xD ,
  M_SAE_RECORD_STARTED = 0xE ,
  M_SAE_RECORD_ERROR = 0xF ,
  M_SAE_RECORD_DONE = 0x10 ,
  M_SAE_STOP_OK = 0x11 ,
  M_SAE_STOP_FAIL = 0x12 ,
  M_SAE_CANCEL_OK = 0x13 ,
  M_SAE_CANCEL_FAIL = 0x14 ,
  M_SAE_PAUSE_OK = 0x15 ,
  M_SAE_PAUSE_FAIL = 0x16 ,
  M_SAE_RESUME_OK = 0x17 ,
  M_SAE_RESUME_FAIL = 0x18 ,
  M_SAE_INFO_DATA_AVAILABLE = 0x19 ,
  M_SAE_INFO_REQUEST_FAIL = 0x1A ,
  M_SAE_MAX_RECORDING_TIME_AVAILABLE = 0x1B ,
  M_SAE_MAX_RECORDING_TIME_ERROR = 0x1C ,
  M_SAE_AUDIO_EVENT_UPDATED = 0x1D ,
  M_SAE_AUDIO_EVENT_UPDATED_MS = 0x1E ,
  M_SAE_AUDIO_EVENT_STOPPED = 0x1F ,
  M_SAE_AUDIO_EVENT_PAUSED = 0x20 ,
  M_SAE_AUDIO_EVENT_RESUMED = 0x21
}
 Event IDs for the GBS_PSOUND_MSG. More...
 
enum  PlaySoundJobID {
  Job_NoJob = 0 ,
  Job_RecFile = 1 ,
  Job_RecBuffer = 2 ,
  Job_PlayFile = 3 ,
  Job_PlayBuffer = 4 ,
  Job_GetInfo = 5 ,
  Job_GetRecordingTimeMax = 6
}
 Job IDs for the GBS_PSOUND_MSG. More...
 
enum  PlaySoundVolumeID {
  VOLUME_CALLS = 0 ,
  VOLUME_SYSTEM = 1 ,
  VOLUME_WALKY_TALKY = 2 ,
  VOLUME_MESSAGES = 4 ,
  VOLUME_CB_SERVICES = 6 ,
  VOLUME_ALARM_CLOCK = 9 ,
  VOLUME_ORGANISER = 0xA ,
  VOLUME_APPLICATIONS = 0xC
}
 Volume (=category) for tones (PlaySound). More...
 

Functions

char * RamVolumeLevel ()
 Get current volume level.
 
char * RamMediaIsPlaying ()
 Copy of a PASIC audio register, historically used to check if a sound is played.
 
int IsPlayerOn ()
 Check if the radio or player is active.
 
int GetPlayStatus (void)
 Get status of the MediaPlayer.
 
void PlaySound (long volume, long cepid, long unk1, long tone_type, long unk2)
 Play tone by id.
 
int PlayMelodyInMem (char unk1, const void *buffer, int size, int cepid, int msg, int unk2)
 Play melody from memory.
 
int PlayMelody_ChangeVolume (int handle, int volume)
 Change the volume of the playing melody.
 
int PlayMelody_GetVolume (int handle, int *volume)
 Get the volume of the playing melody.
 
int PlayMelody_StopPlayback (int handle)
 Stop the playback of the melody.
 
int PlayMelody_PausePlayback (int handle)
 Pause the playback of the melody.
 
int PlayMelody_ResumePlayBack (int handle)
 Resume the playback of the melody.
 
int PlayMelody_SetPosition (int handle, int position)
 Set the position of the playing melody.
 
void * GetPlayObjById (int handle)
 Get a pointer to the PlayObject by PlayObject handle.
 
int GetPlayObjPosition (void *obj, int *position)
 Get the current position from Obs or PlayObj (generic).
 
int GetPlayObjDuration (void *obj, int *duration)
 Get the duration of from Obs or PlayObj (generic).
 
static int PlayMelody_GetPosition (int handle, int *position)
 Get the current position of the playing melody.
 
static int PlayMelody_GetDuration (int handle, int *duration)
 Get the duration of the playing melody.
 
short PlayFile (int flags, const WSHDR *folder, const WSHDR *file, int cepid, int msgid, const PLAYFILE_OPT *sfo)
 Play file from filesystem (path=folder\file).
 
int Audio_GetCurrAudioPath (void)
 Get current audio path.
 
int Audio_GetObjectHandle ()
 Get current object handle.
 
int AACC_AudioTransferReq (int oh, uint32_t type_and_conn)
 Change audio output.
 
void PlaySoundLoop (int unk1, int unk2, int duration)
 Play vibra tone (???).
 
int ChangeVolume (uint8_t volume)
 Change the current audio volume.
 
short SoundAE_PlayFileAsEvent (int event_id, int cepid, int msg_id, const WSHDR *folder, const WSHDR *file)
 Play custom sound.
 
void * RamAudioHook ()
 Pointer to the AudioHook.
 
char * RamIsSoundRecordingActive ()
 Check if active recording of the sound.
 
char * RamSoundRecordingQuality ()
 Quality of the current sound recording.
 

Data Structure Documentation

◆ PLAY_VOLUME

struct PLAY_VOLUME

◆ GBS_PSOUND_MSG

struct GBS_PSOUND_MSG

◆ PLAYFILE_OPT

struct PLAYFILE_OPT

Typedef Documentation

◆ GBS_PSOUND_MSG

typedef struct GBS_PSOUND_MSG GBS_PSOUND_MSG

Definition at line 20 of file sound.h.

◆ PLAYFILE_OPT

typedef struct PLAYFILE_OPT PLAYFILE_OPT

Definition at line 21 of file sound.h.

◆ PLAY_VOLUME

typedef struct PLAY_VOLUME PLAY_VOLUME

Definition at line 22 of file sound.h.

Enumeration Type Documentation

◆ PlaySoundEventID

Event IDs for the GBS_PSOUND_MSG.

Enumerator
M_SAE_EVENT_STARTED 
M_SAE_EVENT_STOPPED 
M_SAE_EVENT_DONE 
M_SAE_EVENT_ERROR 
M_SAE_PLAYBACK_STARTED 
M_SAE_PLAYBACK_ERROR 
M_SAE_PLAYBACK_NEXTCYCLE 
M_SAE_PLAYBACK_DONE 
M_SAE_VOLUME_UPDATED 
M_SAE_VOLUME_ERROR 
M_SAE_PLAYTIME_UPDATED 
M_SAE_PLAYTIME_ERROR 
M_SAE_HANDSFREE_UPDATED 
M_SAE_HANDSFREE_ERROR 
M_SAE_RECORD_STARTED 
M_SAE_RECORD_ERROR 
M_SAE_RECORD_DONE 
M_SAE_STOP_OK 
M_SAE_STOP_FAIL 
M_SAE_CANCEL_OK 
M_SAE_CANCEL_FAIL 
M_SAE_PAUSE_OK 
M_SAE_PAUSE_FAIL 
M_SAE_RESUME_OK 
M_SAE_RESUME_FAIL 
M_SAE_INFO_DATA_AVAILABLE 
M_SAE_INFO_REQUEST_FAIL 
M_SAE_MAX_RECORDING_TIME_AVAILABLE 
M_SAE_MAX_RECORDING_TIME_ERROR 
M_SAE_AUDIO_EVENT_UPDATED 
M_SAE_AUDIO_EVENT_UPDATED_MS 
M_SAE_AUDIO_EVENT_STOPPED 
M_SAE_AUDIO_EVENT_PAUSED 
M_SAE_AUDIO_EVENT_RESUMED 

Definition at line 60 of file sound.h.

◆ PlaySoundJobID

Job IDs for the GBS_PSOUND_MSG.

Enumerator
Job_NoJob 
Job_RecFile 
Job_RecBuffer 
Job_PlayFile 
Job_PlayBuffer 
Job_GetInfo 
Job_GetRecordingTimeMax 

Definition at line 163 of file sound.h.

◆ PlaySoundVolumeID

Volume (=category) for tones (PlaySound).

Enumerator
VOLUME_CALLS 
VOLUME_SYSTEM 
VOLUME_WALKY_TALKY 
VOLUME_MESSAGES 
VOLUME_CB_SERVICES 
VOLUME_ALARM_CLOCK 
VOLUME_ORGANISER 
VOLUME_APPLICATIONS 

Definition at line 186 of file sound.h.

Function Documentation

◆ RamVolumeLevel()

char * RamVolumeLevel ( )

Get current volume level.

Returns
volume level

◆ RamMediaIsPlaying()

char * RamMediaIsPlaying ( )

Copy of a PASIC audio register, historically used to check if a sound is played.

Returns
NSG: MONO control copy, 1 on C81/S75/SL75 and 2 on S68 while audio is routed to the speaker
ELKA: DAC control copy, nonzero while the PCM audio path is active
SG: pointer to the value of an unknown PASIC register, RamMediaIsPlaying() != 2 // sound is playing
Note
On NSG the value is also changed by key clicks and tones, and not changed for headset or Bluetooth playback.
Warning
Result varies across platforms.

◆ IsPlayerOn()

int IsPlayerOn ( )

Check if the radio or player is active.

Returns
1 or 0

◆ GetPlayStatus()

int GetPlayStatus ( void )

Get status of the MediaPlayer.

Returns
unknown values

◆ PlaySound()

void PlaySound ( long volume,
long cepid,
long unk1,
long tone_type,
long unk2 )

Play tone by id.

Parameters
volumecategory of the tone, see: PlaySoundVolumeID
cepidtarget cepid, set to MMI_CEPID
unk1unknown, set to 0
tone_type1-118
unk2unknown, set to 0

◆ PlayMelodyInMem()

int PlayMelodyInMem ( char unk1,
const void * buffer,
int size,
int cepid,
int msg,
int unk2 )

Play melody from memory.

Parameters
unk1unknown, set to 0x11
bufferpointer to the melody buffer
sizesize of the melody buffer
cepidtarget cepid, set MMI_CEPID
msgGBS message ID for the events, set to MSG_PLAYFILE_REPORT or 0
unk2unknown, set to 0
Returns
play object handle
Note
Useful for audiohook.

◆ PlayMelody_ChangeVolume()

int PlayMelody_ChangeVolume ( int handle,
int volume )

Change the volume of the playing melody.

Parameters
handleplay object handle
volumeNSG/ELKA: PLAY_VOLUME passed by value; SG/X75: volume level, 16 = the level from the profile
Returns
1 if success, 0 if error
Note
The type of volume differs between platforms: PLAY_VOLUME on NSG/ELKA, int on SG/X75.
On NSG/ELKA read the current value with PlayMelody_GetVolume and change level.
#ifdef NEWSGOLD
PLAY_VOLUME volume;
if (PlayMelody_GetVolume(handle, &volume)) {
volume.level = 3;
PlayMelody_ChangeVolume(handle, volume);
}
#else
#endif
uint8_t level
volume level 0..5 (Obs 0, 1, 4, 8, 12, 15), 6 = the level from the profile
Definition sound.h:29
int PlayMelody_GetVolume(int handle, int *volume)
Get the volume of the playing melody.
int PlayMelody_ChangeVolume(int handle, int volume)
Change the volume of the playing melody.
Volume of a play object (NSG/ELKA), passed by value to PlayMelody_ChangeVolume.
Definition sound.h:28

◆ PlayMelody_GetVolume()

int PlayMelody_GetVolume ( int handle,
int * volume )

Get the volume of the playing melody.

Parameters
handleplay object handle
[out]volumecurrent volume 0..15, 16 when the melody is not playing
Returns
1 if success, 0 if error

◆ PlayMelody_StopPlayback()

int PlayMelody_StopPlayback ( int handle)

Stop the playback of the melody.

Parameters
handleplay object handle
Returns
1 if success, 0 if error

◆ PlayMelody_PausePlayback()

int PlayMelody_PausePlayback ( int handle)

Pause the playback of the melody.

Parameters
handleplay object handle
Returns
1 if success, 0 if error

◆ PlayMelody_ResumePlayBack()

int PlayMelody_ResumePlayBack ( int handle)

Resume the playback of the melody.

Parameters
handleplay object handle
Returns
1 if success, 0 if error

◆ PlayMelody_SetPosition()

int PlayMelody_SetPosition ( int handle,
int position )

Set the position of the playing melody.

Parameters
handleplay object handle
positionposition in ms
Returns
1 if success, 0 if error

◆ GetPlayObjById()

void * GetPlayObjById ( int handle)

Get a pointer to the PlayObject by PlayObject handle.

Parameters
handleplay object handle
Returns
pointer or NULL

◆ GetPlayObjPosition()

int GetPlayObjPosition ( void * obj,
int * position )

Get the current position from Obs or PlayObj (generic).

Parameters
objObs or PlayObj pointer
[out]positionposition in ms
Returns
1 if success, 0 if error

◆ GetPlayObjDuration()

int GetPlayObjDuration ( void * obj,
int * duration )

Get the duration of from Obs or PlayObj (generic).

Parameters
objObs or PlayObj pointer
[out]durationduration in ms
Returns
1 if success, 0 if error

◆ PlayMelody_GetPosition()

static int PlayMelody_GetPosition ( int handle,
int * position )
inlinestatic

Get the current position of the playing melody.

Parameters
handleplay object handle
[out]positionposition in ms
Returns
1 if success, 0 if error

Definition at line 443 of file sound.h.

◆ PlayMelody_GetDuration()

static int PlayMelody_GetDuration ( int handle,
int * duration )
inlinestatic

Get the duration of the playing melody.

Parameters
handleplay object handle
[out]durationduration in ms
Returns
1 if success, 0 if error

Definition at line 453 of file sound.h.

◆ PlayFile()

short PlayFile ( int flags,
const WSHDR * folder,
const WSHDR * file,
int cepid,
int msgid,
const PLAYFILE_OPT * sfo )

Play file from filesystem (path=folder\file).

Parameters
flagsunknown flags
folderpath to directory with file
filefilename
cepidtarget cepid, set to GBS_GetCurCepid
msgidGBS message for events, set to MSG_PLAYFILE_REPORT
sfopointer to the options: PLAYFILE_OPT
Returns
1 if success, 0 if error
Warning
Different function signatures across platforms!

◆ Audio_GetCurrAudioPath()

int Audio_GetCurrAudioPath ( void )

Get current audio path.

Returns
id
Available on platforms:
NSG, ELKA

◆ Audio_GetObjectHandle()

int Audio_GetObjectHandle ( )

Get current object handle.

Returns
object handle

◆ AACC_AudioTransferReq()

int AACC_AudioTransferReq ( int oh,
uint32_t type_and_conn )

Change audio output.

Parameters
ohobject handle, use Audio_GetObjectHandle
type_and_connconn << 16 | type
Returns
0 or error

◆ PlaySoundLoop()

void PlaySoundLoop ( int unk1,
int unk2,
int duration )

Play vibra tone (???).

Parameters
unk1unknown, set to 0x2F
unk2unknown, set to 1
durationduration in ms
Warning
Untested function that is not found in any ELF's.
Available on platforms:
X75, SG

◆ ChangeVolume()

int ChangeVolume ( uint8_t volume)

Change the current audio volume.

Parameters
volumevolume level
Returns
undocumented
Available on platforms:
X75, SG

◆ SoundAE_PlayFileAsEvent()

short SoundAE_PlayFileAsEvent ( int event_id,
int cepid,
int msg_id,
const WSHDR * folder,
const WSHDR * file )

Play custom sound.

Parameters
event_idevent ID
cepidGBS message CEPID
msg_idGBS message ID
folderfolder for custom sound, can be NULL
filefile for custom sound, can be NULL
Returns
play handle or -1 (0xFFFF) on error
Warning
Untested function that is not found in any ELF's.

◆ RamAudioHook()

void * RamAudioHook ( )

Pointer to the AudioHook.

Returns
implementation specific
Available on platforms:
X75, SG

◆ RamIsSoundRecordingActive()

char * RamIsSoundRecordingActive ( )

Check if active recording of the sound.

Returns
pointer to 1 or 0

◆ RamSoundRecordingQuality()

char * RamSoundRecordingQuality ( )

Quality of the current sound recording.

Returns
pointer to 1 or 0