Skip to content

Commit

Permalink
Adapt to new shine API
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jul 26, 2014
1 parent dbc7eaf commit da5b690
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGES
@@ -1,6 +1,6 @@
0.2.0 ()
=====
* Updated to shine 3.0.0
* Updated to shine 3.1.0

0.1.1 (2013-04-15)
=====
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
@@ -1,6 +1,6 @@

# check for one particular file of the sources
AC_INIT([ocaml-shine],[0.2.0],[savonet-users@lists.sourceforge.net])
AC_INIT([ocaml-shine],[0.2.1],[savonet-users@lists.sourceforge.net])

VERSION=$PACKAGE_VERSION
AC_MSG_RESULT([configuring $PACKAGE_STRING])
Expand All @@ -13,7 +13,7 @@ AC_C_BIGENDIAN(AC_DEFINE([BIGENDIAN], [1], [The target is big endian]),[])
AC_BASE_CHECKS()

PKG_PROG_PKG_CONFIG()
PKG_CONFIG_CHECK_MODULE([shine],[3.0.0])
PKG_CONFIG_CHECK_MODULE([shine],[3.1.0])

# substitutions to perform
AC_SUBST(VERSION)
Expand Down
41 changes: 21 additions & 20 deletions src/shine_stubs.c
Expand Up @@ -110,16 +110,14 @@ static inline int16_t clip(double s)
return (s * INT16_MAX);
}

static inline int16_t bswap_16 (int16_t x) { return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); }

CAMLprim value ocaml_shine_encode_float(value e, value data)
{
CAMLparam2(e,data);
CAMLlocal2(src,ret);
int16_t *pcm[2];
int16_t chan1[SHINE_MAX_SAMPLES], chan2[SHINE_MAX_SAMPLES];
int c,i;
long written;
int written;
unsigned char *outdata;

shine_t enc = Encoder_val(e);
Expand All @@ -146,36 +144,39 @@ CAMLprim value ocaml_shine_encode_float(value e, value data)
CAMLreturn(ret);
}

#ifdef BIGENDIAN
static inline int16_t bswap_16 (int16_t x) { return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); }

void swap_buffer(int16_t *sample_buffer, int length)
{
int i;
for (i=0; i<length; i++)
sample_buffer[i] = bswap_16(sample_buffer[i]);
}
#endif

CAMLprim value ocaml_shine_encode_s16le(value e, value data, value channels)
{
CAMLparam2(e,data);
CAMLlocal1(ret);
int16_t *pcm[2];
int16_t chan1[SHINE_MAX_SAMPLES], chan2[SHINE_MAX_SAMPLES];
int16_t pcm[2*SHINE_MAX_SAMPLES];
int16_t *src = (int16_t *)String_val(data);
int c,i;
long written;
int written;
int chans = Int_val(channels);

unsigned char *outdata;

shine_t enc = Encoder_val(e);
pcm[0] = chan1; pcm[1] = chan2;

for (c = 0; c < chans; c++)
{
for (i = 0; i < shine_samples_per_pass(enc); i++)
{
pcm[c][i] = src[i*chans + c];
#ifdef BIGENDIAN
pcm[c][i] = bswap_16(pcm[c][i]);
#endif
}
}
memcpy(pcm, src, chans*shine_samples_per_pass(enc)*sizeof(int16_t));

caml_enter_blocking_section();

outdata = shine_encode_buffer(enc, pcm, &written);
#ifdef BIGENDIAN
swap_buffer(pcm, chans*shine_samples_per_pass(enc));
#endif

outdata = shine_encode_buffer_interleaved(enc, pcm, &written);

caml_leave_blocking_section();

Expand All @@ -190,7 +191,7 @@ CAMLprim value ocaml_shine_flush(value e)
CAMLparam1(e);
CAMLlocal1(ret);

long written;
int written;
unsigned char *outdata;
shine_t enc = Encoder_val(e);

Expand Down

0 comments on commit da5b690

Please sign in to comment.