Skip to content

Commit

Permalink
fixed the visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
ravachol committed Feb 12, 2024
1 parent acb3db2 commit fde40bb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/soundcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define CHANNELS 2
#define SAMPLE_RATE 192000
#define SAMPLE_WIDTH 3
#define SAMPLE_FORMAT ma_format_s24
#define SAMPLE_FORMAT ma_format_s32

#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 4800
Expand Down
65 changes: 40 additions & 25 deletions src/visuals.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,36 +295,51 @@ void calcSpectrum(int height, int numBars, fftwf_complex *fftInput, fftwf_comple
{

ma_int32 *g_audioBuffer = getAudioBuffer();
ma_decoder *decoder = getCurrentDecoder();
int bitDepth = 24;

ma_format format = SAMPLE_FORMAT;

if (getCurrentImplementationType() == BUILTIN && decoder != NULL)
if (getCurrentImplementationType() == BUILTIN)
{
ma_decoder *decoder = getCurrentDecoder();
format = decoder->outputFormat;
}
else if (getCurrentImplementationType() == OPUS)
{
ma_libopus *decoder = getCurrentOpusDecoder();
format = decoder->format;
}
else if (getCurrentImplementationType() == VORBIS)
{
ma_libvorbis *decoder = getCurrentVorbisDecoder();
format = decoder->format;
}
else if (getCurrentImplementationType() == M4A)
{
m4a_decoder *decoder = getCurrentM4aDecoder();
format = decoder->format;
}

switch (format)
{
case ma_format_u8:
bitDepth = 8;
break;

case ma_format_s16:
bitDepth = 16;
break;

case ma_format_s24:
bitDepth = 24;
break;

case ma_format_f32:
case ma_format_s32:
bitDepth = 32;
break;
default:
break;
}
int bitDepth = 32;

switch (format)
{
case ma_format_u8:
bitDepth = 8;
break;

case ma_format_s16:
bitDepth = 16;
break;

case ma_format_s24:
bitDepth = 24;
break;

case ma_format_f32:
case ma_format_s32:
bitDepth = 32;
break;
default:
break;
}

calc(height, numBars, g_audioBuffer, bitDepth, fftInput, fftOutput, magnitudes, plan);
Expand Down

0 comments on commit fde40bb

Please sign in to comment.