bin/gcut: use mrg pcm api

Rather than carrying duplicates of sdl-1.2 pcm output.
parent babe834d
......@@ -42,15 +42,12 @@ gegl_SOURCES = \
if HAVE_MRG
if HAVE_GEXIV2
if HAVE_SDL
gegl_SOURCES += ui.c mrg-gegl.c
AM_CFLAGS += $(SDL_CFLAGS)
AM_LDFLAGS += $(SDL_LIBS)
endif
endif
endif
if HAVE_SPIRO
gegl_SOURCES += gegl-path-spiro.h gegl-path-spiro.c
endif
......@@ -39,7 +39,6 @@
#include <gegl.h>
#include <gexiv2/gexiv2.h>
#include <gegl-paramspecs.h>
#include <SDL.h>
#include <gegl-audio-fragment.h>
/* set this to 1 to print the active gegl chain
......@@ -55,45 +54,8 @@ void mrg_gegl_blit (Mrg *mrg,
float preview_multiplier);
static int audio_len = 0;
static int audio_pos = 0;
static int audio_post = 0;
//static int audio_start = 0; /* which sample no is at the start of our circular buffer */
#define AUDIO_BUF_LEN 819200000
int16_t audio_data[AUDIO_BUF_LEN];
static void sdl_audio_cb(void *udata, Uint8 *stream, int len)
{
int audio_remaining = audio_len - audio_pos;
if (audio_remaining < 0)
return;
if (audio_remaining < len) len = audio_remaining;
//SDL_MixAudio(stream, (uint8_t*)&audio_data[audio_pos/2], len, SDL_MIX_MAXVOLUME);
memcpy (stream, (uint8_t*)&audio_data[audio_pos/2], len);
audio_pos += len;
audio_post += len;
if (audio_pos >= AUDIO_BUF_LEN)
{
audio_pos = 0;
}
}
static void sdl_add_audio_sample (int sample_pos, float left, float right)
{
audio_data[audio_len/2 + 0] = left * 32767.0 * 0.46;
audio_data[audio_len/2 + 1] = right * 32767.0 * 0.46;
audio_len += 4;
if (audio_len >= AUDIO_BUF_LEN)
{
audio_len = 0;
}
}
static int audio_started = 0;
/* this structure contains the full application state, and is what
......@@ -294,25 +256,10 @@ static State *hack_state = NULL; // XXX: this shoudl be factored away
char **ops = NULL;
static void open_audio (int frequency)
static void open_audio (Mrg *mrg, int frequency)
{
SDL_AudioSpec spec = {0};
SDL_Init(SDL_INIT_AUDIO);
spec.freq = frequency;
spec.format = AUDIO_S16SYS;
spec.channels = 2;
spec.samples = 1024;
spec.callback = sdl_audio_cb;
SDL_OpenAudio(&spec, 0);
if (spec.format != AUDIO_S16SYS)
{
fprintf (stderr, "not getting format we wanted\n");
}
if (spec.freq != frequency)
{
fprintf (stderr, "not getting desires samplerate(%i) we wanted got %i instead\n", frequency, spec.freq);
}
mrg_pcm_set_sample_rate (mrg, frequency);
mrg_pcm_set_format (mrg, MRG_s16S);
}
static void end_audio (void)
......@@ -1024,6 +971,21 @@ static void toggle_slideshow_cb (MrgEvent *event, void *data1, void *data2)
mrg_queue_draw (o->mrg, NULL);
}
static int deferred_redraw_action (Mrg *mrg, void *data)
{
mrg_queue_draw (mrg, NULL);
return 0;
}
static void deferred_redraw (Mrg *mrg, MrgRectangle *rect)
{
MrgRectangle r; /* copy in call stack of dereference rectangle if pointer
is passed in */
if (rect)
r = *rect;
mrg_add_timeout (mrg, 0, deferred_redraw_action, rect?&r:NULL);
}
static void gegl_ui (Mrg *mrg, void *data)
{
State *o = data;
......@@ -1057,18 +1019,23 @@ static void gegl_ui (Mrg *mrg, void *data)
int i;
if (!audio_started)
{
open_audio (gegl_audio_fragment_get_sample_rate (audio));
SDL_PauseAudio(0);
open_audio (mrg, gegl_audio_fragment_get_sample_rate (audio));
audio_started = 1;
}
{
uint16_t temp_buf[sample_count * 2];
for (i = 0; i < sample_count; i++)
{
sdl_add_audio_sample (0, audio->data[0][i], audio->data[1][i]);
temp_buf[i*2] = audio->data[0][i] * 32767.0 * 0.46;
temp_buf[i*2+1] = audio->data[1][i] * 32767.0 * 0.46;
}
mrg_pcm_queue (mrg, (void*)&temp_buf[0], sample_count);
}
while (audio_len > audio_pos + 5000)
g_usleep (50);
while (mrg_pcm_get_queued (mrg) > 3000)
g_usleep (50);
o->prev_frame_played = o->frame_no;
deferred_redraw (mrg, NULL);
}
g_object_unref (audio);
}
......@@ -1607,6 +1574,7 @@ static void zoom_fit_cb (MrgEvent *e, void *data1, void *data2)
zoom_to_fit (data1);
}
static int deferred_zoom_to_fit (Mrg *mrg, void *data)
{
zoom_to_fit (data);
......
......@@ -52,9 +52,7 @@ gcut_SOURCES = \
clip.c
if HAVE_MRG
if HAVE_SDL
gcut_SOURCES += gcut-ui.c renderer.c
AM_CFLAGS += $(SDL_CFLAGS)
AM_LDFLAGS += $(SDL_LIBS)
endif
endif
......@@ -7,7 +7,6 @@
#include <gegl.h>
#include <mrg.h>
#include "gcut.h"
#include <SDL.h>
#include <gegl-audio-fragment.h>
static GThread *thread = NULL;
......@@ -16,13 +15,6 @@ static long prev_ticks = 0;
int rendering_frame = -1;
int done_frame = -1;
static int audio_started = 0;
static int audio_len = 0;
static int audio_pos = 0;
static int audio_post = 0;
#define AUDIO_BUF_LEN 819200000
int16_t audio_data[AUDIO_BUF_LEN];
void gcut_cache_invalid (GeglEDL *edl)
{
......@@ -31,56 +23,10 @@ void gcut_cache_invalid (GeglEDL *edl)
rendering_frame=-1;
}
static void sdl_audio_cb(void *udata, Uint8 *stream, int len)
{
int audio_remaining = audio_len - audio_pos;
if (audio_remaining < 0)
return;
if (audio_remaining < len) len = audio_remaining;
//SDL_MixAudio(stream, (uint8_t*)&audio_data[audio_pos/2], len, SDL_MIX_MAXVOLUME);
memcpy (stream, (uint8_t*)&audio_data[audio_pos/2], len);
audio_pos += len;
audio_post += len;
if (audio_pos >= AUDIO_BUF_LEN)
{
audio_pos = 0;
}
}
static void sdl_add_audio_sample (int sample_pos, float left, float right)
{
audio_data[audio_len/2 + 0] = left * 32767.0 * 0.46;
audio_data[audio_len/2 + 1] = right * 32767.0 * 0.46;
audio_len += 4;
if (audio_len >= AUDIO_BUF_LEN)
{
audio_len = 0;
}
}
static void open_audio (int frequency)
static void open_audio (Mrg *mrg, int frequency)
{
SDL_AudioSpec spec = {0};
SDL_Init(SDL_INIT_AUDIO);
spec.freq = frequency;
spec.format = AUDIO_S16SYS;
spec.channels = 2;
spec.samples = 1024;
spec.callback = sdl_audio_cb;
SDL_OpenAudio(&spec, 0);
if (spec.format != AUDIO_S16SYS)
{
fprintf (stderr, "not getting format we wanted\n");
}
if (spec.freq != frequency)
{
fprintf (stderr, "not getting desires samplerate(%i) we wanted got %i instead\n", frequency, spec.freq);
}
mrg_pcm_set_sample_rate (mrg, frequency);
mrg_pcm_set_format (mrg, MRG_s16S);
}
static void end_audio (void)
......@@ -138,13 +84,18 @@ static gpointer renderer_thread (gpointer data)
int i;
if (!audio_started)
{
open_audio (gegl_audio_fragment_get_sample_rate (audio));
SDL_PauseAudio(0);
open_audio (edl->mrg, gegl_audio_fragment_get_sample_rate (audio));
audio_started = 1;
}
for (i = 0; i < sample_count; i++)
{
sdl_add_audio_sample (0, audio->data[0][i], audio->data[1][i]);
uint16_t temp_buf[sample_count*2];
for (i = 0; i < sample_count; i++)
{
temp_buf[i*2] = audio->data[0][i] * 32767.0 * 0.46;
temp_buf[i*2+1] = audio->data[1][i] * 32767.0 * 0.46;
}
mrg_pcm_queue (edl->mrg, (void*)&temp_buf[0], sample_count);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment