-
Notifications
You must be signed in to change notification settings - Fork 0
Sound
This section contains all Sound functions.
- CP_Sound_Load
- CP_Sound_LoadMusic
- CP_Sound_Free
- CP_Sound_Play
- CP_Sound_PlayMusic
- CP_Sound_PlayAdvanced
- CP_Sound_PauseAll
- CP_Sound_PauseGroup
- CP_Sound_ResumeAll
- CP_Sound_ResumeGroup
- CP_Sound_StopAll
- CP_Sound_StopGroup
- CP_Sound_SetGroupVolume
- CP_Sound_GetGroupVolume
- CP_Sound_SetGroupPitch
- CP_Sound_GetGroupPitch
Load a CP_Sound by inputting the file path of the sound file as a string (const char*).
CP_Sound CP_Sound_Load(const char* filepath);
- filepath (const char*) - The path to the sound file that you want to load.
- CP_Sound - The loaded sound, returns a NULL CP_Sound if the sound could not be loaded.
CP_Sound mySound = NULL;
void Init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
}
void Update()
{
if (CP_Input_KeyTriggered(KEY_S))
CP_Sound_Play(mySound);
}
void Shutdown()
{
CP_Sound_Free(mySound);
}
Loads a CP_Sound from the given file path, and streams the audio from disk while it is playing instead of loading the entire file into memory.
CP_Sound CP_Sound_LoadMusic(const char* filepath);
- filepath (const char*) - The filepath to the music you want to load.
- CP_Sound - The music loaded from the given filepath, returns NULL if no music could be loaded.
CP_Sound mySound = NULL;
void init()
{
myMusic = CP_Sound_LoadMusic("./Assets/Justins_Dance_Song.wav");
}
void update()
{
if (CP_Input_KeyTriggered(KEY_S))
CP_Sound_PlayMusic(myMusic);
}
void shutdown()
{
CP_Sound_Free(myMusic);
}
Frees a given CP_Sound from memory. The CP_Sound will not be valid after this call.
void CP_Sound_Free([CP_Sound](Types/#CP_Sound) sound);
- sound (CP_Sound) - The sound you want to free.
This function does not return anything
CP_Sound mySound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
}
void shutdown()
{
CP_Sound_Free(mySound);
}
Plays a given CP_Sound once in the CP_SOUND_GROUP_SFX sound group.
void CP_Sound_Play([CP_Sound](Types/#CP_Sound) sound);
- sound (CP_Sound) - The sound you want to play.
This function does not return anything.
CP_Sound mySound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
}
void update()
{
if (CP_Input_KeyTriggered(KEY_S))
CP_Sound_Play(mySound);
}
void shutdown()
{
CP_Sound_Free(mySound);
}
Plays a given CP_Sound continuously in the CP_SOUND_GROUP_MUSIC sound group. The sound will loop until it is stopped.
void CP_Sound_PlayMusic([CP_Sound](Types/#CP_Sound) sound);
- sound (CP_Sound) - The sound you want to play as music.
This function does not return anything.
CP_Sound mySound = NULL;
void init()
{
myMusic = CP_Sound_LoadMusic("./Assets/Justins_voice.wav");
}
void update()
{
if (CP_Input_KeyTriggered(KEY_S))
CP_Sound_PlayMusic(myMusic);
}
void shutdown()
{
CP_Sound_Free(myMusic);
}
Plays a given CP_Sound with provided values for the sound's volume and pitch, whether the sound will loop, and the sound group to play it in.
void CP_Sound_PlayAdvanced(CP_Sound sound, float volume, float pitch, CP_BOOL looping, CP_SOUND_GROUP group);
- sound (CP_Sound) - The sound that you want to play.
- volume (float) - The volume modifier that you want to apply (1.0f = no modification, 0.0 = silent).
- pitch (float) - The pitch modification that you want to apply (1.0f = no modification, 0.5 = half pitch, 2.0 = double pitch).
- looping (P_BOOL) - If you want the sound to loop or not.
- group (CP_SOUND_GROUP_MUSIC) - The sound group that you want the sound played in.
This function does not return anything.
CP_Sound mySound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
}
void update()
{
if (CP_Input_KeyTriggered(KEY_S))
{
// play a sound with double the pitch (1 octave up), looping, and put it in sound group 2
CP_Sound_PlayAdvanced(mySound, 1.0f, 2.0f, TRUE, CP_SOUND_GROUP_2);
}
}
void shutdown()
{
CP_Sound_Free(mySound);
}
Pauses all CP_Sounds that are currently playing.
void CP_Sound_PauseAll();
This function has no parameters.
This function does not return anything.
CP_Sound mySound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
}
void update()
{
float songLength = 500;
static float timer = 0;
if(!timer)
{
CP_Sound_Play(mySound);
}
timer += CP_System_GetDt();
if(timer >= .5f * songLength)
{
CP_Sound_PauseAll();
}
}
void shutdown()
{
CP_Sound_Free(mySound);
}
Pauses all CP_Sounds currently playing within the given CP_SOUND_GROUP.
void CP_Sound_PauseGroup(CP_SOUND_GROUP group);
- group (CP_SOUND_GROUP) - The sound group that you want to pause.
This function does not return anything.
CP_Sound mySound = NULL;
CP_Sound mySecondSound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
mySecondSound = CP_Sound_Load("./Assets/Justins_laugh.wav");
}
void update()
{
float songLength = 500;
static float timer = 0;
timer += 1;
CP_Sound_PlayAdvanced(mySound, 1, 1, TRUE, CP_SOUND_GROUP_3);
CP_Sound_PlayAdvanced(mySecondSound, 1, 1, TRUE, CP_SOUND_GROUP_5);
if (timer >= .5f * songLength)
{
// this will pause mySound, but not mySecondSound, because mySecondSound is not in CP_SOUND_GROUP_3
CP_Sound_PauseGroup(CP_SOUND_GROUP_3);
}
}
void shutdown()
{
CP_Sound_Free(mySound);
CP_Sound_Free(mySecondSound);
}
Resumes all CP_Sounds that are currently paused.
void CP_Sound_ResumeAll(void);
This function has no parameters.
This function does not return anything.
CP_Sound mySound = NULL;
CP_Sound mySecondSound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
mySecondSound = CP_Sound_Load("./Assets/Justins_laugh.wav");
}
void update()
{
float songLength = 5;
static float timer = 0;
timer += CP_System_GetDt();
CP_Sound_PlayAdvanced(mySound, 1, 1, TRUE, CP_SOUND_GROUP_3);
CP_Sound_PlayAdvanced(mySecondSound, 1, 1, TRUE, CP_SOUND_GROUP_5);
if(timer >= .5f * songLength)
{
// this will pause mySound, but not mySecondSound, because mySecondSound is not in CP_SOUND_GROUP_3
CP_Sound_PauseGroup(CP_SOUND_GROUP_3);
}
if(time >= songLength)
{
CP_Sound_ResumeAll(); // play any paused sounds
timer = 0; // reset the timer so that the sound pauses 50% further in
}
}
void shutdown()
{
CP_Sound_Free(mySound);
CP_Sound_Free(mySecondSound);
}
Resumes all CP_Sounds that are currently paused within the given CP_SOUND_GROUP.
void CP_Sound_PauseGroup(CP_SOUND_GROUP group);
- group (CP_SOUND_GROUP) - The sound group that you want to resume playing.
This function does not return anything.
CP_Sound mySound = NULL;
CP_Sound mySecondSound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
mySecondSound = CP_Sound_Load("./Assets/Justins_laugh.wav");
}
void update()
{
float songLength = 5;
static float timer = 0;
timer += CP_System_GetDt();
CP_Sound_PlayAdvanced(mySound, 1, 1, TRUE, CP_SOUND_GROUP_3);
CP_Sound_PlayAdvanced(mySecondSound, 1, 1, TRUE, CP_SOUND_GROUP_5);
if(timer >= .5f * songLength)
{
// this will pause mySound, but not mySecondSound, because mySecondSound is not in CP_SOUND_GROUP_3
CP_Sound_PauseGroup(CP_SOUND_GROUP_3);
}
if(timer >= songLength)
{
CP_Sound_ResumeGroup(CP_SOUND_GROUP_3); // resume playing all sounds in group 3, currently only mySound
timer = 0; // reset timer so that group 3 pauses another 50% into the timer
}
}
void shutdown()
{
CP_Sound_Free(mySound);
CP_Sound_Free(mySecondSound);
}
Stops all currently playing CP_Sounds in all CP_SOUND_GROUPS and resets them to their beginnings.
void CP_Sound_StopAll(void);
This function has no parameters.
This function does not return anything.
CP_Sound mySound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
}
void update()
{
float songLength = 5;
static float timer = 0;
timer += CP_System_GetDt();
CP_Sound_Play(mySound);
if(timer >= .5f * songLength)
{
CP_Sound_StopAll(); // stop playing mySound and reset it to it's beginning
CP_Sound_Play(mySound); // play mySound from its beginning
}
}
void shutdown()
{
CP_Sound_Free(mySound);
}
Stops all CP_Sounds that are currently playing within a given group and resets them to their beginnings.
void CP_Sound_StopGroup(CP_SOUND_GROUP group);
- group (CP_SOUND_GROUP) - The group that you want to stop all sounds in.
This function does not return anything.
CP_Sound mySound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
}
void update()
{
float songLength = 5;
static float timer = 0;
timer += CP_System_GetDt();
CP_Sound_PlayAdvanced(mySound, 1, 1, TRUE, CP_SOUND_GROUP_2); // play a looped, but unedited, mySound in group 2
if(timer >= .5f * songLength)
{
CP_Sound_StopGroup(CP_SOUND_GROUP_2); // stop playing mySound and reset it to it's beginning
CP_Sound_PlayAdvanced(mySound, 1, 1, TRUE, CP_SOUND_GROUP_2); // play mySound from its beginning in group 2
}
}
void shutdown()
{
CP_Sound_Free(mySound);
}
Sets the volume of all CP_Sounds within the given CP_SOUND_GROUP.
void CP_Sound_SetGroupVolume(CP_SOUND_GROUP group, float volume)
- group (CP_SOUND_GROUP) - The sound group that you want to set the volume for.
- volume (float) - The volume modifier you want to apply to the group (1.0f is normal volume, 0.0 is silent).
This function does not return anything.
CP_Sound mySound = NULL;
CP_Sound mySecondSound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
mySecondSound = CP_Sound_Load("./Assets/Justins_laugh.wav");
}
void update()
{
float songLength = 5;
static float timer = 0;
timer += CP_System_GetDt();
CP_Sound_PlayAdvanced(mySound, 1, 1, TRUE, CP_SOUND_GROUP_3);
CP_Sound_PlayAdvanced(mySecondSound, 1, 1, TRUE, CP_SOUND_GROUP_5);
if(timer >= .5f * songLength)
{
// make all sounds in group 3 (currently only mySound) half their original volume
CP_Sound_SetGroupVolume(CP_SOUND_GROUP_3, .5);
}
}
void shutdown()
{
CP_Sound_Free(mySound);
CP_Sound_Free(mySecondSound);
}
Gets the volume modifier of all CP_Sounds within the given CP_SOUND_GROUP.
float CP_Sound_GetGroupVolume(CP_SOUND_GROUP group);
- group (CP_SOUND_GROUP) - The sound group that you want the volume modifier of.
- float - The current volume modifier applied to all sounds within the given group.
CP_Sound mySound = NULL;
CP_Sound mySecondSound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
mySecondSound = CP_Sound_Load("./Assets/Justins_laugh.wav");
}
void update()
{
float songLength = 5;
static float timer = 0;
timer += CP_System_GetDt();
CP_Sound_PlayAdvanced(mySound, 1, 1, TRUE, CP_SOUND_GROUP_3);
CP_Sound_PlayAdvanced(mySecondSound, 1, 1, TRUE, CP_SOUND_GROUP_5);
if(timer >= .5f * songLength)
{
// set the volume modifier of group 3 to .5
CP_Sound_SetGroupVolume(CP_SOUND_GROUP_3, .5f);
// get the modifier of group 3, on the currently .5
float volume = CP_Sound_GetGroupVolume(CP_SOUND_GROUP_3);
timer = 0;
}
}
void shutdown()
{
CP_Sound_Free(mySound);
CP_Sound_Free(mySecondSound);
}
Sets the pitch modifier of all CP_Sounds within the given CP_SOUND_GROUP.
void CP_Sound_SetGroupPitch(CP_SOUND_GROUP group, float pitch);
- group (CP_SOUND_GROUP) - The sound group that you want to modify the pitch of.
- pitch (float) - The pitch modifier that you want to give to all sounds in the given group (1.0 is normal pitch, 0.5 is half pitch, 2.0 is double pitch).
This function does not return anything
CP_Sound mySound = NULL;
CP_Sound mySecondSound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
mySecondSound = CP_Sound_Load("./Assets/Justins_laugh.wav");
}
void update()
{
float songLength = 5;
static float timer = 0;
timer += CP_System_GetDt();
CP_Sound_PlayAdvanced(mySound, 1, 1, TRUE, CP_SOUND_GROUP_3);
CP_Sound_PlayAdvanced(mySecondSound, 1, 1, TRUE, CP_SOUND_GROUP_5);
if(timer >= .5f * songLength)
{
// set the pitch modifier of group 3 to 2
CP_Sound_SetGroupPitch(CP_SOUND_GROUP_3, 2);
// get the pitch modifier of group 3, currently 2.0f
float pitch = CP_Sound_GetGroupPitch(CP_SOUND_GROUP_3);
timer = 0;
}
}
void shutdown()
{
CP_Sound_Free(mySound);
CP_Sound_Free(mySecondSound);
}
Gets the pitch modifier applied to all CP_Sounds within the given CP_SOUND_GROUP.
float CP_Sound_GetGroupPitch(CP_SOUND_GROUP group);
- group (CP_SOUND_GROUP) - The sound group that you want to get the pitch of.
- float - The current pitch modifier of the specified CP_SOUND_GROUP.
CP_Sound mySound = NULL;
CP_Sound mySecondSound = NULL;
void init()
{
mySound = CP_Sound_Load("./Assets/Justins_voice.wav");
mySecondSound = CP_Sound_Load("./Assets/Justins_laugh.wav");
}
void update()
{
float songLength = 5;
static float timer = 0;
timer += CP_System_GetDt();
CP_Sound_PlayAdvanced(mySound, 1, 1, TRUE, CP_SOUND_GROUP_3);
CP_Sound_PlayAdvanced(mySecondSound, 1, 1, TRUE, CP_SOUND_GROUP_5);
if(timer >= .5f * songLength)
{
// set the pitch modifier of group 3 to 2
CP_Sound_SetGroupPitch(CP_SOUND_GROUP_3, 2);
// get the pitch modifier of group 3, on the currently 2.0f
float pitch = CP_Sound_GetGroupPitch(CP_SOUND_GROUP_3);
timer = 0;
}
}
void shutdown()
{
CP_Sound_Free(mySound);
CP_Sound_Free(mySecondSound);
}