2 * This file is part of mapper
4 * Copyright (C) 2007 Kaj-Michael Lang
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Quick record audio notes on the road.
28 #include "audio-note.h"
30 #ifdef WITH_DEVICE_770
31 #define AUDIO_SRC "dsppcmsrc"
32 #define AUDIO_SINK "dsppcmsink"
34 #define AUDIO_SRC "alsasrc"
35 #define AUDIO_SINK "autoaudiosink"
38 typedef struct _note_pipeline note_pipeline;
39 struct _note_pipeline {
46 static note_pipeline note_play;
47 static note_pipeline note_record;
52 audio_note_bus_cb(GstBus *bus, GstMessage *msg, gpointer data)
57 switch (GST_MESSAGE_TYPE (msg)) {
61 case GST_MESSAGE_ERROR:
62 gst_message_parse_error (msg, &err, &debug);
65 g_printf("Error: %s\n", err->message);
68 case GST_MESSAGE_STATE_CHANGED:
69 g_printf("State changed\n");
72 g_printf("GST: %s\n", gst_message_type_get_name(GST_MESSAGE_TYPE(msg)));
79 audio_create_pipeline(note_pipeline *np, gboolean rec)
81 np->pipeline=gst_pipeline_new("pipeline");
82 g_assert(np->pipeline);
84 np->src=gst_element_factory_make(AUDIO_SRC, "source");
85 np->filter=gst_element_factory_make("wavenc", "filter");
86 np->sink=gst_element_factory_make("filesink", "sink");
88 np->src=gst_element_factory_make("filesrc", "source");
89 np->filter=gst_element_factory_make("wavenc", "filter");
90 np->sink=gst_element_factory_make(AUDIO_SINK, "sink");
100 * Set the given elements (filesrc or filesink) file location
103 audio_set_filename(GstElement *e, gchar *file)
105 g_object_set(G_OBJECT(e), "location", file, NULL);
109 * Play given audio note file
112 audio_note_play(gchar *file)
114 audio_set_filename(note_play.src, file);
115 if (gst_element_set_state(note_play.pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
116 g_printf("Failed to play file %s\n", file);
123 * Record to given file
126 audio_note_record(gchar *file)
128 audio_set_filename(note_record.sink, file);
129 if (gst_element_set_state(note_record.pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
130 g_printf("Failed to record to file %s\n", file);
143 * Init gst pipelines for note play and record
146 audio_note_init(void)
148 audio_create_pipeline(¬e_play, FALSE);
149 audio_create_pipeline(¬e_record, TRUE);
151 bus=gst_pipeline_get_bus(GST_PIPELINE(note_play.pipeline));
153 gst_bus_add_watch(bus, audio_note_bus_cb, NULL);
155 bus=gst_pipeline_get_bus(GST_PIPELINE(note_record.pipeline));
157 gst_bus_add_watch(bus, audio_note_bus_cb, NULL);
163 audio_note_deinit(void)
165 gst_element_set_state(note_play.pipeline, GST_STATE_NULL);
166 gst_object_unref(note_play.pipeline);
168 gst_element_set_state(note_record.pipeline, GST_STATE_NULL);
169 gst_object_unref(note_record.pipeline);