Skip to content

Commit

Permalink
lib: Add libtremor support
Browse files Browse the repository at this point in the history
For faster decoding on integer-only machines.
  • Loading branch information
SimonKagstrom committed Mar 18, 2011
1 parent 1c8b1eb commit a315b12
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export

CFLAGS = -Wall -Wextra -ggdb -std=gnu99
LDFLAGS = -lz -lvorbisfile
LDFLAGS = -lz

LD = $(CC)

Expand All @@ -26,6 +26,13 @@ ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG
endif

ifeq ($(USE_TREMOR), 1)
CFLAGS += -DUSE_TREMOR=1
LDFLAGS += -lvorbisidec
else
LDFLAGS += -lvorbisfile
endif

# Mac OS X specifics
ifeq ($(shell uname -s),Darwin)
LT = glibtool --tag=CC
Expand Down
4 changes: 4 additions & 0 deletions src/Makefile.local.mk.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ CLIENT_DESPOTIFY = 1
CLIENT_GATEWAY = 1
# CLIENT_MAEMIFY = 1

## Enable libtremor, the integer-only OGG Vorbis decoder
# USE_TREMOR = 1


## Enable Nokia Maemo4 specific code in maemify client.
## At least LINUX_BACKEND = gstreamer seems to work with this.
# MAEMO4 = 1
Expand Down
30 changes: 26 additions & 4 deletions src/lib/sndqueue.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id$
* $Id: sndqueue.c 485 2010-01-14 08:33:24Z jorgenpt $
*
*/

Expand Down Expand Up @@ -442,6 +442,15 @@ size_t snd_ov_read_callback(void *ptr, size_t size, size_t nmemb, void* session)
return totlength;
}

int seek_func (void *session, ogg_int64_t offset, int whence)
{
(void)session;
(void)offset;
(void)whence;

return -1;
}

int snd_get_pcm(struct despotify_session* ds, struct pcm_data* pcm)
{
if (!ds || !ds->fifo || !ds->fifo->start) {
Expand All @@ -464,7 +473,7 @@ int snd_get_pcm(struct despotify_session* ds, struct pcm_data* pcm)
/* Initialize Vorbis struct with the appropriate callbacks */
ov_callbacks callbacks;
callbacks.read_func = snd_ov_read_callback;
callbacks.seek_func = NULL;
callbacks.seek_func = seek_func;
callbacks.close_func = NULL;
callbacks.tell_func = NULL;

Expand All @@ -490,8 +499,15 @@ int snd_get_pcm(struct despotify_session* ds, struct pcm_data* pcm)

while (1) {
/* decode to pcm */
ssize_t r = ov_read(ds->vf, pcm->buf, sizeof(pcm->buf),
SYSTEM_ENDIAN, 2, 1, NULL);
ssize_t r;

#if defined(USE_TREMOR)
r = ov_read(ds->vf, pcm->buf, sizeof(pcm->buf),
NULL);
#else
r = ov_read(ds->vf, pcm->buf, sizeof(pcm->buf),
SYSTEM_ENDIAN, 2, 1, NULL);
#endif

/* assume no valid data read. */
pcm->len = 0;
Expand All @@ -518,7 +534,13 @@ int snd_get_pcm(struct despotify_session* ds, struct pcm_data* pcm)
pcm->len = r;

if (ds->client_callback) {
#if defined(USE_TREMOR)
ogg_int64_t int_point = ov_time_tell(ds->vf);
double point = ((double)int_point) / 1000.0;
#else
double point = ov_time_tell(ds->vf);
#endif

ds->client_callback(ds, DESPOTIFY_TIME_TELL, &point,
ds->client_callback_data);
}
Expand Down
8 changes: 6 additions & 2 deletions src/lib/sndqueue.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/*
* $Id$
* $Id: sndqueue.h 476 2009-12-01 13:54:42Z zagor $
*
*/

#ifndef DESPOTIFY_SNDQUEUE_H
#define DESPOTIFY_SNDQUEUE_H

#include <pthread.h>
#include <vorbis/vorbisfile.h>
#if defined(USE_TREMOR)
# include <tremor/ivorbisfile.h>
#else
# include <vorbis/vorbisfile.h>
#endif

#include "despotify.h"

Expand Down

0 comments on commit a315b12

Please sign in to comment.