drv_gst.c 1.56 KB
Newer Older
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
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
#include <stdlib.h>

#include "gstmikmod.h"

static int buffer_size;
static SBYTE *audiobuffer = NULL;
extern int need_sync;

static BOOL mikmod_IsThere( void )
{
  return 1;
}

static BOOL mikmod_Init( void )
{
  buffer_size = 32768;
  if (!( audiobuffer = ( SBYTE * ) g_malloc( buffer_size ) ))
    return 1;
    
  return VC_Init();
}

static void mikmod_Exit( void )
{
  VC_Exit();

  if ( audiobuffer )
  {
    g_free(audiobuffer);
    audiobuffer = NULL;
  }	
}


static void mikmod_Update( void )
{
Wim Taymans's avatar
Wim Taymans committed
37 38
  gint length;
  GstBuffer *outdata;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
39 40 41 42

  length = VC_WriteBytes((SBYTE *) audiobuffer, buffer_size);
  	
  outdata = gst_buffer_new();
Jeremy Simon's avatar
Jeremy Simon committed
43

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
44 45 46
  GST_BUFFER_DATA( outdata ) = g_memdup( audiobuffer, length );
  GST_BUFFER_SIZE( outdata ) = length;

Jeremy Simon's avatar
Jeremy Simon committed
47 48
  GST_BUFFER_TIMESTAMP( outdata ) = timestamp;

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
49 50
  if ( need_sync == 1 )
  {
Wim Taymans's avatar
Wim Taymans committed
51
    /* FIXME, send a flush event or something */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
52 53
    need_sync = 0 ;
  }
54
  gst_pad_push( srcpad, GST_DATA (outdata ));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
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
      
}

static BOOL mikmod_Reset( void )
{
  VC_Exit();
  return VC_Init();
}


MDRIVER drv_gst =
{
	NULL,
	"mikmod",
	"mikmod output driver v1.0",
	0, 255,
#if (LIBMIKMOD_VERSION > 0x030106)
        "mikmod",
        NULL,
#endif
        mikmod_IsThere, 
	VC_SampleLoad,
	VC_SampleUnload,
	VC_SampleSpace,
	VC_SampleLength,
	mikmod_Init,
	mikmod_Exit,
	mikmod_Reset,
	VC_SetNumVoices,
	VC_PlayStart,
	VC_PlayStop,
	mikmod_Update,
	NULL,
	VC_VoiceSetVolume,
	VC_VoiceGetVolume,
	VC_VoiceSetFrequency,
	VC_VoiceGetFrequency,
	VC_VoiceSetPanning,
	VC_VoiceGetPanning,
	VC_VoicePlay,
	VC_VoiceStop,
	VC_VoiceStopped,
	VC_VoiceGetPosition,
	VC_VoiceRealVolume
};