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 32 #define GST_TYPE_AUDIO_TEST_SRC \ 33 (gst_audio_test_src_get_type()) 34 #define GST_AUDIO_TEST_SRC(obj) \ 35 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_TEST_SRC,GstAudioTestSrc)) 36 #define GST_AUDIO_TEST_SRC_CLASS(klass) \ 37 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_TEST_SRC,GstAudioTestSrcClass)) 38 #define GST_IS_AUDIO_TEST_SRC(obj) \ 39 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_TEST_SRC)) 40 #define GST_IS_AUDIO_TEST_SRC_CLASS(klass) \ 41 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_TEST_SRC)) 42 43 /** 44 * GstAudioTestSrcWave: 45 * @GST_AUDIO_TEST_SRC_WAVE_SINE: a sine wave 46 * @GST_AUDIO_TEST_SRC_WAVE_SQUARE: a square wave 47 * @GST_AUDIO_TEST_SRC_WAVE_SAW: a saw wave 48 * @GST_AUDIO_TEST_SRC_WAVE_TRIANGLE: a tringle wave 49 * @GST_AUDIO_TEST_SRC_WAVE_SILENCE: silence 50 * @GST_AUDIO_TEST_SRC_WAVE_WHITE_NOISE: white uniform noise 51 * @GST_AUDIO_TEST_SRC_WAVE_PINK_NOISE: pink noise 52 * @GST_AUDIO_TEST_SRC_WAVE_SINE_TAB: sine wave using a table 53 * @GST_AUDIO_TEST_SRC_WAVE_TICKS: periodic ticks 54 * @GST_AUDIO_TEST_SRC_WAVE_GAUSSIAN_WHITE_NOISE: white (zero mean) Gaussian noise 55 * @GST_AUDIO_TEST_SRC_WAVE_RED_NOISE: red (brownian) noise 56 * @GST_AUDIO_TEST_SRC_WAVE_BLUE_NOISE: spectraly inverted pink noise 57 * @GST_AUDIO_TEST_SRC_WAVE_VIOLET_NOISE: spectraly inverted red (brownian) noise 58 * 59 * Different types of supported sound waves. 60 */ 61 typedef enum { 62 GST_AUDIO_TEST_SRC_WAVE_SINE, 63 GST_AUDIO_TEST_SRC_WAVE_SQUARE, 64 GST_AUDIO_TEST_SRC_WAVE_SAW, 65 GST_AUDIO_TEST_SRC_WAVE_TRIANGLE, 66 GST_AUDIO_TEST_SRC_WAVE_SILENCE, 67 GST_AUDIO_TEST_SRC_WAVE_WHITE_NOISE, 68 GST_AUDIO_TEST_SRC_WAVE_PINK_NOISE, 69 GST_AUDIO_TEST_SRC_WAVE_SINE_TAB, 70 GST_AUDIO_TEST_SRC_WAVE_TICKS, 71 GST_AUDIO_TEST_SRC_WAVE_GAUSSIAN_WHITE_NOISE, 72 GST_AUDIO_TEST_SRC_WAVE_RED_NOISE, 73 GST_AUDIO_TEST_SRC_WAVE_BLUE_NOISE, 74 GST_AUDIO_TEST_SRC_WAVE_VIOLET_NOISE 75 } GstAudioTestSrcWave; 76 77 #define PINK_MAX_RANDOM_ROWS (30) 78 #define PINK_RANDOM_BITS (16) 79 #define PINK_RANDOM_SHIFT ((sizeof(long)*8)-PINK_RANDOM_BITS) 80 81 typedef struct { 82 glong rows[PINK_MAX_RANDOM_ROWS]; 83 glong running_sum; /* Used to optimize summing of generators. */ 84 gint index; /* Incremented each sample. */ 85 gint index_mask; /* Index wrapped by ANDing with this mask. */ 86 gdouble scalar; /* Used to scale within range of -1.0 to +1.0 */ 87 } GstPinkNoise; 88 89 typedef struct { 90 gdouble state; /* noise state */ 91 } GstRedNoise; 92 93 typedef struct _GstAudioTestSrc GstAudioTestSrc; 94 typedef struct _GstAudioTestSrcClass GstAudioTestSrcClass; 95 96 typedef void (*ProcessFunc) (GstAudioTestSrc*, guint8 *); 97 98 /** 99 * GstAudioTestSrc: 100 * 101 * audiotestsrc object structure. 102 */ 103 struct _GstAudioTestSrc { 104 GstBaseSrc parent; 105 106 ProcessFunc process; 107 GstAudioFormatPack pack_func; 108 gint pack_size; 109 gpointer tmp; 110 gsize tmpsize; 111 112 /* parameters */ 113 GstAudioTestSrcWave wave; 114 gdouble volume; 115 gdouble freq; 116 117 /* audio parameters */ 118 GstAudioInfo info; 119 gint samples_per_buffer; 120 121 /*< private >*/ 122 gboolean tags_pushed; /* send tags just once ? */ 123 GstClockTimeDiff timestamp_offset; /* base offset */ 124 GstClockTime next_time; /* next timestamp */ 125 gint64 next_sample; /* next sample to send */ 126 gint64 next_byte; /* next byte to send */ 127 gint64 sample_stop; 128 gboolean check_seek_stop; 129 gboolean eos_reached; 130 gint generate_samples_per_buffer; /* used to generate a partial buffer */ 131 gboolean can_activate_pull; 132 gboolean reverse; /* play backwards */ 133 134 /* waveform specific context data */ 135 GRand *gen; /* random number generator */ 136 gdouble accumulator; /* phase angle */ 137 GstPinkNoise pink; 138 GstRedNoise red; 139 gdouble wave_table[1024]; 140 guint sine_periods_per_tick; 141 guint64 tick_interval; 142 guint marker_tick_period; 143 gdouble marker_tick_volume; 144 gboolean apply_tick_ramp; 145 guint samples_between_ticks; 146 guint tick_counter; 147 }; 148 149 struct _GstAudioTestSrcClass { 150 GstBaseSrcClass parent_class; 151 }; 152 153 GType gst_audio_test_src_get_type (void); 154 155 G_END_DECLS 156 157 #endif /* __GST_AUDIO_TEST_SRC_H__ */ 158