comparison libaf/af_tools.c @ 8607:d6f40a06867b

Changes includes: - Improved runtime control system - 3 New filter panning, compressor/limiter and a noise gate - The compressor/limiter and the noise gate are not yet finished - The panning filter does combined mixing and channel routing and can be used to down-mix from stereo to mono (for example) - Improvements to volume and channel - volume now has a very good soft clipping using sin() - channel can handle generic routing of audio data - Conversion of all filters to handle floating point data - Cleanup of message printing - Fix for the sig 11 bug reported by Denes
author anders
date Sat, 28 Dec 2002 13:59:53 +0000
parents
children 440301fef3fe
comparison
equal deleted inserted replaced
8606:d80edba39db9 8607:d6f40a06867b
1 #include <math.h>
2 #include <af.h>
3
4 /* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if
5 fail */
6 inline int af_from_dB(int n, float* in, float* out, float k, float mi, float ma)
7 {
8 int i = 0;
9 // Sanity check
10 if(!in || !out)
11 return AF_ERROR;
12
13 for(i=0;i<n;i++){
14 if(in[i]<=-200)
15 out[i]=0.0;
16 else
17 out[i]=pow(10.0,clamp(in[i],mi,ma)/k);
18 }
19 return AF_OK;
20 }
21
22 /* Convert from gain value to dB. Returns AF_OK if of and AF_ERROR if
23 fail */
24 inline int af_to_dB(int n, float* in, float* out, float k)
25 {
26 int i = 0;
27 // Sanity check
28 if(!in || !out)
29 return AF_ERROR;
30
31 for(i=0;i<AF_NCH;i++){
32 if(in[i] == 0.0)
33 out[i]=-200.0;
34 else
35 out[i]=k*log10(in[i]);
36 }
37 return AF_OK;
38 }
39
40 /* Convert from ms to sample time*/
41 inline int af_from_ms(int n, float* in, float* out, int rate, float mi, float ma)
42 {
43 int i = 0;
44 // Sanity check
45 if(!in || !out)
46 return AF_ERROR;
47
48 for(i=0;i<AF_NCH;i++)
49 out[i]=clamp(in[i],ma,mi);
50
51 return AF_OK;
52 }
53
54 /* Convert from sample time to ms */
55 inline int af_to_ms(int n, float* in, float* out, int rate)
56 {
57 int i = 0;
58 // Sanity check
59 if(!in || !out)
60 return AF_ERROR;
61
62 for(i=0;i<AF_NCH;i++)
63 out[i]=in[i];
64
65 return AF_OK;
66 }
67
68 /* Helper function for testing the output format */
69 inline int af_test_output(struct af_instance_s* af, af_data_t* out)
70 {
71 if((af->data->format != out->format) ||
72 (af->data->bps != out->bps) ||
73 (af->data->rate != out->rate) ||
74 (af->data->nch != out->nch)){
75 memcpy(out,af->data,sizeof(af_data_t));
76 return AF_FALSE;
77 }
78 return AF_OK;
79 }