[hatari-devel] sound.c code and stats function output |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
Hi,
When checking the sound.c patch on the list, I noticed that sound.c
includes few variables and functions that are not used anywhere else,
and could therefore be static.
Sound_Stats_Show() is one of them. I started to wonder whether it would
make sense to convert it into one of the debugger "info" functions, so
that it could be called from breakpoints.
Attached patch does that, and limits visibility of the vars & functions
not used outside of sound.c.
With that patch, and these debugger commands, sound info function would
be called on every 8th VBL:
> lock sound 1
> b VBL ! VBL :8 :lock :quiet
Note: Above "locks" sound info function to be called on every debugger
invocation, with verbosity level 1 [1]. And create breakpoint trigger
when VBL count changes, for the 8th time, calls locked info function,
and is "quiet" ie. does not show breakpoint details.
- Eero
[1] Only few info functions do handle extra arg, and typically just as a
flag on whether to list opcodes / function names for OS trap. For rest
of info functions, it's a dummy arg:
$ git grep _Info | grep h:.*dummy
falcon/crossbar.h:extern void Crossbar_Info(FILE *fp, uint32_t dummy);
falcon/dsp.h:extern void DSP_Info(FILE *fp, uint32_t dummy);
falcon/nvram.h:extern void NvRam_Info(FILE *fp, uint32_t dummy);
falcon/videl.h:extern void Videl_Info(FILE *fp, uint32_t dummy);
includes/acia.h:void ACIA_Info(FILE *fp, uint32_t dummy);
includes/bios.h:extern void Bios_Info(FILE *fp, uint32_t dummy);
includes/dmaSnd.h:extern void DmaSnd_Info(FILE *fp, uint32_t dummy);
includes/ikbd.h:extern void IKBD_Info(FILE *fp, uint32_t dummy);
includes/mfp.h:extern void MFP_Info(FILE *fp, uint32_t dummy);
includes/psg.h:extern void PSG_Info(FILE *fp, uint32_t dummy);
includes/rtc.h:extern void Rtc_Info(FILE *fp, uint32_t dummy);
includes/scc.h:void SCC_Info(FILE *fp, uint32_t dummy);
includes/video.h:extern void Video_Info(FILE *fp, uint32_t dummy);
includes/xbios.h:extern void XBios_Info(FILE *fp, uint32_t dummy);
But if in some case increasing (or reducing) their verbosity would be
useful, those dummy args could be be changed to a verbosity one...
diff --git a/src/debug/debugInfo.c b/src/debug/debugInfo.c
index 22b0a805..b5605773 100644
--- a/src/debug/debugInfo.c
+++ b/src/debug/debugInfo.c
@@ -37,6 +37,7 @@ const char DebugInfo_fileid[] = "Hatari debuginfo.c";
#include "nvram.h"
#include "psg.h"
#include "rtc.h"
+#include "sound.h"
#include "stMemory.h"
#include "scu_vme.h"
#include "tos.h"
@@ -681,7 +682,7 @@ static const struct {
{ true, "registers", DebugInfo_CpuRegister,NULL, "Show CPU register contents" },
{ false,"rtc", Rtc_Info, NULL, "Show (Mega ST/STE) RTC register contents" },
{ false,"scc", SCC_Info, NULL, "Show SCC register contents" },
- { false,"scu", SCU_Info, NULL, "Show SCU/VME register information" },
+ { false,"sound", Sound_Stats_Info, NULL, "Show internal sound handling info, arg is verbosity" },
{ false,"vdi", VDI_Info, NULL, "Show VDI vector contents (with <value>, show opcodes)" },
{ false,"videl", Videl_Info, NULL, "Show Falcon Videl register contents" },
{ false,"video", Video_Info, NULL, "Show Video information" },
diff --git a/src/includes/sound.h b/src/includes/sound.h
index d72b5dc4..7bff0b62 100644
--- a/src/includes/sound.h
+++ b/src/includes/sound.h
@@ -22,7 +22,7 @@ extern bool bEnvelopeFreqFlag;
#define AUDIOMIXBUFFER_SIZE 16384 /* Size of circular buffer to store samples (eg 44Khz), must be a power of 2 */
#define AUDIOMIXBUFFER_SIZE_MASK ( AUDIOMIXBUFFER_SIZE - 1 ) /* To limit index values inside AudioMixBuffer[] */
extern int16_t AudioMixBuffer[AUDIOMIXBUFFER_SIZE][2]; /* Ring buffer to store mixed audio output (YM2149, DMA sound, ...) */
-extern int AudioMixBuffer_pos_write; /* Current writing position into above buffer */
+//extern int AudioMixBuffer_pos_write; /* Current writing position into above buffer */
extern int AudioMixBuffer_pos_read; /* Current reading position into above buffer */
extern bool Sound_BufferIndexNeedReset;
@@ -55,17 +55,17 @@ extern int YM2149_LPF_Filter;
#define YM2149_HPF_FILTER_NONE 0
#define YM2149_HPF_FILTER_IIR 1
-extern int YM2149_HPF_Filter;
+//extern int YM2149_HPF_Filter;
#define YM2149_RESAMPLE_METHOD_NEAREST 0
#define YM2149_RESAMPLE_METHOD_WEIGHTED_AVERAGE_2 1
#define YM2149_RESAMPLE_METHOD_WEIGHTED_AVERAGE_N 2
-extern int YM2149_Resample_Method;
+//extern int YM2149_Resample_Method;
extern void Sound_Init(void);
extern void Sound_Reset(void);
-extern void Sound_ResetBufferIndex(void);
+//extern void Sound_ResetBufferIndex(void);
extern void Sound_MemorySnapShot_Capture(bool bSave);
extern void Sound_Stats_Show (void);
extern void Sound_Update(uint64_t CPU_Clock);
@@ -77,6 +77,7 @@ extern bool Sound_AreWeRecording(void);
extern void Sound_SetYmVolumeMixing(void);
extern ymsample Subsonic_IIR_HPF_Left(ymsample x0);
extern ymsample Subsonic_IIR_HPF_Right(ymsample x0);
+extern void Sound_Stats_Info ( FILE *fp, uint32_t verbosity );
#endif /* HATARI_SOUND_H */
diff --git a/src/sound.c b/src/sound.c
index 86c7f725..ef598c4d 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -287,12 +287,12 @@ int YmVolumeMixing = YM_TABLE_MIXING;
int YM2149_LPF_Filter = YM2149_LPF_FILTER_PWM;
// int YM2149_LPF_Filter = YM2149_LPF_FILTER_NONE; /* For debug */
-int YM2149_HPF_Filter = YM2149_HPF_FILTER_IIR;
-// int YM2149_HPF_Filter = YM2149_HPF_FILTER_NONE; /* For debug */
+static int YM2149_HPF_Filter = YM2149_HPF_FILTER_IIR;
+// static int YM2149_HPF_Filter = YM2149_HPF_FILTER_NONE; /* For debug */
-//int YM2149_Resample_Method = YM2149_RESAMPLE_METHOD_NEAREST;
-//int YM2149_Resample_Method = YM2149_RESAMPLE_METHOD_WEIGHTED_AVERAGE_2;
-int YM2149_Resample_Method = YM2149_RESAMPLE_METHOD_WEIGHTED_AVERAGE_N;
+//static int YM2149_Resample_Method = YM2149_RESAMPLE_METHOD_NEAREST;
+//static int YM2149_Resample_Method = YM2149_RESAMPLE_METHOD_WEIGHTED_AVERAGE_2;
+static int YM2149_Resample_Method = YM2149_RESAMPLE_METHOD_WEIGHTED_AVERAGE_N;
static double pos_fract_nearest; /* For YM2149_Next_Resample_Nearest */
static double pos_fract_weighted_2; /* For YM2149_Next_Resample_Weighted_Average_2 */
@@ -302,8 +302,8 @@ static uint32_t pos_fract_weighted_n; /* YM2149_Next_Resample_Weighted_Average
bool bEnvelopeFreqFlag; /* Cleared each frame for YM saving */
int16_t AudioMixBuffer[AUDIOMIXBUFFER_SIZE][2]; /* Ring buffer to store mixed audio output (YM2149, DMA sound, ...) */
-int AudioMixBuffer_pos_write; /* Current writing position into above buffer */
int AudioMixBuffer_pos_read; /* Current reading position into above buffer */
+static int AudioMixBuffer_pos_write; /* Current writing position into above buffer */
int nGeneratedSamples; /* Generated samples since audio buffer update */
@@ -317,7 +317,7 @@ bool Sound_BufferIndexNeedReset = false;
/* we can have 5000 YM samples per VBL. We use a slightly larger buffer */
/* to have some kind of double buffering */
#define YM_BUFFER_250_SIZE_MASK ( YM_BUFFER_250_SIZE - 1 ) /* To limit index values inside the ring buffer */
-ymsample YM_Buffer_250[ YM_BUFFER_250_SIZE ]; /* Ring buffer to store YM samples */
+static ymsample YM_Buffer_250[ YM_BUFFER_250_SIZE ]; /* Ring buffer to store YM samples */
static int YM_Buffer_250_pos_write; /* Current writing position into above buffer */
static int YM_Buffer_250_pos_read; /* Current reading position into above buffer */
@@ -1568,7 +1568,7 @@ void Sound_Reset(void)
* Very important : this function should only be called by setting
* Sound_BufferIndexNeedReset=true
*/
-void Sound_ResetBufferIndex(void)
+static void Sound_ResetBufferIndex(void)
{
Audio_Lock();
nGeneratedSamples = SoundBufferSize + SAMPLES_PER_FRAME;
@@ -1641,7 +1641,7 @@ void Sound_MemorySnapShot_Capture(bool bSave)
static void Sound_Stats_Add ( int Samples_Nbr )
{
Sound_Stats_Array[ Sound_Stats_Index++ ] = Samples_Nbr;
- if ( Sound_Stats_Index == SOUND_STATS_SIZE )
+ if ( Sound_Stats_Index >= ARRAY_SIZE(Sound_Stats_Array) )
Sound_Stats_Index = 0;
}
@@ -1654,7 +1654,7 @@ static void Sound_Stats_Add ( int Samples_Nbr )
* stay as close as possible over time to the chosen audio frequency (eg 44100 Hz).
* If not, it means the accuracy should be improved when generating YM samples
*/
-void Sound_Stats_Show ( void )
+void Sound_Stats_Info ( FILE *fp, uint32_t verbosity )
{
int i;
double sum;
@@ -1663,6 +1663,9 @@ void Sound_Stats_Show ( void )
double freq_diff;
static double diff_min=0, diff_max=0;
+ if (verbosity > 0)
+ fprintf ( fp , "Sound Stats: sound_update_vbl vbl=%d nbr=%d\n" , nVBLs, Sound_Stats_SamplePerVBL );
+
sum = 0;
for ( i=0 ; i<SOUND_STATS_SIZE ; i++ )
sum += Sound_Stats_Array[ i ];
@@ -1682,7 +1685,7 @@ void Sound_Stats_Show ( void )
if ( ( freq_diff > 0 ) && ( freq_diff < 40 ) && ( freq_diff > diff_max ) )
diff_max = freq_diff;
- fprintf ( stderr , "Sound_Stats_Show vbl_per_sec=%.4f freq_gen=%.4f freq_diff=%.4f (min=%.4f max=%.4f)\n" ,
+ fprintf ( fp , "Sound Stats: vbl_per_sec=%.4f freq_gen=%.4f freq_diff=%.4f (min=%.4f max=%.4f)\n" ,
vbl_per_sec , freq_gen , freq_diff , diff_min , diff_max );
}
@@ -1812,11 +1815,10 @@ void Sound_Update(uint64_t CPU_Clock)
void Sound_Update_VBL(void)
{
Sound_Update ( CyclesGlobalClockCounter ); /* generate as many samples as needed to fill this VBL */
-//fprintf ( stderr , "sound_update_vbl vbl=%d nbr=%d\n" , nVBLs, Sound_Stats_SamplePerVBL );
/* Update some stats */
Sound_Stats_Add ( Sound_Stats_SamplePerVBL );
-// Sound_Stats_Show ();
+// Sound_Stats_Info (stderr, 0);
/* Reset sound buffer if needed (after pause, fast forward, slow system, ...) */
if ( Sound_BufferIndexNeedReset )