2 ** Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
9 ** This program 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
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #define SF_MAX(x,y) ((x) > (y) ? (x) : (y))
31 static float crappy_snare (float *output
, int len
, int offset
, float gain
, float maxabs
) ;
34 generate_file (const char * filename
, int format
, int len
)
38 output
= calloc (len
, sizeof (float)) ;
40 maxabs
= crappy_snare (output
, len
, 0, 0.95, maxabs
) ;
41 maxabs
= crappy_snare (output
, len
, len
/ 4, 0.85, maxabs
) ;
42 maxabs
= crappy_snare (output
, len
, 2 * len
/ 4, 0.85, maxabs
) ;
43 crappy_snare (output
, len
, 3 * len
/ 4, 0.85, maxabs
) ;
45 write_mono_file (filename
, format
, 44100, output
, len
) ;
52 { return rand () / (0.5 * RAND_MAX
) - 1.0 ;
56 crappy_snare (float *output
, int len
, int offset
, float gain
, float maxabs
)
60 for (k
= offset
; k
< len
&& env
< gain
; k
++)
62 output
[k
] += env
* rand_float () ;
63 maxabs
= SF_MAX (maxabs
, fabs (output
[k
])) ;
66 for ( ; k
< len
&& env
> 1e-8 ; k
++)
68 output
[k
] += env
* rand_float () ;
69 maxabs
= SF_MAX (maxabs
, fabs (output
[k
])) ;