'/* A simple frontend for libxmp using fixed-size buffers */
'/* This file is in public domain */

#include "crt.bi"
#Include "xmp.bi"
#include "sound.bi"


#define BUFFER_SIZE 5000
dim Shared buffer(BUFFER_SIZE) As string


	Dim As xmp_context ctx
	Dim As xmp_module_info mi
	Dim As integer i
	Dim argv As ZString Ptr Ptr = __FB_ARGV__

	if (sound_init(44100, 2) < 0) Then
		fprintf(stderr, !"%s: can't initialize sound\n", Command(0))
		End		
	EndIf


	ctx = xmp_create_context()

	for i As Integer = 1 To __FB_ARGC__ - 1 
		if xmp_load_module(ctx, *argv[i]) < 0 then
			fprintf(stderr, !"%s: error loading %s\n", Command(0),_
				*argv[i])
			Continue For
		EndIf

		if xmp_start_player(ctx, 44100, 0) = 0 then

			'/* Show module data */

			xmp_get_module_info(ctx, @mi)
			printf(!"%s (%s)\n", mi.mod_->name, mi.mod_->type)

			'/* Play module */

			while xmp_play_buffer(ctx, @buffer(0), BUFFER_SIZE, 1) = 0 
				sound_play(@buffer(0), BUFFER_SIZE)
			Wend
			xmp_end_player(ctx)
		EndIf

		xmp_release_module(ctx)
	Next

	xmp_free_context(ctx)

	sound_deinit()

