Subversion Repositories svnkaklik

Rev

Rev 538 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 538 Rev 539
Line 167... Line 167...
167
	signed short *samples;
167
	signed short *samples;
168
	snd_pcm_channel_area_t *areas;
168
	snd_pcm_channel_area_t *areas;
169
	unsigned int period;
169
	unsigned int period;
170
};
170
};
171
 
171
 
-
 
172
 
-
 
173
////// SIGNAL GENERATION STUFF
172
/*int linear_chirp(int *pole, int delka_pole){  // vygeneruje linearni chirp a vzorky ulozi do pole
174
/*int linear_chirp(int *pole, int delka_pole){  // vygeneruje linearni chirp a vzorky ulozi do pole
173
 
175
 
174
static const float f0 = 0.0001;
176
static const float f0 = 0.0001;
175
static const float k = 0.00001;
177
static const float k = 0.00001;
176
 
178
 
Line 182... Line 184...
182
//  else return 0;
184
//  else return 0;
183
 
185
 
184
}*/
186
}*/
185
 
187
 
186
// vygeneruje linearni chirp a vzorky ulozi do pole
188
// vygeneruje linearni chirp a vzorky ulozi do pole
187
unsigned int linear_windowed_chirp(unsigned int *pole, unsigned int delka_pole)
189
unsigned int linear_windowed_chirp(unsigned int *pole, unsigned int delka_pole,unsigned int offset)
188
{  
190
{
189
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
191
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
190
 
192
 
191
static const float f0 = 3000;
193
static const float f0 = 1000;
192
static const float fmax = 5000;
194
static const float fmax = 10000;
193
static const float Tw = 0.002;
195
static const float Tw = 0.002;
194
static float k;
196
static float k;
195
 
197
 
196
unsigned int n=0;
198
unsigned int n=0;
197
double t;
199
double t;
Line 200... Line 202...
200
  k=2*(fmax-f0)/Tw;
202
  k=2*(fmax-f0)/Tw;
201
  perioda = rate*Tw; 
203
  perioda = rate*Tw; 
202
 
204
 
203
  for(n=0;n<=perioda;n++){
205
  for(n=0;n<=perioda;n++){
204
     t = (double) n/ (double)rate;
206
     t = (double) n/ (double)rate;
205
     pole[n] = (short) round ( (0.35875 - 0.48829*cos(2*M_PI*t*1/Tw) + 0.14128*cos(2*M_PI*2*t*1/Tw) - 0.01168*cos(2*M_PI*3*t*1/Tw))*maxval*sin(2*M_PI*(t)*(f0+(k/2)*(t))) );
207
     pole[n+offset] = (short) round ( (0.35875 - 0.48829*cos(2*M_PI*t*1/Tw) + 0.14128*cos(2*M_PI*2*t*1/Tw) - 0.01168*cos(2*M_PI*3*t*1/Tw))*maxval*sin(2*M_PI*(t)*(f0+(k/2)*(t))) );
206
  }
208
  }
207
  return perioda;
209
  return (perioda+offset);
208
}
210
}
209
 
211
 
210
// generate sine samples and store
212
// generate sine samples and store
211
int sine(unsigned int *pole, unsigned int delka_pole)
213
int sine(unsigned int *pole, unsigned int delka_pole)
212
{
214
{
Line 217... Line 219...
217
  for(n=0;n < delka_pole;n++){
219
  for(n=0;n < delka_pole;n++){
218
    t = 440.0 * (double) n/ (double)rate;
220
    t = 440.0 * (double) n/ (double)rate;
219
    pole[n] = (short) round(maxval*sin(2*M_PI*t));
221
    pole[n] = (short) round(maxval*sin(2*M_PI*t));
220
  }
222
  }
221
}
223
}
-
 
224
//// generate simple sine ping
-
 
225
unsigned int sine_ping(unsigned int *pole, unsigned int delka_pole,unsigned int offset, double frequency)
-
 
226
{
-
 
227
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
-
 
228
unsigned int n;
-
 
229
double t;
222
 
230
 
-
 
231
  for(n=0;n < delka_pole;n++){
-
 
232
    t = frequency * (double) n/ (double)rate;
-
 
233
    pole[n] = (short) round(maxval*sin(2*M_PI*t));
-
 
234
  }
-
 
235
}
223
 
236
 
224
 
-
 
-
 
237
/////////// CALL BACK STUFF ///////////////////
225
static void async_playback_callback(snd_async_handler_t *ahandler)
238
static void async_playback_callback(snd_async_handler_t *ahandler)
226
{
239
{
227
	snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler);
240
	snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler);
228
/*	struct async_private_data *data = snd_async_handler_get_callback_private(ahandler);
241
/*	struct async_private_data *data = snd_async_handler_get_callback_private(ahandler);
229
	signed short *samples = data->samples;
242
	signed short *samples = data->samples;
Line 327... Line 340...
327
	if ((err = set_swparams(capture_handle, swparams)) < 0) {
340
	if ((err = set_swparams(capture_handle, swparams)) < 0) {
328
		printf("Setting of swparams failed: %s\n", snd_strerror(err));
341
		printf("Setting of swparams failed: %s\n", snd_strerror(err));
329
		exit(EXIT_FAILURE);
342
		exit(EXIT_FAILURE);
330
	}
343
	}
331
 
344
 
-
 
345
/// generate ping pattern
-
 
346
 
332
        chirp_size=linear_windowed_chirp(chirp,1000000);
347
        chirp_size=linear_windowed_chirp(chirp,1000000, 300);
333
 
348
 
334
/// register playback callback 
349
/// register playback callback 
335
	err = snd_async_add_pcm_handler(&phandler, playback_handle, async_playback_callback, &data); // fill by dummy &data
350
	err = snd_async_add_pcm_handler(&phandler, playback_handle, async_playback_callback, &data); // fill by dummy &data
336
	if (err < 0) {
351
	if (err < 0) {
337
		printf("Unable to register async handler\n");
352
		printf("Unable to register async handler\n");