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

compatible c and c++ #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/biquad.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef SNDFILTER_BIQUAD__H
#define SNDFILTER_BIQUAD__H

#include "sf_common.h"
#include "snd.h"

// biquad filtering is a technique used to perform a variety of sound filters
Expand Down Expand Up @@ -41,6 +42,8 @@ typedef struct {
sf_sample_st yn2;
} sf_biquad_state_st;

SF_API_BEGIN

// these functions will initialize an sf_biquad_state_st structure based on the desired filter
void sf_lowpass (sf_biquad_state_st *state, int rate, float cutoff, float resonance);
void sf_highpass (sf_biquad_state_st *state, int rate, float cutoff, float resonance);
Expand All @@ -56,4 +59,6 @@ void sf_highshelf(sf_biquad_state_st *state, int rate, float freq, float Q, floa
void sf_biquad_process(sf_biquad_state_st *state, int size, sf_sample_st *input,
sf_sample_st *output);

SF_API_END

#endif // SNDFILTER_BIQUAD__H
5 changes: 5 additions & 0 deletions src/compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef SNDFILTER_COMPRESSOR__H
#define SNDFILTER_COMPRESSOR__H

#include "sf_common.h"
#include "snd.h"

// dynamic range compression is a complex topic with many different algorithms
Expand Down Expand Up @@ -75,6 +76,8 @@ typedef struct {
sf_sample_st delaybuf[SF_COMPRESSOR_MAXDELAY]; // predelay buffer
} sf_compressor_state_st;

SF_API_BEGIN

// populate a compressor state with all default values
void sf_defaultcomp(sf_compressor_state_st *state, int rate);

Expand Down Expand Up @@ -108,4 +111,6 @@ void sf_advancecomp(sf_compressor_state_st *state,
void sf_compressor_process(sf_compressor_state_st *state, int size, sf_sample_st *input,
sf_sample_st *output);

SF_API_END

#endif // SNDFILTER_COMPRESSOR__H
5 changes: 5 additions & 0 deletions src/reverb.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
#ifndef SNDFILTER_REVERB__H
#define SNDFILTER_REVERB__H

#include "sf_common.h"
#include "snd.h"

SF_API_BEGIN

// this API works by first initializing an sf_reverb_state_st structure, then using it to process a
// sample in chunks
//
Expand Down Expand Up @@ -286,4 +289,6 @@ void sf_advancereverb(sf_reverb_state_st *rv,
void sf_reverb_process(sf_reverb_state_st *state, int size, sf_sample_st *input,
sf_sample_st *output);

SF_API_END

#endif // SNDFILTER_REVERB__H
20 changes: 20 additions & 0 deletions src/sf_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// (c) Copyright 2021, Kazuki Tanaka (@tk-aria)
// MIT License
// Project Home: https://github.com/velipso/sndfilter

#ifndef SNDFILTER_COMMON__H
#define SNDFILTER_COMMON__H

#ifdef __cplusplus

#define SF_API_BEGIN extern "C" {
#define SF_API_END }

#else

#define SF_API_BEGIN
#define SF_API_END

#endif

#endif // SNDFILTER_COMMON__H
5 changes: 5 additions & 0 deletions src/snd.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define SNDFILTER_SND__H

#include <stdbool.h>
#include "sf_common.h"

typedef struct {
float L; // left channel sample
Expand All @@ -20,7 +21,11 @@ typedef struct {
int rate; // samples per second
} sf_snd_st, *sf_snd;

SF_API_BEGIN

sf_snd sf_snd_new(int size, int rate, bool clear);
void sf_snd_free(sf_snd snd);

SF_API_END

#endif // SNDFILTER_SND__H
5 changes: 5 additions & 0 deletions src/wav.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
#ifndef SNDFILTER_WAV__H
#define SNDFILTER_WAV__H

#include "sf_common.h"
#include "snd.h"

SF_API_BEGIN

sf_snd sf_wavload(const char *file);
bool sf_wavsave(sf_snd snd, const char *file);

SF_API_END

#endif // SNDFILTER_WAV__H