/* sound effect gimmick player - blather (output) routine */

#include <exec/types.h>
#include <functions.h>
#include <exec/memory.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <stdio.h>
#include <fcntl.h>

#include "assert.h"

#include "iff.h"
#include "8svx.h"

#include "sample.h"
#include "chatter.h"

extern int timer_noload;

extern  struct gab_info gab_data[N_GAB_TYPES];

blather(gab_type)
int gab_type;
{
	struct gab_info *gabp;
	int nitems;
	Sample *sampleptr;

	/* if it's a timer event and they've specified deferred loading
	 * of samples for timer events, play a deferred sound.  
	 */
	if ((gab_type == GAB_EVERY_SO_OFTEN) && (timer_noload))
	{
		PlayDeferredSound();
		return;
	}

	/* otherwise play a loaded sound */

	gabp = &gab_data[gab_type];

	nitems = gabp->n_gab_items;

	if (nitems == 0)
		return;

	sampleptr = gabp->Samples[gabp->next_play_gab_item++];

	ASSERT_SAMPLE_MAGIC(sampleptr);

	PlayChannelSample(sampleptr,64,rando(2));

	if (gabp->next_play_gab_item >= gabp->n_gab_items)
		rerandomize(gab_type);
}
