/*
    GDAM - Geoff & Dave's Audio Mixer
    Copyright (C) 1999    Dave Benson, Geoff Matters.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

    Contact:
        daveb@ffem.org <Dave Benson>
        geoff@ugcs.caltech.edu <Geoff Matters>
*/
#ifndef __GDAS_ECHO_H_
#define __GDAS_ECHO_H_

typedef struct _GdasEcho GdasEcho;
typedef struct _GdasEchoClass GdasEchoClass;
typedef struct _GdasEchoElement GdasEchoElement;

#include "gdasfilter.h"

GtkType gdas_echo_get_type();
#define GDAS_TYPE_ECHO   gdas_echo_get_type()
#define GDAS_ECHO(ptr) ((GdasEcho*) gtk_type_check_object_cast ((GtkTypeObject*) (ptr), GDAS_TYPE_ECHO))

struct _GdasEchoElement {
	int			delay;
	GdamFixed		volume;
};
struct _GdasEchoClass {
	GdasFilterClass		filter_class;
        void                  (*add_echo)(GdamSample   *dest,
                                          const GdamSample *src,
                                          int           num_samples,
					  GdamFixed	scale);
};

struct _GdasEcho {
	GdasFilter		filter;
	int		   	num_echoes;
	GdasEchoElement*	echoes;
	int			past_buf_length;
	int			past_buf_next_output;
	GdamSample*		past_buf;
	gboolean                reverb;

	/* Gain to copy underlying through to the output buffer
	 * without copying to the past-echo buffer.
	 * (for `reverb' mostly) */
	GdamFixed		passthrough_volume;
	/* Gain to reduce the output from the past-echo buffer without
	 * changing the echo / feedback gain */
	GdamFixed		wet_volume;

	/* Used to fade when transitioning from echo to echo,
	 * to smooth out clipping pops. */
	int			fade_window;
	int			fade_time;
	int		   	old_num_echoes;
	GdasEchoElement*	old_echoes;

	/* Largest delay of any echo. */
	int			max_delay;
	/* Used during _read(), allocated once. */
	GdamSample*		recent_past_buf;
	guint			recent_past_buf_size;
};

void        gdas_echo_set_echoes       (GdasEcho        *echo,
                                        int              num_echoes,
                                        GdasEchoElement *echoes);

#endif
