Author: ayoung
Date: Mon Jun  7 06:31:01 2010
New Revision: 8845

URL: http://svn.slimdevices.com/jive?rev=8845&view=rev
Log:
bug 16288: Squeezeplay-based testing client 
Null audio backend.

Added:
    7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_null.c   
(with props)
Modified:
    7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode.c
    7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_mad.c
    7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_priv.h

Modified: 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode.c
URL: 
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode.c?rev=8845&r1=8844&r2=8845&view=diff
==============================================================================
--- 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode.c (original)
+++ 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode.c Mon Jun  7 
06:31:01 2010
@@ -1002,6 +1002,9 @@
        if (!f) {
                f = &decode_portaudio;
        }
+#endif
+#ifdef HAVE_NULLAUDIO
+       f = &decode_null;
 #endif
        if (!f) {
                /* no audio support */

Modified: 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_mad.c
URL: 
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_mad.c?rev=8845&r1=8844&r2=8845&view=diff
==============================================================================
--- 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_mad.c 
(original)
+++ 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_mad.c Mon Jun 
 7 06:31:01 2010
@@ -212,6 +212,31 @@
 }
 
 
+#ifdef HAVE_NULLAUDIO
+/*
+ * NAME:       synth->frame()
+ * DESCRIPTION:        perform PCM synthesis of frame subband samples
+ */
+void null_synth_frame(struct mad_synth *synth, struct mad_frame const *frame)
+{
+  unsigned int nch, ns;
+
+  nch = MAD_NCHANNELS(&frame->header);
+  ns  = MAD_NSBSAMPLES(&frame->header);
+
+  synth->pcm.samplerate = frame->header.samplerate;
+  synth->pcm.channels   = nch;
+  synth->pcm.length     = 32 * ns;
+
+  if (frame->options & MAD_OPTION_HALFSAMPLERATE) {
+    synth->pcm.samplerate /= 2;
+    synth->pcm.length     /= 2;
+
+  }
+}
+#endif
+
+
 static void decode_mad_frame(struct decode_mad *self) {
        size_t read_max, read_num, remaining;
        u8_t *read_start;
@@ -303,7 +328,11 @@
                        }
                }
 
+#ifdef HAVE_NULLAUDIO
+               null_synth_frame(&self->synth, &self->frame);
+#else
                mad_synth_frame(&self->synth, &self->frame);
+#endif
 
                /* pcm is now ready  */
                self->state = MAD_STATE_PCM_READY;

Added: 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_null.c
URL: 
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_null.c?rev=8845&view=auto
==============================================================================
--- 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_null.c (added)
+++ 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_null.c Mon 
Jun  7 06:31:01 2010
@@ -1,0 +1,221 @@
+/*
+** Copyright 2007-2008 Logitech. All Rights Reserved.
+**
+** This file is licensed under BSD. Please see the LICENSE file for details.
+*/
+
+#include "common.h"
+
+#include "audio/fifo.h"
+#include "audio/mqueue.h"
+#include "audio/decode/decode.h"
+#include "audio/decode/decode_priv.h"
+
+
+#ifdef HAVE_NULLAUDIO
+
+/* Stream sample rate */
+static u32_t stream_sample_rate;
+
+
+/*
+ * This function is called by timer when the stream is active to request
+ * audio samples
+ */
+static Uint32 callback(Uint32 interval) {
+       size_t bytes_used, len, skip_bytes = 0, add_bytes = 0;
+       int add_silence_ms;
+       bool_t reached_start_point;
+       u32_t delay;
+
+       if ((decode_audio->state & (DECODE_STATE_AUTOSTART | 
DECODE_STATE_RUNNING)) == 0) {
+//             LOG_DEBUG(log_audio_output, "Not running");
+               return interval;
+       }
+
+       decode_audio_lock();
+
+       stream_sample_rate = decode_audio->set_sample_rate;
+       len = SAMPLES_TO_BYTES(stream_sample_rate * interval / 1000);
+
+       bytes_used = fifo_bytes_used(&decode_audio->fifo);
+
+       /* Should we start the audio now based on having enough decoded data? */
+       if (decode_audio->state & DECODE_STATE_AUTOSTART
+                       && bytes_used >=  len
+                       && bytes_used >= 
SAMPLES_TO_BYTES((u32_t)((decode_audio->output_threshold * stream_sample_rate) 
/ 10))
+               )
+       {
+               decode_audio->state &= ~DECODE_STATE_AUTOSTART;
+               decode_audio->state |= DECODE_STATE_RUNNING;
+       }
+
+       /* audio running? */
+       if (!(decode_audio->state & DECODE_STATE_RUNNING)) {
+//             LOG_DEBUG(log_audio_output, "Not yet running");
+               /* mix in sound effects */
+               goto mixin_effects;
+       }
+
+//     LOG_DEBUG(log_audio_output, "Running");
+
+       /* sync accurate playpoint */
+       decode_audio->sync_elapsed_samples = decode_audio->elapsed_samples;
+       delay = 0;
+
+       if (decode_audio->sync_elapsed_samples > delay) {
+               decode_audio->sync_elapsed_samples -= delay;
+       }
+       decode_audio->sync_elapsed_timestamp = jive_jiffies();
+
+       add_silence_ms = decode_audio->add_silence_ms;
+       if (add_silence_ms) {
+               add_bytes = SAMPLES_TO_BYTES((u32_t)((add_silence_ms * 
stream_sample_rate) / 1000));
+               if (add_bytes > len) add_bytes = len;
+               len -= add_bytes;
+               add_silence_ms -= (BYTES_TO_SAMPLES(add_bytes) * 1000) / 
stream_sample_rate;
+               if (add_silence_ms < 2)
+                       add_silence_ms = 0;
+
+               decode_audio->add_silence_ms = add_silence_ms;
+
+               if (!len) {
+                       goto mixin_effects;
+               }
+       }
+
+       /* only skip if it will not cause an underrun */
+       if (bytes_used >= len && decode_audio->skip_ahead_bytes > 0) {
+               skip_bytes = bytes_used - len;
+               if (skip_bytes > decode_audio->skip_ahead_bytes) {
+                       skip_bytes = decode_audio->skip_ahead_bytes;            
        
+               }
+       }
+
+       if (bytes_used > len) {
+               bytes_used = len;
+       }
+
+       /* audio underrun? */
+       if (bytes_used == 0) {
+               decode_audio->state |= DECODE_STATE_UNDERRUN;
+
+               goto mixin_effects;
+       }
+
+       if (bytes_used < len) {
+               decode_audio->state |= DECODE_STATE_UNDERRUN;
+       }
+       else {
+               decode_audio->state &= ~DECODE_STATE_UNDERRUN;
+       }
+
+       if (skip_bytes) {
+               size_t wrap;
+
+               LOG_DEBUG(log_audio_output, "Skipping %d bytes", (int) 
skip_bytes);
+               
+               wrap = fifo_bytes_until_rptr_wrap(&decode_audio->fifo);
+
+               if (wrap < skip_bytes) {
+                       fifo_rptr_incby(&decode_audio->fifo, wrap);
+                       skip_bytes -= wrap;
+                       decode_audio->skip_ahead_bytes -= wrap;
+                       decode_audio->elapsed_samples += BYTES_TO_SAMPLES(wrap);
+               }
+
+               fifo_rptr_incby(&decode_audio->fifo, skip_bytes);
+               decode_audio->skip_ahead_bytes -= skip_bytes;
+               decode_audio->elapsed_samples += BYTES_TO_SAMPLES(skip_bytes);
+       }
+
+       while (bytes_used) {
+               size_t wrap, bytes_write;
+
+               wrap = fifo_bytes_until_rptr_wrap(&decode_audio->fifo);
+
+               bytes_write = bytes_used;
+               if (wrap < bytes_write) {
+                       bytes_write = wrap;
+               }
+
+               fifo_rptr_incby(&decode_audio->fifo, bytes_write);
+               decode_audio->elapsed_samples += BYTES_TO_SAMPLES(bytes_write);
+
+               bytes_used -= bytes_write;
+       }
+
+       reached_start_point = decode_check_start_point();
+       if (reached_start_point && decode_audio->track_sample_rate != 
stream_sample_rate) {
+               decode_audio->set_sample_rate = decode_audio->track_sample_rate;
+       }
+
+ mixin_effects:
+       /* mix in sound effects */
+       /* don't */
+
+       decode_audio_unlock();
+
+       return interval;
+}
+
+static void decode_null_start(void) {
+       LOG_DEBUG(log_audio_output, "decode_null_start");
+
+       ASSERT_AUDIO_LOCKED();
+
+       decode_audio->set_sample_rate = decode_audio->track_sample_rate;
+}
+
+static void decode_null_pause(void) {
+       ASSERT_AUDIO_LOCKED();
+}
+
+static void decode_null_resume(void) {
+       ASSERT_AUDIO_LOCKED();
+}
+
+static void decode_null_stop(void) {
+       LOG_DEBUG(log_audio_output, "decode_null_stop");
+
+       ASSERT_AUDIO_LOCKED();
+
+       stream_sample_rate = decode_audio->set_sample_rate = 44100;
+}
+
+
+static int decode_null_init(lua_State *L) {
+       void *buf;
+
+       /* allocate output memory */
+       buf = malloc(DECODE_AUDIO_BUFFER_SIZE);
+       if (!buf) {
+               LOG_WARN(log_audio_output, "Cannot allocate output buffer");
+               return 0;
+       }
+
+       decode_init_buffers(buf, false);
+       decode_audio->max_rate = 48000;
+
+       stream_sample_rate = decode_audio->set_sample_rate = 44100;
+
+       /* XXX set up timer to call callback reqularly */
+       /* only need callback to run while actually playing */
+       if (SDL_SetTimer(100, callback) != 0) {
+               LOG_WARN(log_audio_output, "Cannot start callback timer");
+               return 0;
+       }
+
+       return 1;
+}
+
+
+struct decode_audio_func decode_null = {
+       decode_null_init,
+       decode_null_start,
+       decode_null_pause,
+       decode_null_resume,
+       decode_null_stop,
+};
+
+#endif // HAVE_NULLAUDIO

Propchange: 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_null.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_priv.h
URL: 
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_priv.h?rev=8845&r1=8844&r2=8845&view=diff
==============================================================================
--- 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_priv.h 
(original)
+++ 7.6/trunk/squeezeplay/src/squeezeplay/src/audio/decode/decode_priv.h Mon 
Jun  7 06:31:01 2010
@@ -175,7 +175,7 @@
 /* Audio output backends */
 extern struct decode_audio_func decode_alsa;
 extern struct decode_audio_func decode_portaudio;
-
+extern struct decode_audio_func decode_null;
 
 /* Decode output api */
 extern void decode_init_buffers(void *buf, bool_t prio_inherit);

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/jive-checkins

Reply via email to