mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-15 19:05:34 +00:00
REVIEWED: Formatting to follow raylib conventions
This commit is contained in:
@@ -148,7 +148,7 @@ int main(void)
|
||||
CaptureFrame(&fft, audioSamples);
|
||||
RenderFrame(&fft, &fftImage);
|
||||
UpdateTexture(fftTexture, fftImage.data);
|
||||
//------------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
@@ -269,7 +269,7 @@ static void CaptureFrame(FFTData *fftData, const float *audioSamples)
|
||||
|
||||
fftData->lastFftTime = GetTime();
|
||||
memcpy(fftData->fftHistory[fftData->historyPos], smoothedSpectrum, sizeof(smoothedSpectrum));
|
||||
fftData->historyPos = (fftData->historyPos + 1) % fftData->fftHistoryLen;
|
||||
fftData->historyPos = (fftData->historyPos + 1)%fftData->fftHistoryLen;
|
||||
}
|
||||
|
||||
static void RenderFrame(const FFTData *fftData, Image *fftImage)
|
||||
@@ -277,12 +277,9 @@ static void RenderFrame(const FFTData *fftData, Image *fftImage)
|
||||
double framesSinceTapback = floor(fftData->tapbackPos/WINDOW_TIME);
|
||||
framesSinceTapback = Clamp(framesSinceTapback, 0.0, fftData->fftHistoryLen - 1);
|
||||
|
||||
int historyPosition = (fftData->historyPos - 1 - (int)framesSinceTapback) % fftData->fftHistoryLen;
|
||||
if (historyPosition < 0)
|
||||
historyPosition += fftData->fftHistoryLen;
|
||||
int historyPosition = (fftData->historyPos - 1 - (int)framesSinceTapback)%fftData->fftHistoryLen;
|
||||
if (historyPosition < 0) historyPosition += fftData->fftHistoryLen;
|
||||
|
||||
const float *amplitude = fftData->fftHistory[historyPosition];
|
||||
for (int bin = 0; bin < BUFFER_SIZE; bin++) {
|
||||
ImageDrawPixel(fftImage, bin, FFT_ROW, ColorFromNormalized((Vector4){ amplitude[bin], UNUSED_CHANNEL, UNUSED_CHANNEL, UNUSED_CHANNEL }));
|
||||
}
|
||||
for (int bin = 0; bin < BUFFER_SIZE; bin++) ImageDrawPixel(fftImage, bin, FFT_ROW, ColorFromNormalized((Vector4){ amplitude[bin], UNUSED_CHANNEL, UNUSED_CHANNEL, UNUSED_CHANNEL }));
|
||||
}
|
||||
@@ -35,10 +35,10 @@ int main(void)
|
||||
|
||||
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
|
||||
bool pause = false; // Music playing paused
|
||||
|
||||
|
||||
float pan = 0.0f; // Default audio pan center [-1.0f..1.0f]
|
||||
SetMusicPan(music, pan);
|
||||
|
||||
|
||||
float volume = 0.8f; // Default audio volume [0.0f..1.0f]
|
||||
SetMusicVolume(music, volume);
|
||||
|
||||
@@ -67,29 +67,29 @@ int main(void)
|
||||
if (pause) PauseMusicStream(music);
|
||||
else ResumeMusicStream(music);
|
||||
}
|
||||
|
||||
|
||||
// Set audio pan
|
||||
if (IsKeyDown(KEY_LEFT))
|
||||
if (IsKeyDown(KEY_LEFT))
|
||||
{
|
||||
pan -= 0.05f;
|
||||
if (pan < -1.0f) pan = -1.0f;
|
||||
SetMusicPan(music, pan);
|
||||
}
|
||||
else if (IsKeyDown(KEY_RIGHT))
|
||||
else if (IsKeyDown(KEY_RIGHT))
|
||||
{
|
||||
pan += 0.05f;
|
||||
if (pan > 1.0f) pan = 1.0f;
|
||||
SetMusicPan(music, pan);
|
||||
}
|
||||
|
||||
|
||||
// Set audio volume
|
||||
if (IsKeyDown(KEY_DOWN))
|
||||
if (IsKeyDown(KEY_DOWN))
|
||||
{
|
||||
volume -= 0.05f;
|
||||
if (volume < 0.0f) volume = 0.0f;
|
||||
SetMusicVolume(music, volume);
|
||||
}
|
||||
else if (IsKeyDown(KEY_UP))
|
||||
else if (IsKeyDown(KEY_UP))
|
||||
{
|
||||
volume += 0.05f;
|
||||
if (volume > 1.0f) volume = 1.0f;
|
||||
@@ -109,7 +109,7 @@ int main(void)
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
DrawText("LEFT-RIGHT for PAN CONTROL", 320, 74, 10, DARKBLUE);
|
||||
DrawRectangle(300, 100, 200, 12, LIGHTGRAY);
|
||||
DrawRectangleLines(300, 100, 200, 12, GRAY);
|
||||
@@ -121,7 +121,7 @@ int main(void)
|
||||
|
||||
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
|
||||
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
DrawText("UP-DOWN for VOLUME CONTROL", 320, 334, 10, DARKGREEN);
|
||||
DrawRectangle(300, 360, 200, 12, LIGHTGRAY);
|
||||
DrawRectangleLines(300, 360, 200, 12, GRAY);
|
||||
|
||||
@@ -166,7 +166,7 @@ int main(void)
|
||||
memcpy(writeBuf + writeCursor, data + readCursor, writeLength*sizeof(short));
|
||||
|
||||
// Update cursors and loop audio
|
||||
readCursor = (readCursor + writeLength) % waveLength;
|
||||
readCursor = (readCursor + writeLength)%waveLength;
|
||||
|
||||
writeCursor += writeLength;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ int main(void)
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user