rewrite noise

This commit is contained in:
Connor Olding 2015-06-08 11:44:06 -07:00
parent a945cabb4c
commit 5f6921bf5c
3 changed files with 56 additions and 41 deletions

View File

@ -1,45 +1,62 @@
#define ID 0xEC57A71C
#define LABEL "crap_noise"
#define NAME "crap noise generator"
#define AUTHOR "Connor Olding"
#define COPYRIGHT "MIT"
#define PARAMETERS 0
#include <string.h>
#include "util.hpp"
#include "Param.hpp"
#include "Crap.hpp"
typedef struct {
} personal;
struct Crap_noise
:public AdjustAll<Crap> {
static constexpr ulong id = 0xEC57A71C;
static constexpr char label[] = "crap_noise";
static constexpr char name[] = "crap noise generator";
static constexpr char author[] = "Connor Olding";
static constexpr char copyright[] = "MIT";
static constexpr ulong parameters = 0;
template<typename T>
INNER void
process(personal *data,
T *in_L, T *in_R,
T *out_L, T *out_R,
unsigned long count)
{
// TODO: separate and preserve mirand for each channel
for (unsigned long pos = 0; pos < count; pos++)
out_L[pos] = whitenoise();
for (unsigned long pos = 0; pos < count; pos++)
out_R[pos] = whitenoise();
}
unsigned int mirand_L, mirand_R;
INNER void
construct(personal *data)
{}
inline
Crap_noise()
: mirand_L(123), mirand_R(456)
{}
INNER void
destruct(personal *data)
{}
inline void
process(
double *in_L, double *in_R,
double *out_L, double *out_R,
ulong count)
{
for (ulong i = 0; i < count; i++)
out_L[i] = whitenoise(mirand_L);
for (ulong i = 0; i < count; i++)
out_R[i] = whitenoise(mirand_R);
}
INNER void
resume(personal *data)
{}
inline void
process(
float *in_L, float *in_R,
float *out_L, float *out_R,
ulong count)
{
for (ulong i = 0; i < count; i++)
out_L[i] = whitenoise(mirand_L);
for (ulong i = 0; i < count; i++)
out_R[i] = whitenoise(mirand_R);
}
INNER void
pause(personal *data)
{}
static inline void
construct_params(Param *params)
{}
INNER void
adjust(personal *data, unsigned long fs)
{}
inline void
resume()
{}
inline void
pause()
{}
inline void
adjust_all(Param *params)
{}
};

View File

@ -37,10 +37,8 @@ disable_denormals()
#define ANGULAR_LIM(fc, fs) (2 * M_PI / (fs) * LIMIT((fc), 1, (fs)/2))
/* via http://www.rgba.org/articles/sfrand/sfrand.htm */
static unsigned int mirand = 1;
INNER float
whitenoise()
whitenoise(unsigned int &mirand)
{
union either {
float f;

View File

@ -123,9 +123,9 @@ main(int argc, char **argv)
}
}
mirand = time(NULL);
unsigned int mirand = time(NULL);
for (int i = 0; i < audio_count*BLOCK_SIZE; i++)
audio_buffer[i] = whitenoise();
audio_buffer[i] = whitenoise(mirand);
if (d->activate) d->activate(h);
for (int i = 0; i < 64*64*8; i++)