Skip to content

Commit

Permalink
Add mixer float version, use it for linux jack engine
Browse files Browse the repository at this point in the history
  • Loading branch information
falkTX committed Oct 29, 2013
1 parent 6ced67a commit 1f58910
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 9 deletions.
104 changes: 103 additions & 1 deletion release/distrib/replay/lib/replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,107 @@ void Initreverb(void);
volatile int Done_Reset;
void Reset_Values(void);

// ------------------------------------------------------
// Audio mixer, float version
void STDCALL MixerFloat(float *buf1, float* buf2, Uint32 Len)
{
#if !defined(__STAND_ALONE__)
float clamp_left_value;
float clamp_right_value;
#endif

#if !defined(__STAND_ALONE__)
if(!rawrender)
{
#endif
for(Uint32 i = 0; i < Len; ++i)
{
GetPlayerValues();

#if !defined(__STAND_ALONE__)
// Gather datas for the scopes and the vumeters
clamp_left_value = left_float * 32767.0f;
clamp_right_value = right_float * 32767.0f;
#endif

#if !defined(__WINAMP__)
#if !defined(__STAND_ALONE__)
// Add the metronome at the end of the audio chain
if(trigger_metronome)
{
short Left_Dat;
short Right_Dat;
Left_Dat = (Metronome_Dats[(metronome_internal_counter_int * 2) + 1] << 8) |
(Metronome_Dats[(metronome_internal_counter_int * 2)] & 0xff);
Right_Dat = Left_Dat;

#if defined(__MACOSX__)
if(AUDIO_16Bits)
{
left_value += Left_Dat;
right_value += Right_Dat;
}
else
{
// ([1.0..-1.0f])
left_float += (float) (Left_Dat) / 32767.0f;
right_float += (float) (Right_Dat) / 32767.0f;
}
#else
left_value += Left_Dat;
right_value += Right_Dat;
#endif

metronome_internal_counter_int++;
if((metronome_internal_counter_int) == Metronome_Dats_Size)
{
metronome_internal_counter_int = 0;
trigger_metronome = FALSE;
metronome_latency = TRUE;
}
}
#endif
#endif

*buf1++ = left_float;
*buf2++ = right_float;

#if !defined(__STAND_ALONE__)
// Pre-record
Scope_Dats_LeftRight[0][pos_scope] = clamp_left_value;
Scope_Dats_LeftRight[1][pos_scope] = clamp_right_value;

clamp_left_value = fabsf(Scope_Dats_LeftRight[0][pos_scope_latency]);
clamp_right_value = fabsf(Scope_Dats_LeftRight[1][pos_scope_latency]);
if(clamp_left_value > L_MaxLevel) L_MaxLevel = (int) clamp_left_value;
if(clamp_right_value > R_MaxLevel) R_MaxLevel = (int) clamp_right_value;
wait_level++;
if(wait_level > 127)
{
wait_level = 0;
L_MaxLevel -= 128;
R_MaxLevel -= 128;
if(L_MaxLevel < 0) L_MaxLevel = 0;
if(R_MaxLevel < 0) R_MaxLevel = 0;
}

pos_scope++;
if(pos_scope >= (AUDIO_Latency / 2)) pos_scope = 0;
pos_scope_latency = pos_scope - (AUDIO_Latency / 4);
if(pos_scope_latency < 0) pos_scope_latency = (AUDIO_Latency / 2) + pos_scope_latency;
#endif
}

if(local_curr_ramp_vol <= 0.0f)
{
Reset_Values();
}

#if !defined(__STAND_ALONE__)
} //RawRender
#endif
}

// ------------------------------------------------------
// Audio mixer
void STDCALL Mixer(Uint8 *Buffer, Uint32 Len)
Expand Down Expand Up @@ -1206,7 +1307,8 @@ int STDCALL Ptk_InitDriver(void)
#if defined(__WIN32__)
if(!AUDIO_Init_Driver(hWnd, &Mixer))
#else
if(!AUDIO_Init_Driver(&Mixer))
//if(!AUDIO_Init_Driver(&Mixer))
if(!AUDIO_Init_DriverFloat(&MixerFloat))
#endif
{
return(FALSE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ extern int AUDIO_Milliseconds;
void Message_Error(char *Message);
#endif

int AUDIO_Init_Driver(void (STDCALL *Mixer)(Uint8 *, Uint32));
//int AUDIO_Init_Driver(void (STDCALL *Mixer)(Uint8 *, Uint32));
int AUDIO_Init_DriverFloat(void (STDCALL *Mixer)(float*, float*, Uint32));
int AUDIO_Create_Sound_Buffer(int milliseconds);
void AUDIO_Stop_Sound_Buffer(void);
void AUDIO_Stop_Driver(void);
Expand Down
21 changes: 14 additions & 7 deletions release/distrib/replay/lib/sounddriver/sounddriver_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void AUDIO_Stop_Sound_Buffer(void) {}

// ------------------------------------------------------
// Functions
void (STDCALL *AUDIO_Mixer)(Uint8 *, Uint32);
void (STDCALL *AUDIO_Mixer)(Uint8 *, Uint32) = NULL;
void (STDCALL *AUDIO_MixerFloat)(float*, float*, Uint32) = NULL;

static int jaudio_process_callback(jack_nframes_t nframes, void*)
{
Expand All @@ -69,14 +70,15 @@ static int jaudio_process_callback(jack_nframes_t nframes, void*)

if (AUDIO_Play_Flag)
{
#if 0
Uint8 mixerBuf[nframes*2];
AUDIO_Mixer(mixerBuf, nframes*2);

for (jack_nframes_t i=0; i < nframes; ++i)
{
audioBuf1[i] = float(mixerBuf[ i])*2.0f-1.0f;
audioBuf2[i] = float(mixerBuf[nframes+i])*2.0f-1.0f;
}
audioBuf1[i] = audioBuf2[i] = double((signed short)((mixerBuf[2*i+1]<<8) | mixerBuf[2*i]))*2.0/65535.0;
#else
AUDIO_MixerFloat(audioBuf1, audioBuf2, nframes);
#endif

AUDIO_Samples += nframes;
AUDIO_Timer = ((((float) AUDIO_Samples) * (1.0f / (float) AUDIO_Latency)) * 1000.0f);
Expand All @@ -103,9 +105,14 @@ static void jaudio_shutdown_callback(void* arg)
// ------------------------------------------------------
// Name: AUDIO_Init_Driver()
// Desc: Init the audio driver
int AUDIO_Init_Driver(void (*Mixer)(Uint8 *, Uint32))

// int AUDIO_Init_Driver(void (*Mixer)(Uint8 *, Uint32))
// {
// AUDIO_Mixer = Mixer;

int AUDIO_Init_DriverFloat(void (*MixerFloat)(float*, float*, Uint32))
{
AUDIO_Mixer = Mixer;
AUDIO_MixerFloat = MixerFloat;

jaudio_client = jack_client_open("protrekkr", JackNullOption, NULL);

Expand Down

0 comments on commit 1f58910

Please sign in to comment.