Hash :
94046104
Author :
Thomas de Grivel
Date :
2020-02-24T15:19:27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
/*
This is part of Patchwork13! the real-time data synthesis toolkit.
http://patchwork13.sourceforge.net/
pw13_std - the patchwork13 standard patches library
Copyright (C) 2005 Thomas de Grivel <billitch@yahoo.fr>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
delay.pw13p.c - Generates a delay on buffers
*/
#include <stdlib.h>
#include <stdio.h>
#include <pw13/pw13.h>
#include <std/float.pw13dt.h>
#include <std/int.pw13dt.h>
typedef struct s_delay{
int nb_samples;
int absolute_position;
float* samples_buffer;
} s_delay;
static void pw13_delay_pump (Pw13_Patch *p, Pw13_Time *time)
{
float feedback;
s_delay* local_param;
int i,delay;
pw13_pump_sources (p, time);
feedback=pw13_float_input_val (p->input+2);
local_param = (s_delay*) p->param;
delay = pw13_int_input_val (p->input+1);
if (delay < 0)
{
delay = 0;
}
if ( (local_param->nb_samples) != (delay) )
{
if( local_param->samples_buffer != NULL)
{
local_param->samples_buffer=realloc(local_param->samples_buffer,
(delay)*sizeof(float));
if ( ((local_param->nb_samples) < (delay)) && (delay != 0 ))
{
for (i=(local_param->nb_samples-1);i<(delay);i++)
{
local_param->samples_buffer[i]=local_param->samples_buffer[i % (local_param->nb_samples)];
}
}
}
else
{
local_param->samples_buffer=malloc(sizeof(float)*(delay));
}
local_param->nb_samples = delay;
}
if( local_param->samples_buffer != NULL)
{
local_param->absolute_position ++ ;
local_param->absolute_position %= local_param->nb_samples;
local_param->samples_buffer[local_param->absolute_position] =
local_param->samples_buffer[local_param->absolute_position] * feedback
+ pw13_float_input_val (p->input);
pw13_float_output_val (p->output[0]) =
local_param->samples_buffer[local_param->absolute_position];
}
}
static int pw13_delay_start (Pw13_Patch *p, Pw13_Time *time)
{
time=time;
s_delay* start_param=malloc(sizeof(s_delay*));
start_param->nb_samples=pw13_float_input_val (p->input+1);
start_param->absolute_position=-1;
start_param->samples_buffer=NULL;
(p->param)=start_param;
return 1;
}
static void pw13_delay_stop (Pw13_Patch *p)
{
free(p->param);
}
PW13_EXPORT
int pw13_dl_patch_class_init (const char *name, Pw13_Patch *p, void *param)
{
param = param;
pw13_patch_init(name, p, 3, 1);
pw13_float_input("Sample Input", p->input, p, 0);
pw13_int_input("Delay", p->input+1, p, 1000);
pw13_float_input("Feedback", p->input+2, p, 0.5);
pw13_float_output("Sample Output", p->output, p);
p->pump = pw13_delay_pump;
p->start = pw13_delay_start;
p->stop = pw13_delay_stop;
return 1;
}