Pulsar  3d3a057
player.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Player init
4  */
5 #pragma once
6 
8 
9 #define PLSR_PLAYER_MAX_CHANNELS 2
10 #define PLSR_PLAYER_INVALID_SOUND NULL
11 
12 /// Player method categories
13 typedef enum {
14  PLSR_PlayerCategoryType_Init = 0,
15  PLSR_PlayerCategoryType_Load,
16  PLSR_PlayerCategoryType_LoadFormats,
17  PLSR_PlayerCategoryType_LoadLookup,
19 
20 /// Player config
21 typedef struct {
22  bool initRenderer; ///< `true` if audren service init should be handled by the player
23 
24  AudioRendererConfig audrenConfig; ///< Audio renderer config (output rate, voices count, ...)
25  int startVoiceId; ///< First renderer voice index to be used by the player (should be `>= 0 && < audrenConfig.num_voices`)
26  int endVoiceId; ///< Last renderer voice index to be used by the player (should be `>= 0 && <= startVoiceId`)
27  const u8 sinkChannels[PLSR_PLAYER_MAX_CHANNELS]; ///< Sink channels the player should use
29 
30 /// Player sound channel
31 typedef struct {
32  void* mempool; ///< Pointer to the aligned memory containing audio samples (and ADPCM parameters when applicable)
33  AudioDriverWaveBuf wavebufs[2]; ///< Audio driver audio buffer struct (0 = intro/main; 1 = loop if looping)
34  int mempoolId; ///< Audio driver assigned mempool index
35  int voiceId; ///< Audio driver assigned voice index
37 
38 /// Player sound
39 typedef struct {
40  unsigned int wavebufCount;
41  unsigned int channelCount;
42  PLSR_PlayerSoundChannel channels[PLSR_PLAYER_MAX_CHANNELS];
44 
45 /// Player sound ID
47 
48 /// Player
49 typedef struct {
50  AudioDriver driver; ///< Audio driver internal state
51  PLSR_PlayerConfig config; ///< Effective player configuration
52 } PLSR_Player;
53 
54 /// Get default player configuration
56 
57 /// Get player instance (NULL if not initialized)
59 
60 /// Initialize player with a custom configuration
62 
63 /// Initialize player with the default configuration
64 NX_INLINE PLSR_RC plsrPlayerInit(void) {
66 }
67 
68 /// Convenience shortcut to wait until next audio renderer frame
69 NX_INLINE void plsrPlayerWaitNextFrame(void) {
70  audrenWaitFrame();
71 }
72 
73 /// De-initialize player
74 void plsrPlayerExit(void);
75 
76 /// Play a loaded sound from the beginning
78 
79 /// Stop a sound if it is currently playing
81 
82 /// Free ressources used by a loaded sound
84 
85 /// Set sound pitch factor (effective next time it's played)
87 
88 /// Set sound volume factor (effective next time it's played)
PLSR_RC plsrPlayerStop(PLSR_PlayerSoundId id)
Stop a sound if it is currently playing.
const PLSR_PlayerConfig * plsrPlayerGetDefaultConfig(void)
Get default player configuration.
int voiceId
Audio driver assigned voice index.
Definition: player.h:35
NX_INLINE void plsrPlayerWaitNextFrame(void)
Convenience shortcut to wait until next audio renderer frame.
Definition: player.h:69
PLSR_RC plsrPlayerInitEx(const PLSR_PlayerConfig *config)
Initialize player with a custom configuration.
Archive container interface.
void plsrPlayerFree(PLSR_PlayerSoundId id)
Free ressources used by a loaded sound.
int endVoiceId
Last renderer voice index to be used by the player (should be >= 0 && <= startVoiceId) ...
Definition: player.h:26
PLSR_PlayerConfig config
Effective player configuration.
Definition: player.h:51
PLSR_RC plsrPlayerPlay(PLSR_PlayerSoundId id)
Play a loaded sound from the beginning.
PLSR_Player * plsrPlayerGetInstance(void)
Get player instance (NULL if not initialized)
NX_INLINE PLSR_RC plsrPlayerInit(void)
Initialize player with the default configuration.
Definition: player.h:64
PLSR_PlayerCategoryType
Player method categories.
Definition: player.h:13
int startVoiceId
First renderer voice index to be used by the player (should be >= 0 && < audrenConfig.num_voices)
Definition: player.h:25
int mempoolId
Audio driver assigned mempool index.
Definition: player.h:34
Player config.
Definition: player.h:21
PLSR_RC plsrPlayerSetVolume(PLSR_PlayerSoundId id, float volume)
Set sound volume factor (effective next time it&#39;s played)
Player sound channel.
Definition: player.h:31
AudioDriver driver
Audio driver internal state.
Definition: player.h:50
void * mempool
Pointer to the aligned memory containing audio samples (and ADPCM parameters when applicable) ...
Definition: player.h:32
PLSR_RC plsrPlayerSetPitch(PLSR_PlayerSoundId id, float pitch)
Set sound pitch factor (effective next time it&#39;s played)
Player.
Definition: player.h:49
const PLSR_PlayerSound * PLSR_PlayerSoundId
Player sound ID.
Definition: player.h:46
bool initRenderer
true if audren service init should be handled by the player
Definition: player.h:22
u32 PLSR_RC
Result code returned by Pulsar functions.
Definition: types.h:73
void plsrPlayerExit(void)
De-initialize player.
Player sound.
Definition: player.h:39
AudioRendererConfig audrenConfig
Audio renderer config (output rate, voices count, ...)
Definition: player.h:24