From: Kaj-Michael Lang Date: Thu, 28 Feb 2008 16:59:17 +0000 (+0200) Subject: Set caps so we don't record @ 32-bit stereo 44100. Skip on tablets as they default... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3559a8a299881a1657595c9366ec8f6738ff84ce;p=mapper Set caps so we don't record @ 32-bit stereo 44100. Skip on tablets as they default to hw limit (8kHz). --- diff --git a/src/audio-note.c b/src/audio-note.c index b0c1830..4637052 100644 --- a/src/audio-note.c +++ b/src/audio-note.c @@ -23,34 +23,75 @@ */ #include "config.h" +#include #include #include +#include "ui-common.h" #include "audio.h" #include "audio-note.h" static note_pipeline note_play; static note_pipeline note_record; static GstBus *bus; +static gchar *cfile=NULL; static gboolean audio_note_record_cb(GtkWidget *widget, gpointer data) { -audio_note_record("/tmp/testing.wav"); +const gchar *basedir; +gchar buffer[128]; +audio_note_ui *ui=(audio_note_ui *)data; +GDate *gd; +time_t t; +struct tm *tmp; + +/* XXX: Make this a configuration option */ +#ifdef WITH_DEVICE_770 +basedir="/media/mmc1/MapperAudioNotes"; +if (g_mkdir_with_parents(basedir, 0775)==-1) { + MACRO_BANNER_SHOW_INFO(_window, _("Failed to create directory for sound files!")); + return TRUE; +} +#else +basedir=g_get_home_dir(); +#endif + +t=time(NULL); +tmp=localtime(&t); +if (tmp == NULL) { + MACRO_BANNER_SHOW_INFO(_window, _("Failed to get timestamp for file!")); + return TRUE; +} +strftime(buffer, sizeof(buffer), "%Y-%m-%d-%H:%M:%S", tmp); + +if (cfile) + g_free(cfile); + +cfile=g_strdup_printf("%s/an-%s.wav", basedir, buffer); + +audio_note_record(cfile); + +MACRO_BANNER_SHOW_INFO(_window, _("Recording...")); + return TRUE; } static gboolean audio_note_play_cb(GtkWidget *widget, gpointer data) { -audio_note_play("/tmp/testing.wav"); +audio_note_ui *ui=(audio_note_ui *)data; + +audio_note_play(cfile); +MACRO_BANNER_SHOW_INFO(_window, _("Playing...")); return TRUE; } static gboolean audio_note_stop_cb(GtkWidget *widget, gpointer data) { -audio_note_stop(); +if (audio_note_stop()==TRUE) + MACRO_BANNER_SHOW_INFO(_window, _("Stopped...")); return TRUE; } @@ -121,20 +162,28 @@ if (rec==TRUE) { np->src=gst_element_factory_make(AUDIO_SRC, "source"); np->filter=gst_element_factory_make("wavenc", "filter"); np->sink=gst_element_factory_make("filesink", "sink"); -#if 0 - /* No idea wasting space with some hifi format */ - np->caps=gst_element_factory_make("capsfilter", "caps"); + + gst_bin_add_many(GST_BIN(np->pipeline), np->src, np->filter, np->sink, NULL); + +#ifndef WITH_DEVICE_770 + /* Don't waste space with some hifi format */ np->srccaps=gst_caps_new_simple ("audio/x-raw-int", "depth", G_TYPE_INT, 16, "signed", G_TYPE_BOOLEAN, TRUE, - "width", G_TYPE_INT, 16, - "rate", G_TYPE_INT, 8000, + "width", G_TYPE_INT, 16, + "rate", G_TYPE_INT, 11025, "channels", G_TYPE_INT, 1, NULL); + if (!gst_element_link_filtered(np->src, np->filter, np->srccaps)) + g_printerr("Failed to set caps for source\n"); + else + gst_element_link(np->src, np->filter); + gst_caps_unref(np->srccaps); +#else + gst_element_link(np->src, np->filter); #endif - gst_bin_add_many(GST_BIN(np->pipeline), np->src, np->filter, np->sink, NULL); - if (!gst_element_link_many(np->src, np->filter, np->sink, NULL)) - g_printerr("Failed to link record pipeline\n"); + gst_element_link(np->filter, np->sink); + } else { g_debug("GST: Creating playback pipeline"); np->src=gst_element_factory_make("filesrc", "source"); diff --git a/src/audio-note.h b/src/audio-note.h index 0f64ac8..250ee02 100644 --- a/src/audio-note.h +++ b/src/audio-note.h @@ -30,6 +30,8 @@ struct _note_pipeline { GstElement *src; GstElement *sink; GstElement *filter; + GstElement *caps; + GstCaps *srccaps; gboolean active; gboolean rec; };