/* DO NOT EDIT THIS FILE - it is machine generated (JCGO_116) */

#ifdef JCGO_SEPARATED
#define JCGO_116
#include "jcgortl.h"
#include "Main.h"
#endif

#ifdef JCGO_116

#ifdef CHKALL_StreamAudioPlayer
#include "jcgobchk.h"
#endif

#define    SIGN_BIT        (0x80)   /* Sign bit for a A-law byte.        */
#define    QUANT_MASK      (0xf)    /* Quantization field mask.          */
#define    SEG_SHIFT       (4)      /* Left shift for segment number.    */
#define    SEG_MASK        (0x70)   /* Segment field mask.               */
#define    BIAS            (0x84)   /* Bias for linear code (for u-law). */

int ulaw2linear(long size, unsigned char *u_ptr, short *out_ptr) {
 short t;
 unsigned char u_val;

 for (long i=0; i< size; i++) {
  u_val = ~(*u_ptr);
  u_ptr++;
  t = ((u_val & QUANT_MASK) << 3) + BIAS;
  t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
  *out_ptr++ = ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
 }

 return 0;
}

JCGO_NOSEP_FRWINL void CFASTCALL
package_StreamAudioPlayer__stopPlayer__( package_StreamAudioPlayer
 This )
{
 {
  SDL_PauseAudio(1);
 }
}

JCGO_NOSEP_FRWINL void CFASTCALL
package_StreamAudioPlayer__writeStream__BAII( package_StreamAudioPlayer
 This, jbyteArr buff, jint off, jint len )
{
 JCGO_SYNC_BLOCKSAFENZ(This)
 {
  unsigned char ulaw[len];

  for (int i = 0; i < len; i += 1) {
   ulaw[i] = JCGO_ARRAY_BACCESS(buff, i + off);
  }

  ulaw2linear(len, ulaw, pcm_out);
  SDL_QueueAudio(1, pcm_out, len * 2);
 }
 JCGO_SYNC_END
}

JCGO_NOSEP_STATIC package_StreamAudioPlayer CFASTCALL
package_StreamAudioPlayer__this__( package_StreamAudioPlayer This
 )
{
 {
  ;
 }
 return This;
}

JCGO_NOSEP_FRWINL package_StreamAudioPlayer CFASTCALL
package_StreamAudioPlayer__new__( void )
{
 return package_StreamAudioPlayer__this__(
  (package_StreamAudioPlayer)jcgo_newObject((jvtable)&package_StreamAudioPlayer_methods));
}

JCGO_NOSEP_DATA CONST struct package_StreamAudioPlayer_methods_s package_StreamAudioPlayer_methods=
{
 JCGO_CLASSREF_OF(package_StreamAudioPlayer__class),
 JCGO_GCJDESCR_ZEROINIT
 OBJT_package_StreamAudioPlayer,
 -(JCGO_OBJSIZE_T)sizeof(struct package_StreamAudioPlayer_s),
 NULL,
 JCGO_CLINIT_INIT(0)
 package_StreamAudioPlayer__this__,
 java_lang_Object__equals__Lo,
 java_lang_Object__hashCode__,
 java_lang_Object__toString__,
 java_lang_Object__finalize__
};

JCGO_NOSEP_DATA JCGO_NOTHR_CONST struct package_StreamAudioPlayer_class_s
 package_StreamAudioPlayer__class JCGO_THRD_ATTRNONGC=
{
 {
  &java_lang_Class_methods,
  JCGO_MON_INIT
  JCGO_OBJREF_OF(*(java_lang_Object)&package_StreamAudioPlayer_methods),
  JCGO_STRREF_OF(jcgo_string1_StrmAdPl),
  JCGO_CLASSREF_OF(java_lang_Object__class),
  ((jObjectArr)JCGO_OBJREF_OF(jcgo_array3_Object)),
  0x1
 }
};

JCGO_NOSEP_DATA CONST jcgo_arrtype492_Mdclnt jcgo_array2_StrmAdPl=
{
 (jvtable)&jbyteArr_methods,
 JCGO_MON_INIT
 17,
 {
  (jbyte)(jchar)83/*'S'*/, (jbyte)(jchar)116/*'t'*/, (jbyte)(jchar)114/*'r'*/,
   (jbyte)(jchar)101/*'e'*/, (jbyte)(jchar)97/*'a'*/, (jbyte)(jchar)109/*'m'*/,
   (jbyte)(jchar)65/*'A'*/, (jbyte)(jchar)117/*'u'*/, (jbyte)(jchar)100/*'d'*/,
   (jbyte)(jchar)105/*'i'*/, (jbyte)(jchar)111/*'o'*/, (jbyte)(jchar)80/*'P'*/,
   (jbyte)(jchar)108/*'l'*/, (jbyte)(jchar)97/*'a'*/, (jbyte)(jchar)121/*'y'*/,
   (jbyte)(jchar)101/*'e'*/, (jbyte)(jchar)114/*'r'*/
 }
};

JCGO_NOSEP_DATA JCGO_NOTHR_CONST struct java_lang_String_s jcgo_string1_StrmAdPl
 JCGO_THRD_ATTRNONGC=
{
 &java_lang_String_methods,
 JCGO_MON_INIT
 (java_lang_Object)JCGO_OBJREF_OF(jcgo_array2_StrmAdPl),
 0, 17, (jint)0x9bda5297L
};

#ifdef CHKALL_StreamAudioPlayer
#include "jcgochke.h"
#endif

#endif
