Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VERBLIB_PCM_TYPE and VERBLIB_PCM_TYPE_MAX #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions verblib.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
#ifndef VERBLIB_H
#define VERBLIB_H

#ifndef VERBLIB_PCM_TYPE
#define VERBLIB_PCM_TYPE float
#endif

#ifndef VERBLIB_PCM_MAX_VALUE
#define VERBLIB_PCM_MAX_VALUE 1.0f
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -55,7 +63,7 @@ extern "C" {
* output_buffer may be the same pointer as input_buffer if in place processing is desired.
* frames specifies the number of sample frames that should be processed.
*/
void verblib_process ( verblib* verb, const float* input_buffer, float* output_buffer, unsigned long frames );
void verblib_process ( verblib* verb, const VERBLIB_PCM_TYPE* input_buffer, VERBLIB_PCM_TYPE* output_buffer, unsigned long frames );

/* Set the size of the room, between 0.0 and 1.0. */
void verblib_set_room_size ( verblib* verb, float value );
Expand Down Expand Up @@ -472,7 +480,7 @@ int verblib_initialize ( verblib* verb, unsigned long sample_rate, unsigned int
return 1;
}

void verblib_process ( verblib* verb, const float* input_buffer, float* output_buffer, unsigned long frames )
void verblib_process ( verblib* verb, const VERBLIB_PCM_TYPE* input_buffer, VERBLIB_PCM_TYPE* output_buffer, unsigned long frames )
{
int i;
float outL, outR, input;
Expand All @@ -482,7 +490,7 @@ void verblib_process ( verblib* verb, const float* input_buffer, float* output_b
while ( frames-- > 0 )
{
outL = 0.0f;
input = ( input_buffer[0] * 2.0f ) * verb->gain;
input = ( (float)(input_buffer[0]) / VERBLIB_PCM_MAX_VALUE * 2.0f ) * verb->gain;

/* Accumulate comb filters in parallel. */
for ( i = 0; i < verblib_numcombs; i++ )
Expand All @@ -497,7 +505,7 @@ void verblib_process ( verblib* verb, const float* input_buffer, float* output_b
}

/* Calculate output REPLACING anything already there. */
output_buffer[0] = outL * verb->wet1 + input_buffer[0] * verb->dry;
output_buffer[0] = (VERBLIB_PCM_TYPE)((outL * verb->wet1 + ((float)(input_buffer[0]) / VERBLIB_PCM_MAX_VALUE) * verb->dry) * VERBLIB_PCM_MAX_VALUE);

/* Increment sample pointers. */
++input_buffer;
Expand All @@ -523,8 +531,8 @@ void verblib_process ( verblib* verb, const float* input_buffer, float* output_b
const float coef_side = verb->input_width * tmp;
while ( frames-- > 0 )
{
const float mid = ( input_buffer[0] + input_buffer[1] ) * coef_mid;
const float side = ( input_buffer[1] - input_buffer[0] ) * coef_side;
const float mid = ( (float)(input_buffer[0]) / VERBLIB_PCM_MAX_VALUE + (float)(input_buffer[1]) / VERBLIB_PCM_MAX_VALUE ) * coef_mid;
const float side = ( (float)(input_buffer[1]) / VERBLIB_PCM_MAX_VALUE - (float)(input_buffer[0]) / VERBLIB_PCM_MAX_VALUE ) * coef_side;
const float input_left = ( mid - side ) * ( verb->gain * 2.0f );
const float input_right = ( mid + side ) * ( verb->gain * 2.0f );

Expand All @@ -545,8 +553,8 @@ void verblib_process ( verblib* verb, const float* input_buffer, float* output_b
}

/* Calculate output REPLACING anything already there. */
output_buffer[0] = outL * verb->wet1 + outR * verb->wet2 + input_buffer[0] * verb->dry;
output_buffer[1] = outR * verb->wet1 + outL * verb->wet2 + input_buffer[1] * verb->dry;
output_buffer[0] = (VERBLIB_PCM_TYPE)((outL * verb->wet1 + outR * verb->wet2 + ((float)(input_buffer[0]) / VERBLIB_PCM_MAX_VALUE) * verb->dry) * VERBLIB_PCM_MAX_VALUE);
output_buffer[1] = (VERBLIB_PCM_TYPE)((outR * verb->wet1 + outL * verb->wet2 + ((float)(input_buffer[1]) / VERBLIB_PCM_MAX_VALUE) * verb->dry) * VERBLIB_PCM_MAX_VALUE);

/* Increment sample pointers. */
input_buffer += 2;
Expand All @@ -558,7 +566,7 @@ void verblib_process ( verblib* verb, const float* input_buffer, float* output_b
while ( frames-- > 0 )
{
outL = outR = 0.0f;
input = ( input_buffer[0] + input_buffer[1] ) * verb->gain;
input = ( (float)(input_buffer[0]) / VERBLIB_PCM_MAX_VALUE + (float)(input_buffer[1]) / VERBLIB_PCM_MAX_VALUE ) * verb->gain;

/* Accumulate comb filters in parallel. */
for ( i = 0; i < verblib_numcombs; i++ )
Expand All @@ -575,8 +583,8 @@ void verblib_process ( verblib* verb, const float* input_buffer, float* output_b
}

/* Calculate output REPLACING anything already there. */
output_buffer[0] = outL * verb->wet1 + outR * verb->wet2 + input_buffer[0] * verb->dry;
output_buffer[1] = outR * verb->wet1 + outL * verb->wet2 + input_buffer[1] * verb->dry;
output_buffer[0] = (VERBLIB_PCM_TYPE)((outL * verb->wet1 + outR * verb->wet2 + ((float)(input_buffer[0]) / VERBLIB_PCM_MAX_VALUE) * verb->dry) * VERBLIB_PCM_MAX_VALUE);
output_buffer[1] = (VERBLIB_PCM_TYPE)((outR * verb->wet1 + outL * verb->wet2 + ((float)(input_buffer[1]) / VERBLIB_PCM_MAX_VALUE) * verb->dry) * VERBLIB_PCM_MAX_VALUE);

/* Increment sample pointers. */
input_buffer += 2;
Expand Down