1 /* GStreamer 2 * Copyright (C) 2005 Stefan Kost <ensonic@users.sf.net> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public 15 * License along with this library; if not, write to the 16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef __GST_AUDIO_TEST_SRC_H__ 21 #define __GST_AUDIO_TEST_SRC_H__ 22 23 24 #include <gst/gst.h> 25 #include <gst/base/gstbasesrc.h> 26 27 #include <gst/audio/audio.h> 28 29 G_BEGIN_DECLS 30 31 #define GST_TYPE_AUDIO_TEST_SRC (gst_audio_test_src_get_type()) 32 G_DECLARE_FINAL_TYPE (GstAudioTestSrc, gst_audio_test_src, GST, AUDIO_TEST_SRC, 33 GstBaseSrc) 34 35 /** 36 * GstAudioTestSrcWave: 37 * @GST_AUDIO_TEST_SRC_WAVE_SINE: a sine wave 38 * @GST_AUDIO_TEST_SRC_WAVE_SQUARE: a square wave 39 * @GST_AUDIO_TEST_SRC_WAVE_SAW: a saw wave 40 * @GST_AUDIO_TEST_SRC_WAVE_TRIANGLE: a tringle wave 41 * @GST_AUDIO_TEST_SRC_WAVE_SILENCE: silence 42 * @GST_AUDIO_TEST_SRC_WAVE_WHITE_NOISE: white uniform noise 43 * @GST_AUDIO_TEST_SRC_WAVE_PINK_NOISE: pink noise 44 * @GST_AUDIO_TEST_SRC_WAVE_SINE_TAB: sine wave using a table 45 * @GST_AUDIO_TEST_SRC_WAVE_TICKS: periodic ticks 46 * @GST_AUDIO_TEST_SRC_WAVE_GAUSSIAN_WHITE_NOISE: white (zero mean) Gaussian noise 47 * @GST_AUDIO_TEST_SRC_WAVE_RED_NOISE: red (brownian) noise 48 * @GST_AUDIO_TEST_SRC_WAVE_BLUE_NOISE: spectraly inverted pink noise 49 * @GST_AUDIO_TEST_SRC_WAVE_VIOLET_NOISE: spectraly inverted red (brownian) noise 50 * 51 * Different types of supported sound waves. 52 */ 53 typedef enum { 54 GST_AUDIO_TEST_SRC_WAVE_SINE, 55 GST_AUDIO_TEST_SRC_WAVE_SQUARE, 56 GST_AUDIO_TEST_SRC_WAVE_SAW, 57 GST_AUDIO_TEST_SRC_WAVE_TRIANGLE, 58 GST_AUDIO_TEST_SRC_WAVE_SILENCE, 59 GST_AUDIO_TEST_SRC_WAVE_WHITE_NOISE, 60 GST_AUDIO_TEST_SRC_WAVE_PINK_NOISE, 61 GST_AUDIO_TEST_SRC_WAVE_SINE_TAB, 62 GST_AUDIO_TEST_SRC_WAVE_TICKS, 63 GST_AUDIO_TEST_SRC_WAVE_GAUSSIAN_WHITE_NOISE, 64 GST_AUDIO_TEST_SRC_WAVE_RED_NOISE, 65 GST_AUDIO_TEST_SRC_WAVE_BLUE_NOISE, 66 GST_AUDIO_TEST_SRC_WAVE_VIOLET_NOISE 67 } GstAudioTestSrcWave; 68 69 #define PINK_MAX_RANDOM_ROWS (30) 70 #define PINK_RANDOM_BITS (16) 71 #define PINK_RANDOM_SHIFT ((sizeof(long)*8)-PINK_RANDOM_BITS) 72 73 typedef struct { 74 glong rows[PINK_MAX_RANDOM_ROWS]; 75 glong running_sum; /* Used to optimize summing of generators. */ 76 gint index; /* Incremented each sample. */ 77 gint index_mask; /* Index wrapped by ANDing with this mask. */ 78 gdouble scalar; /* Used to scale within range of -1.0 to +1.0 */ 79 } GstPinkNoise; 80 81 typedef struct { 82 gdouble state; /* noise state */ 83 } GstRedNoise; 84 85 typedef void (*ProcessFunc) (GstAudioTestSrc*, guint8 *); 86 87 /** 88 * GstAudioTestSrc: 89 * 90 * audiotestsrc object structure. 91 */ 92 struct _GstAudioTestSrc { 93 GstBaseSrc parent; 94 95 ProcessFunc process; 96 GstAudioFormatPack pack_func; 97 gint pack_size; 98 gpointer tmp; 99 gsize tmpsize; 100 101 /* parameters */ 102 GstAudioTestSrcWave wave; 103 gdouble volume; 104 gdouble freq; 105 106 /* audio parameters */ 107 GstAudioInfo info; 108 gint samples_per_buffer; 109 110 /*< private >*/ 111 gboolean tags_pushed; /* send tags just once ? */ 112 GstClockTimeDiff timestamp_offset; /* base offset */ 113 GstClockTime next_time; /* next timestamp */ 114 gint64 next_sample; /* next sample to send */ 115 gint64 next_byte; /* next byte to send */ 116 gint64 sample_stop; 117 gboolean check_seek_stop; 118 gboolean eos_reached; 119 gint generate_samples_per_buffer; /* used to generate a partial buffer */ 120 gboolean can_activate_pull; 121 gboolean reverse; /* play backwards */ 122 123 /* waveform specific context data */ 124 GRand *gen; /* random number generator */ 125 gdouble accumulator; /* phase angle */ 126 GstPinkNoise pink; 127 GstRedNoise red; 128 gdouble wave_table[1024]; 129 guint sine_periods_per_tick; 130 guint64 tick_interval; 131 guint marker_tick_period; 132 gdouble marker_tick_volume; 133 gboolean apply_tick_ramp; 134 guint samples_between_ticks; 135 guint tick_counter; 136 }; 137 138 GST_ELEMENT_REGISTER_DECLARE (audiotestsrc); 139 140 G_END_DECLS 141 142 #endif /* __GST_AUDIO_TEST_SRC_H__ */ 143