@@ -994,17 +994,13 @@ static void sbc_set_defaults(sbc_t *sbc, unsigned long flags)
{
struct sbc_priv *priv = sbc->priv;
- if (priv->msbc) {
- priv->pack_frame = msbc_pack_frame;
- priv->unpack_frame = msbc_unpack_frame;
- } else {
- priv->pack_frame = sbc_pack_frame;
- priv->unpack_frame = sbc_unpack_frame;
- }
+ priv->pack_frame = sbc_pack_frame;
+ priv->unpack_frame = sbc_unpack_frame;
sbc->flags = flags;
sbc->frequency = SBC_FREQ_44100;
sbc->mode = SBC_MODE_STEREO;
+ sbc->allocation = SBC_AM_LOUDNESS;
sbc->subbands = SBC_SB_8;
sbc->blocks = SBC_BLK_16;
sbc->bitpool = 32;
@@ -1017,6 +1013,30 @@ static void sbc_set_defaults(sbc_t *sbc, unsigned long flags)
#endif
}
+static void sbc_set_defaults_msbc(sbc_t *sbc, unsigned long flags)
+{
+ struct sbc_priv *priv = sbc->priv;
+
+ priv->msbc = true;
+ priv->pack_frame = msbc_pack_frame;
+ priv->unpack_frame = msbc_unpack_frame;
+
+ sbc->flags = flags;
+ sbc->frequency = SBC_FREQ_16000;
+ sbc->mode = SBC_MODE_MONO;
+ sbc->allocation = SBC_AM_LOUDNESS;
+ sbc->subbands = SBC_SB_8;
+ sbc->blocks = MSBC_BLOCKS;
+ sbc->bitpool = 26;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ sbc->endian = SBC_LE;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ sbc->endian = SBC_BE;
+#else
+#error "Unknown byte order"
+#endif
+}
+
SBC_EXPORT int sbc_init(sbc_t *sbc, unsigned long flags)
{
if (!sbc)
@@ -1040,33 +1060,13 @@ SBC_EXPORT int sbc_init(sbc_t *sbc, unsigned long flags)
SBC_EXPORT int sbc_init_msbc(sbc_t *sbc, unsigned long flags)
{
- struct sbc_priv *priv;
-
- if (!sbc)
- return -EIO;
-
- memset(sbc, 0, sizeof(sbc_t));
-
- sbc->priv_alloc_base = malloc(sizeof(struct sbc_priv) + SBC_ALIGN_MASK);
- if (!sbc->priv_alloc_base)
- return -ENOMEM;
-
- sbc->priv = (void *) (((uintptr_t) sbc->priv_alloc_base +
- SBC_ALIGN_MASK) & ~((uintptr_t) SBC_ALIGN_MASK));
-
- memset(sbc->priv, 0, sizeof(struct sbc_priv));
-
- priv = sbc->priv;
- priv->msbc = true;
+ int err;
- sbc_set_defaults(sbc, flags);
+ err = sbc_init(sbc, flags);
+ if (err < 0)
+ return err;
- sbc->frequency = SBC_FREQ_16000;
- sbc->blocks = MSBC_BLOCKS;
- sbc->subbands = SBC_SB_8;
- sbc->mode = SBC_MODE_MONO;
- sbc->allocation = SBC_AM_LOUDNESS;
- sbc->bitpool = 26;
+ sbc_set_defaults_msbc(sbc, flags);
return 0;
}
@@ -1079,12 +1079,7 @@ SBC_EXPORT int sbc_reinit_msbc(sbc_t *sbc, unsigned long flags)
if (err < 0)
return err;
- sbc->frequency = SBC_FREQ_16000;
- sbc->blocks = MSBC_BLOCKS;
- sbc->subbands = SBC_SB_8;
- sbc->mode = SBC_MODE_MONO;
- sbc->allocation = SBC_AM_LOUDNESS;
- sbc->bitpool = 26;
+ sbc_set_defaults_msbc(sbc, flags);
return 0;
}