summaryrefslogtreecommitdiffstats
path: root/gst
diff options
context:
space:
mode:
authorOlivier Crete <olivier.crete@collabora.co.uk>2008-06-13 23:41:44 +0000
committerEdward Hervey <bilboed@bilboed.com>2009-02-21 17:48:06 +0100
commitb81a072d49be32899c392c516d0ef86feb7e117b (patch)
treeeb9985c9455e3f494584e240df2f65a6cb35f5e8 /gst
parentdd8d949bd9547d3f14f67729a857a894e14c0a55 (diff)
downloadgst-plugins-bad-b81a072d49be32899c392c516d0ef86feb7e117b.tar.gz
gst-plugins-bad-b81a072d49be32899c392c516d0ef86feb7e117b.tar.bz2
gst-plugins-bad-b81a072d49be32899c392c516d0ef86feb7e117b.zip
[MOVED FROM GST-P-FARSIGHT] Put the sample rate in dtmfsrc into a variable
20080613234144-3e2dc-e60070943bec829b703b8821c7aa4351a02deebe.gz
Diffstat (limited to 'gst')
-rw-r--r--gst/dtmf/gstdtmfsrc.c25
-rw-r--r--gst/dtmf/gstdtmfsrc.h2
2 files changed, 16 insertions, 11 deletions
diff --git a/gst/dtmf/gstdtmfsrc.c b/gst/dtmf/gstdtmfsrc.c
index 38470a00..55c1a4aa 100644
--- a/gst/dtmf/gstdtmfsrc.c
+++ b/gst/dtmf/gstdtmfsrc.c
@@ -143,7 +143,7 @@
#define DEFAULT_PACKET_INTERVAL 50 /* ms */
#define MIN_PACKET_INTERVAL 10 /* ms */
#define MAX_PACKET_INTERVAL 50 /* ms */
-#define SAMPLE_RATE 8000
+#define DEFAULT_SAMPLE_RATE 8000
#define SAMPLE_SIZE 16
#define CHANNELS 1
#define MIN_EVENT 0
@@ -242,8 +242,6 @@ static void gst_dtmf_src_get_property (GObject * object, guint prop_id,
static gboolean gst_dtmf_src_handle_event (GstBaseSrc *src, GstEvent * event);
static GstStateChangeReturn gst_dtmf_src_change_state (GstElement * element,
GstStateChange transition);
-static void gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key,
- float duration, GstBuffer * buffer);
static GstFlowReturn gst_dtmf_src_create (GstBaseSrc * basesrc,
guint64 offset, guint length, GstBuffer ** buffer);
static void gst_dtmf_src_add_start_event (GstDTMFSrc *dtmfsrc,
@@ -318,6 +316,8 @@ gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass *g_class)
dtmfsrc->event_queue = g_async_queue_new ();
dtmfsrc->last_event = NULL;
+ dtmfsrc->sample_rate = DEFAULT_SAMPLE_RATE;
+
GST_DEBUG_OBJECT (dtmfsrc, "init done");
}
@@ -522,12 +522,13 @@ gst_dtmf_src_add_stop_event (GstDTMFSrc *dtmfsrc)
}
static void
-gst_dtmf_src_generate_silence(GstBuffer * buffer, float duration)
+gst_dtmf_src_generate_silence(GstBuffer * buffer, float duration,
+ gint sample_rate)
{
gint buf_size;
/* Create a buffer with data set to 0 */
- buf_size = ((duration/1000)*SAMPLE_RATE*SAMPLE_SIZE*CHANNELS)/8;
+ buf_size = ((duration/1000)*sample_rate*SAMPLE_SIZE*CHANNELS)/8;
GST_BUFFER_SIZE (buffer) = buf_size;
GST_BUFFER_MALLOCDATA (buffer) = g_malloc0(buf_size);
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
@@ -536,7 +537,7 @@ gst_dtmf_src_generate_silence(GstBuffer * buffer, float duration)
static void
gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key, float duration,
- GstBuffer * buffer)
+ GstBuffer * buffer, gint sample_rate)
{
gint16 *p;
gint tone_size;
@@ -545,7 +546,7 @@ gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key, float duration,
double volume_factor;
/* Create a buffer for the tone */
- tone_size = ((duration/1000)*SAMPLE_RATE*SAMPLE_SIZE*CHANNELS)/8;
+ tone_size = ((duration/1000)*sample_rate*SAMPLE_SIZE*CHANNELS)/8;
GST_BUFFER_SIZE (buffer) = tone_size;
GST_BUFFER_MALLOCDATA (buffer) = g_malloc(tone_size);
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
@@ -562,8 +563,8 @@ gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key, float duration,
/*
* We add the fundamental frequencies together.
*/
- f1 = sin(2 * M_PI * key.low_frequency * (event->sample / SAMPLE_RATE));
- f2 = sin(2 * M_PI * key.high_frequency * (event->sample / SAMPLE_RATE));
+ f1 = sin(2 * M_PI * key.low_frequency * (event->sample / sample_rate));
+ f2 = sin(2 * M_PI * key.high_frequency * (event->sample / sample_rate));
amplitude = (f1 + f2) / 2;
@@ -602,11 +603,12 @@ gst_dtmf_src_create_next_tone_packet (GstDTMFSrc *dtmfsrc,
if (send_silence) {
GST_DEBUG_OBJECT (dtmfsrc, "Generating silence");
- gst_dtmf_src_generate_silence (buf, dtmfsrc->interval);
+ gst_dtmf_src_generate_silence (buf, dtmfsrc->interval,
+ dtmfsrc->sample_rate);
} else {
GST_DEBUG_OBJECT (dtmfsrc, "Generating tone");
gst_dtmf_src_generate_tone(event, DTMF_KEYS[event->event_number],
- dtmfsrc->interval, buf);
+ dtmfsrc->interval, buf, dtmfsrc->sample_rate);
}
event->packet_count++;
@@ -806,6 +808,7 @@ gst_dtmf_src_unlock_stop (GstBaseSrc *src) {
return TRUE;
}
+
static GstStateChangeReturn
gst_dtmf_src_change_state (GstElement * element, GstStateChange transition)
{
diff --git a/gst/dtmf/gstdtmfsrc.h b/gst/dtmf/gstdtmfsrc.h
index 0340a7c2..fdf6f50d 100644
--- a/gst/dtmf/gstdtmfsrc.h
+++ b/gst/dtmf/gstdtmfsrc.h
@@ -79,6 +79,8 @@ struct _GstDTMFSrc {
gboolean paused;
GstClockID clockid;
+
+ gint sample_rate;
};