feature: Introduced c-style context pointer on AudioCallback
This commit is contained in:
parent
e46b6147fc
commit
48fc229d0c
1 changed files with 36 additions and 28 deletions
|
|
@ -24,8 +24,8 @@ static unsigned int delayWriteIndex = 0;
|
|||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static void AudioProcessEffectLPF(void *buffer, unsigned int frames); // Audio effect: lowpass filter
|
||||
static void AudioProcessEffectDelay(void *buffer, unsigned int frames); // Audio effect: delay
|
||||
static void AudioProcessEffectLPF(void *buffer, unsigned int frames, void *context); // Audio effect: lowpass filter
|
||||
static void AudioProcessEffectDelay(void *buffer, unsigned int frames, void *context); // Audio effect: delay
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
|
|
@ -51,7 +51,7 @@ int main(void)
|
|||
|
||||
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
|
||||
bool pause = false; // Music playing paused
|
||||
|
||||
|
||||
bool enableEffectLPF = false; // Enable effect low-pass-filter
|
||||
bool enableEffectDelay = false; // Enable effect delay (1 second)
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ int main(void)
|
|||
if (IsKeyPressed(KEY_F))
|
||||
{
|
||||
enableEffectLPF = !enableEffectLPF;
|
||||
if (enableEffectLPF) AttachAudioStreamProcessor(music.stream, AudioProcessEffectLPF);
|
||||
if (enableEffectLPF) AttachAudioStreamProcessor(music.stream, AudioProcessEffectLPF, 0);
|
||||
else DetachAudioStreamProcessor(music.stream, AudioProcessEffectLPF);
|
||||
}
|
||||
|
||||
|
|
@ -93,10 +93,10 @@ int main(void)
|
|||
if (IsKeyPressed(KEY_D))
|
||||
{
|
||||
enableEffectDelay = !enableEffectDelay;
|
||||
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
||||
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay, 0);
|
||||
else DetachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
||||
}
|
||||
|
||||
|
||||
// Get normalized time played for current music stream
|
||||
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music);
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ int main(void)
|
|||
|
||||
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 20, LIGHTGRAY);
|
||||
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 260, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
DrawText(TextFormat("PRESS F TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), 200, 320, 20, GRAY);
|
||||
DrawText(TextFormat("PRESS D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY);
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ int main(void)
|
|||
// Module Functions Definition
|
||||
//------------------------------------------------------------------------------------
|
||||
// Audio effect: lowpass filter
|
||||
static void AudioProcessEffectLPF(void *buffer, unsigned int frames)
|
||||
static void AudioProcessEffectLPF(void *buffer, unsigned int frames, void *context)
|
||||
{
|
||||
static float low[2] = { 0.0f, 0.0f };
|
||||
static const float cutoff = 70.0f / 44100.0f; // 70 Hz lowpass filter
|
||||
|
|
@ -164,7 +164,7 @@ static void AudioProcessEffectLPF(void *buffer, unsigned int frames)
|
|||
}
|
||||
|
||||
// Audio effect: delay
|
||||
static void AudioProcessEffectDelay(void *buffer, unsigned int frames)
|
||||
static void AudioProcessEffectDelay(void *buffer, unsigned int frames, void *context)
|
||||
{
|
||||
for (unsigned int i = 0; i < frames*2; i += 2)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue