Changeset d6008a8bb8e5e76d77dd15a654fc2fabef8910e9
- Timestamp:
- 09/11/07 12:14:01
(1 year ago)
- Author:
- Rafaël Carré <funman@videolan.org>
- git-committer:
- Rafaël Carré <funman@videolan.org> 1189505641 +0000
- git-parent:
[c6eafbbbf3edd51c00f96598cf4513856a1a757e]
- git-author:
- Rafaël Carré <funman@videolan.org> 1189505641 +0000
- Message:
Reverts [21943] for galaktos as it is external to vlc.
Just in case it is merged one day with upstream source.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r6ee1e19 |
rd6008a8 |
|
| 49 | 49 | void initPCM(int samples) |
|---|
| 50 | 50 | { |
|---|
| 51 | | int i; |
|---|
| | 51 | int i; |
|---|
| 52 | 52 | |
|---|
| 53 | 53 | //Allocate memory for PCM data buffer |
|---|
| … | … | |
| 55 | 55 | PCMd[0] = (double *)malloc(samples * sizeof(double)); |
|---|
| 56 | 56 | PCMd[1] = (double *)malloc(samples * sizeof(double)); |
|---|
| 57 | | |
|---|
| | 57 | |
|---|
| 58 | 58 | maxsamples=samples; |
|---|
| 59 | 59 | new=0; |
|---|
| … | … | |
| 84 | 84 | int samples=512; |
|---|
| 85 | 85 | |
|---|
| 86 | | for(i=0;i<samples;i++) |
|---|
| 87 | | { |
|---|
| 88 | | j=i+start; |
|---|
| 89 | | PCMd[0][j%maxsamples]=(PCMdata[0][i]/16384.0); |
|---|
| 90 | | PCMd[1][j%maxsamples]=(PCMdata[1][i]/16384.0); |
|---|
| 91 | | } |
|---|
| | 86 | for(i=0;i<samples;i++) |
|---|
| | 87 | { |
|---|
| | 88 | j=i+start; |
|---|
| | 89 | PCMd[0][j%maxsamples]=(PCMdata[0][i]/16384.0); |
|---|
| | 90 | PCMd[1][j%maxsamples]=(PCMdata[1][i]/16384.0); |
|---|
| | 91 | } |
|---|
| | 92 | |
|---|
| 92 | 93 | |
|---|
| 93 | | |
|---|
| 94 | | // printf("Added %d samples %d %d %f\n",samples,start,(start+samples)%maxsamples,PCM[0][start+10]); |
|---|
| | 94 | // printf("Added %d samples %d %d %f\n",samples,start,(start+samples)%maxsamples,PCM[0][start+10]); |
|---|
| 95 | 95 | |
|---|
| 96 | 96 | start+=samples; |
|---|
| … | … | |
| 114 | 114 | { |
|---|
| 115 | 115 | int i,index; |
|---|
| 116 | | |
|---|
| | 116 | |
|---|
| 117 | 117 | index=start-1; |
|---|
| 118 | 118 | |
|---|
| … | … | |
| 120 | 120 | |
|---|
| 121 | 121 | PCMdata[0]=PCMd[channel][index]; |
|---|
| 122 | | |
|---|
| | 122 | |
|---|
| 123 | 123 | for(i=1;i<samples;i++) |
|---|
| 124 | 124 | { |
|---|
| 125 | 125 | index=start-1-i; |
|---|
| 126 | 126 | if (index<0) index=maxsamples+index; |
|---|
| 127 | | |
|---|
| | 127 | |
|---|
| 128 | 128 | PCMdata[i]=(1-smoothing)*PCMd[channel][index]+smoothing*PCMdata[i-1]; |
|---|
| 129 | 129 | } |
|---|
| 130 | | |
|---|
| | 130 | |
|---|
| 131 | 131 | //return derivative of PCM data |
|---|
| 132 | 132 | if(derive) |
|---|
| 133 | 133 | { |
|---|
| 134 | 134 | for(i=0;i<samples-1;i++) |
|---|
| 135 | | { |
|---|
| 136 | | PCMdata[i]=PCMdata[i]-PCMdata[i+1]; |
|---|
| 137 | | } |
|---|
| | 135 | { |
|---|
| | 136 | PCMdata[i]=PCMdata[i]-PCMdata[i+1]; |
|---|
| | 137 | } |
|---|
| 138 | 138 | PCMdata[samples-1]=0; |
|---|
| 139 | 139 | } |
|---|
| … | … | |
| 143 | 143 | |
|---|
| 144 | 144 | |
|---|
| 145 | | |
|---|
| | 145 | |
|---|
| 146 | 146 | } |
|---|
| 147 | 147 | |
|---|
| … | … | |
| 155 | 155 | { |
|---|
| 156 | 156 | int i,index; |
|---|
| 157 | | |
|---|
| | 157 | |
|---|
| 158 | 158 | index=start-1; |
|---|
| 159 | 159 | |
|---|
| … | … | |
| 161 | 161 | |
|---|
| 162 | 162 | PCMdata[0]=PCMd[channel][index]; |
|---|
| 163 | | |
|---|
| | 163 | |
|---|
| 164 | 164 | for(i=1;i<new;i++) |
|---|
| 165 | 165 | { |
|---|
| 166 | 166 | index=start-1-i; |
|---|
| 167 | 167 | if (index<0) index=maxsamples+index; |
|---|
| 168 | | |
|---|
| | 168 | |
|---|
| 169 | 169 | PCMdata[i]=(1-smoothing)*PCMd[channel][index]+smoothing*PCMdata[i-1]; |
|---|
| 170 | 170 | } |
|---|
| 171 | | |
|---|
| | 171 | |
|---|
| 172 | 172 | //return derivative of PCM data |
|---|
| 173 | 173 | if(derive) |
|---|
| 174 | 174 | { |
|---|
| 175 | 175 | for(i=0;i<new-1;i++) |
|---|
| 176 | | { |
|---|
| 177 | | PCMdata[i]=PCMdata[i]-PCMdata[i+1]; |
|---|
| 178 | | } |
|---|
| | 176 | { |
|---|
| | 177 | PCMdata[i]=PCMdata[i]-PCMdata[i+1]; |
|---|
| | 178 | } |
|---|
| 179 | 179 | PCMdata[new-1]=0; |
|---|
| 180 | 180 | } |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 42 | 42 | { |
|---|
| 43 | 43 | |
|---|
| 44 | | int x,y; |
|---|
| | 44 | int x,y; |
|---|
| 45 | 45 | |
|---|
| 46 | 46 | vol_instant=0; |
|---|
| … | … | |
| 66 | 66 | beat_variance[x]=0; |
|---|
| 67 | 67 | for (y=0;y<80;y++) |
|---|
| 68 | | { |
|---|
| 69 | | beat_buffer[x][y]=0; |
|---|
| 70 | | } |
|---|
| | 68 | { |
|---|
| | 69 | beat_buffer[x][y]=0; |
|---|
| | 70 | } |
|---|
| 71 | 71 | } |
|---|
| 72 | 72 | |
|---|
| 73 | | } |
|---|
| | 73 | } |
|---|
| 74 | 74 | |
|---|
| 75 | 75 | void getBeatVals(double *vdataL,double *vdataR, double *vol) |
|---|
| … | … | |
| 81 | 81 | |
|---|
| 82 | 82 | for ( x=0;x<16;x++) |
|---|
| 83 | | { |
|---|
| 84 | | |
|---|
| 85 | | beat_instant[x]=0; |
|---|
| 86 | | for ( y=linear*2;y<(linear+8+x)*2;y++) |
|---|
| 87 | | { |
|---|
| 88 | | beat_instant[x]+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/(8+x)); |
|---|
| 89 | | vol_instant+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/512.0); |
|---|
| | 83 | { |
|---|
| | 84 | |
|---|
| | 85 | beat_instant[x]=0; |
|---|
| | 86 | for ( y=linear*2;y<(linear+8+x)*2;y++) |
|---|
| | 87 | { |
|---|
| | 88 | beat_instant[x]+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/(8+x)); |
|---|
| | 89 | vol_instant+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/512.0); |
|---|
| 90 | 90 | |
|---|
| 91 | | } |
|---|
| 92 | | |
|---|
| 93 | | linear=y/2; |
|---|
| 94 | | beat_history[x]-=(beat_buffer[x][beat_buffer_pos])*.0125; |
|---|
| 95 | | beat_buffer[x][beat_buffer_pos]=beat_instant[x]; |
|---|
| 96 | | beat_history[x]+=(beat_instant[x])*.0125; |
|---|
| 97 | | |
|---|
| 98 | | beat_val[x]=(beat_instant[x])/(beat_history[x]); |
|---|
| 99 | | |
|---|
| 100 | | beat_att[x]+=(beat_instant[x])/(beat_history[x]); |
|---|
| | 91 | } |
|---|
| | 92 | |
|---|
| | 93 | linear=y/2; |
|---|
| | 94 | beat_history[x]-=(beat_buffer[x][beat_buffer_pos])*.0125; |
|---|
| | 95 | beat_buffer[x][beat_buffer_pos]=beat_instant[x]; |
|---|
| | 96 | beat_history[x]+=(beat_instant[x])*.0125; |
|---|
| | 97 | |
|---|
| | 98 | beat_val[x]=(beat_instant[x])/(beat_history[x]); |
|---|
| | 99 | |
|---|
| | 100 | beat_att[x]+=(beat_instant[x])/(beat_history[x]); |
|---|
| 101 | 101 | |
|---|
| 102 | 102 | |
|---|
| 103 | | |
|---|
| 104 | | } |
|---|
| 105 | | |
|---|
| | 103 | |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|
| 106 | 106 | vol_history-=(vol_buffer[beat_buffer_pos])*.0125; |
|---|
| 107 | 107 | vol_buffer[beat_buffer_pos]=vol_instant; |
|---|
| … | … | |
| 111 | 111 | mid=0; |
|---|
| 112 | 112 | for(x=1;x<10;x++) |
|---|
| 113 | | { |
|---|
| 114 | | mid+=(beat_instant[x]); |
|---|
| 115 | | temp2+=(beat_history[x]); |
|---|
| 116 | | |
|---|
| 117 | | } |
|---|
| 118 | | |
|---|
| 119 | | mid=mid/(1.5*temp2); |
|---|
| 120 | | temp2=0; |
|---|
| 121 | | treb=0; |
|---|
| 122 | | for(x=10;x<16;x++) |
|---|
| 123 | | { |
|---|
| 124 | | treb+=(beat_instant[x]); |
|---|
| 125 | | temp2+=(beat_history[x]); |
|---|
| 126 | | } |
|---|
| 127 | | treb=treb/(1.5*temp2); |
|---|
| 128 | | *vol=vol_instant/(1.5*vol_history); |
|---|
| 129 | | |
|---|
| 130 | | bass=(beat_instant[0])/(1.5*beat_history[0]); |
|---|
| | 113 | { |
|---|
| | 114 | mid+=(beat_instant[x]); |
|---|
| | 115 | temp2+=(beat_history[x]); |
|---|
| | 116 | |
|---|
| | 117 | } |
|---|
| | 118 | |
|---|
| | 119 | mid=mid/(1.5*temp2); |
|---|
| | 120 | temp2=0; |
|---|
| | 121 | treb=0; |
|---|
| | 122 | for(x=10;x<16;x++) |
|---|
| | 123 | { |
|---|
| | 124 | treb+=(beat_instant[x]); |
|---|
| | 125 | temp2+=(beat_history[x]); |
|---|
| | 126 | } |
|---|
| | 127 | treb=treb/(1.5*temp2); |
|---|
| | 128 | *vol=vol_instant/(1.5*vol_history); |
|---|
| | 129 | |
|---|
| | 130 | bass=(beat_instant[0])/(1.5*beat_history[0]); |
|---|
| 131 | 131 | |
|---|
| 132 | | treb_att=.6 * treb_att + .4 * treb; |
|---|
| 133 | | mid_att=.6 * mid_att + .4 * mid; |
|---|
| 134 | | bass_att=.6 * bass_att + .4 * bass; |
|---|
| 135 | | //printf("%f %f %f %f\n",bass,mid,treb,*vol); |
|---|
| 136 | | // *vol=(beat_instant[3])/(beat_history[3]); |
|---|
| 137 | | beat_buffer_pos++; |
|---|
| 138 | | if( beat_buffer_pos>79)beat_buffer_pos=0; |
|---|
| 139 | | |
|---|
| | 132 | treb_att=.6 * treb_att + .4 * treb; |
|---|
| | 133 | mid_att=.6 * mid_att + .4 * mid; |
|---|
| | 134 | bass_att=.6 * bass_att + .4 * bass; |
|---|
| | 135 | //printf("%f %f %f %f\n",bass,mid,treb,*vol); |
|---|
| | 136 | // *vol=(beat_instant[3])/(beat_history[3]); |
|---|
| | 137 | beat_buffer_pos++; |
|---|
| | 138 | if( beat_buffer_pos>79)beat_buffer_pos=0; |
|---|
| | 139 | |
|---|
| 140 | 140 | } |
|---|
| 141 | 141 | void freeBeatDetect() |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 26 | 26 | #include <math.h> |
|---|
| 27 | 27 | /* Values to optimize the sigmoid function */ |
|---|
| 28 | | #define R 32767 |
|---|
| 29 | | #define RR 65534 |
|---|
| | 28 | #define R 32767 |
|---|
| | 29 | #define RR 65534 |
|---|
| 30 | 30 | |
|---|
| 31 | 31 | inline double int_wrapper(double * arg_list) { |
|---|
| … | … | |
| 37 | 37 | |
|---|
| 38 | 38 | inline double sqr_wrapper(double * arg_list) { |
|---|
| 39 | | |
|---|
| 40 | | return pow(2, arg_list[0]); |
|---|
| 41 | | } |
|---|
| 42 | | |
|---|
| 43 | | |
|---|
| 44 | | inline double sign_wrapper(double * arg_list) { |
|---|
| 45 | | |
|---|
| 46 | | return -arg_list[0]; |
|---|
| 47 | | } |
|---|
| | 39 | |
|---|
| | 40 | return pow(2, arg_list[0]); |
|---|
| | 41 | } |
|---|
| | 42 | |
|---|
| | 43 | |
|---|
| | 44 | inline double sign_wrapper(double * arg_list) { |
|---|
| | 45 | |
|---|
| | 46 | return -arg_list[0]; |
|---|
| | 47 | } |
|---|
| 48 | 48 | |
|---|
| 49 | 49 | inline double min_wrapper(double * arg_list) { |
|---|
| 50 | | |
|---|
| 51 | | if (arg_list[0] > arg_list[1]) |
|---|
| 52 | | return arg_list[1]; |
|---|
| 53 | | |
|---|
| 54 | | return arg_list[0]; |
|---|
| 55 | | } |
|---|
| | 50 | |
|---|
| | 51 | if (arg_list[0] > arg_list[1]) |
|---|
| | 52 | return arg_list[1]; |
|---|
| | 53 | |
|---|
| | 54 | return arg_list[0]; |
|---|
| | 55 | } |
|---|
| 56 | 56 | |
|---|
| 57 | 57 | inline double max_wrapper(double * arg_list) { |
|---|
| 58 | 58 | |
|---|
| 59 | | if (arg_list[0] > arg_list[1]) |
|---|
| 60 | | return arg_list[0]; |
|---|
| 61 | | |
|---|
| 62 | | return arg_list[1]; |
|---|
| | 59 | if (arg_list[0] > arg_list[1]) |
|---|
| | 60 | return arg_list[0]; |
|---|
| | 61 | |
|---|
| | 62 | return arg_list[1]; |
|---|
| 63 | 63 | } |
|---|
| 64 | 64 | |
|---|
| … | … | |
| 67 | 67 | return (RR / (1 + exp( -(((double)(arg_list[0])) * arg_list[1]) / R) - R)); |
|---|
| 68 | 68 | } |
|---|
| 69 | | |
|---|
| 70 | | |
|---|
| | 69 | |
|---|
| | 70 | |
|---|
| 71 | 71 | inline double bor_wrapper(double * arg_list) { |
|---|
| 72 | 72 | |
|---|
| 73 | | return (double)((int)arg_list[0] || (int)arg_list[1]); |
|---|
| 74 | | } |
|---|
| 75 | | |
|---|
| | 73 | return (double)((int)arg_list[0] || (int)arg_list[1]); |
|---|
| | 74 | } |
|---|
| | 75 | |
|---|
| 76 | 76 | inline double band_wrapper(double * arg_list) { |
|---|
| 77 | | return (double)((int)arg_list[0] && (int)arg_list[1]); |
|---|
| 78 | | } |
|---|
| | 77 | return (double)((int)arg_list[0] && (int)arg_list[1]); |
|---|
| | 78 | } |
|---|
| 79 | 79 | |
|---|
| 80 | 80 | inline double bnot_wrapper(double * arg_list) { |
|---|
| 81 | | return (double)(!(int)arg_list[0]); |
|---|
| 82 | | } |
|---|
| | 81 | return (double)(!(int)arg_list[0]); |
|---|
| | 82 | } |
|---|
| 83 | 83 | |
|---|
| 84 | 84 | inline double if_wrapper(double * arg_list) { |
|---|
| 85 | 85 | |
|---|
| 86 | | if ((int)arg_list[0] == 0) |
|---|
| 87 | | return arg_list[2]; |
|---|
| 88 | | return arg_list[1]; |
|---|
| 89 | | } |
|---|
| | 86 | if ((int)arg_list[0] == 0) |
|---|
| | 87 | return arg_list[2]; |
|---|
| | 88 | return arg_list[1]; |
|---|
| | 89 | } |
|---|
| 90 | 90 | |
|---|
| 91 | 91 | |
|---|
| … | … | |
| 97 | 97 | //printf("VAL: %f\n", l); |
|---|
| 98 | 98 | return l; |
|---|
| 99 | | } |
|---|
| | 99 | } |
|---|
| 100 | 100 | |
|---|
| 101 | 101 | inline double equal_wrapper(double * arg_list) { |
|---|
| 102 | 102 | |
|---|
| 103 | | return (arg_list[0] == arg_list[1]); |
|---|
| 104 | | } |
|---|
| | 103 | return (arg_list[0] == arg_list[1]); |
|---|
| | 104 | } |
|---|
| 105 | 105 | |
|---|
| 106 | 106 | |
|---|
| 107 | 107 | inline double above_wrapper(double * arg_list) { |
|---|
| 108 | 108 | |
|---|
| 109 | | return (arg_list[0] > arg_list[1]); |
|---|
| 110 | | } |
|---|
| | 109 | return (arg_list[0] > arg_list[1]); |
|---|
| | 110 | } |
|---|
| 111 | 111 | |
|---|
| 112 | 112 | |
|---|
| 113 | 113 | inline double below_wrapper(double * arg_list) { |
|---|
| 114 | 114 | |
|---|
| 115 | | return (arg_list[0] < arg_list[1]); |
|---|
| | 115 | return (arg_list[0] < arg_list[1]); |
|---|
| 116 | 116 | } |
|---|
| 117 | 117 | |
|---|
| 118 | 118 | inline double sin_wrapper(double * arg_list) { |
|---|
| 119 | | return (sin (arg_list[0])); |
|---|
| | 119 | return (sin (arg_list[0])); |
|---|
| 120 | 120 | } |
|---|
| 121 | 121 | |
|---|
| 122 | 122 | |
|---|
| 123 | 123 | inline double cos_wrapper(double * arg_list) { |
|---|
| 124 | | return (cos (arg_list[0])); |
|---|
| | 124 | return (cos (arg_list[0])); |
|---|
| 125 | 125 | } |
|---|
| 126 | 126 | |
|---|
| 127 | 127 | inline double tan_wrapper(double * arg_list) { |
|---|
| 128 | | return (tan(arg_list[0])); |
|---|
| | 128 | return (tan(arg_list[0])); |
|---|
| 129 | 129 | } |
|---|
| 130 | 130 | |
|---|
| 131 | 131 | inline double asin_wrapper(double * arg_list) { |
|---|
| 132 | | return (asin (arg_list[0])); |
|---|
| | 132 | return (asin (arg_list[0])); |
|---|
| 133 | 133 | } |
|---|
| 134 | 134 | |
|---|
| 135 | 135 | inline double acos_wrapper(double * arg_list) { |
|---|
| 136 | | return (acos (arg_list[0])); |
|---|
| | 136 | return (acos (arg_list[0])); |
|---|
| 137 | 137 | } |
|---|
| 138 | 138 | |
|---|
| 139 | 139 | inline double atan_wrapper(double * arg_list) { |
|---|
| 140 | | return (atan (arg_list[0])); |
|---|
| | 140 | return (atan (arg_list[0])); |
|---|
| 141 | 141 | } |
|---|
| 142 | 142 | |
|---|
| … | … | |
| 194 | 194 | |
|---|
| 195 | 195 | int result = 1; |
|---|
| 196 | | |
|---|
| | 196 | |
|---|
| 197 | 197 | int n = (int)arg_list[0]; |
|---|
| 198 | | |
|---|
| | 198 | |
|---|
| 199 | 199 | while (n > 1) { |
|---|
| 200 | 200 | result = result * n; |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 1 | | /* Wrappers for all the builtin functions |
|---|
| | 1 | /* Wrappers for all the builtin functions |
|---|
| 2 | 2 | The arg_list pointer is a list of doubles. Its |
|---|
| 3 | 3 | size is equal to the number of arguments the parameter |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 14 | 14 | #ifndef FALSE |
|---|
| 15 | 15 | #define FALSE 0 |
|---|
| 16 | | #endif |
|---|
| | 16 | #endif |
|---|
| 17 | 17 | |
|---|
| 18 | 18 | #define PROJECTM_FILE_EXTENSION ".prjm" |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 78 | 78 | /* Initialize tree data structures */ |
|---|
| 79 | 79 | |
|---|
| 80 | | if ((custom_shape->param_tree = |
|---|
| | 80 | if ((custom_shape->param_tree = |
|---|
| 81 | 81 | create_splaytree(compare_string, copy_string, free_string)) == NULL) { |
|---|
| 82 | 82 | free_custom_shape(custom_shape); |
|---|
| … | … | |
| 84 | 84 | } |
|---|
| 85 | 85 | |
|---|
| 86 | | if ((custom_shape->per_frame_eqn_tree = |
|---|
| | 86 | if ((custom_shape->per_frame_eqn_tree = |
|---|
| 87 | 87 | create_splaytree(compare_int, copy_int, free_int)) == NULL) { |
|---|
| 88 | 88 | free_custom_shape(custom_shape); |
|---|
| … | … | |
| 90 | 90 | } |
|---|
| 91 | 91 | |
|---|
| 92 | | if ((custom_shape->init_cond_tree = |
|---|
| | 92 | if ((custom_shape->init_cond_tree = |
|---|
| 93 | 93 | create_splaytree(compare_string, copy_string, free_string)) == NULL) { |
|---|
| 94 | 94 | free_custom_shape(custom_shape); |
|---|
| 95 | 95 | return NULL; |
|---|
| 96 | 96 | } |
|---|
| 97 | | |
|---|
| 98 | | if ((custom_shape->per_frame_init_eqn_tree = |
|---|
| | 97 | |
|---|
| | 98 | if ((custom_shape->per_frame_init_eqn_tree = |
|---|
| 99 | 99 | create_splaytree(compare_string, copy_string, free_string)) == NULL) { |
|---|
| 100 | 100 | free_custom_shape(custom_shape); |
|---|
| … | … | |
| 126 | 126 | if ((param = new_param_double("b", P_FLAG_NONE, &custom_shape->b, NULL, 1.0, 0.0, .5)) == NULL){ |
|---|
| 127 | 127 | free_custom_shape(custom_shape); |
|---|
| 128 | | return NULL; |
|---|
| | 128 | return NULL; |
|---|
| 129 | 129 | } |
|---|
| 130 | 130 | |
|---|
| … | … | |
| 166 | 166 | if ((param = new_param_double("border_b", P_FLAG_NONE, &custom_shape->border_b, NULL, 1.0, 0.0, .5)) == NULL){ |
|---|
| 167 | 167 | free_custom_shape(custom_shape); |
|---|
| 168 | | return NULL; |
|---|
| | 168 | return NULL; |
|---|
| 169 | 169 | } |
|---|
| 170 | 170 | |
|---|
| … | … | |
| 206 | 206 | if ((param = new_param_double("b2", P_FLAG_NONE, &custom_shape->b2, NULL, 1.0, 0.0, .5)) == NULL){ |
|---|
| 207 | 207 | free_custom_shape(custom_shape); |
|---|
| 208 | | return NULL; |
|---|
| | 208 | return NULL; |
|---|
| 209 | 209 | } |
|---|
| 210 | 210 | |
|---|
| … | … | |
| 218 | 218 | return NULL; |
|---|
| 219 | 219 | } |
|---|
| 220 | | |
|---|
| | 220 | |
|---|
| 221 | 221 | if (insert_param(param, custom_shape->param_tree) < 0) { |
|---|
| 222 | 222 | free_custom_shape(custom_shape); |
|---|
| … | … | |
| 323 | 323 | return NULL; |
|---|
| 324 | 324 | } |
|---|
| 325 | | |
|---|
| | 325 | |
|---|
| 326 | 326 | if ((param = new_param_double("tex_ang", P_FLAG_NONE, &custom_shape->tex_ang, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) { |
|---|
| 327 | 327 | free_custom_shape(custom_shape); |
|---|
| … | … | |
| 410 | 410 | |
|---|
| 411 | 411 | /* End of parameter loading. Note that the read only parameters associated |
|---|
| 412 | | with custom shapes (ie, sample) are global variables, and not specific to |
|---|
| | 412 | with custom shapes (ie, sample) are global variables, and not specific to |
|---|
| 413 | 413 | the custom shape datastructure. */ |
|---|
| 414 | 414 | |
|---|
| … | … | |
| 476 | 476 | destroy_param_db_tree_shape(custom_shape->param_tree); |
|---|
| 477 | 477 | destroy_per_frame_init_eqn_tree_shape(custom_shape->per_frame_init_eqn_tree); |
|---|
| 478 | | |
|---|
| | 478 | |
|---|
| 479 | 479 | free(custom_shape); |
|---|
| 480 | 480 | |
|---|
| … | … | |
| 490 | 490 | if (preset == NULL) |
|---|
| 491 | 491 | return NULL; |
|---|
| 492 | | |
|---|
| | 492 | |
|---|
| 493 | 493 | if ((custom_shape = splay_find(&id, preset->custom_shape_tree)) == NULL) { |
|---|
| 494 | | |
|---|
| | 494 | |
|---|
| 495 | 495 | if (CUSTOM_SHAPE_DEBUG) { printf("find_custom_shape: creating custom shape (id = %d)...", id);fflush(stdout);} |
|---|
| 496 | | |
|---|
| | 496 | |
|---|
| 497 | 497 | if (create_flag == FALSE) { |
|---|
| 498 | 498 | if (CUSTOM_SHAPE_DEBUG) printf("you specified not to (create flag = false), returning null\n"); |
|---|
| 499 | 499 | return NULL; |
|---|
| 500 | 500 | } |
|---|
| 501 | | |
|---|
| | 501 | |
|---|
| 502 | 502 | if ((custom_shape = new_custom_shape(id)) == NULL) { |
|---|
| 503 | 503 | if (CUSTOM_SHAPE_DEBUG) printf("failed...out of memory?\n"); |
|---|
| 504 | 504 | return NULL; |
|---|
| 505 | 505 | } |
|---|
| 506 | | |
|---|
| | 506 | |
|---|
| 507 | 507 | if (CUSTOM_SHAPE_DEBUG) { printf("success.Inserting..."); fflush(stdout);} |
|---|
| 508 | | |
|---|
| | 508 | |
|---|
| 509 | 509 | if (splay_insert(custom_shape, &custom_shape->id, preset->custom_shape_tree) < 0) { |
|---|
| 510 | 510 | if (CUSTOM_SHAPE_DEBUG) printf("failed, probably a duplicated!!\n"); |
|---|
| … | … | |
| 512 | 512 | return NULL; |
|---|
| 513 | 513 | } |
|---|
| 514 | | |
|---|
| | 514 | |
|---|
| 515 | 515 | if (CUSTOM_SHAPE_DEBUG) printf("done.\n"); |
|---|
| 516 | 516 | } |
|---|
| 517 | | |
|---|
| | 517 | |
|---|
| 518 | 518 | return custom_shape; |
|---|
| 519 | 519 | } |
|---|
| … | … | |
| 556 | 556 | with the following code */ |
|---|
| 557 | 557 | if ((init_cond = splay_find(param->name, interface_shape->init_cond_tree)) == NULL) { |
|---|
| 558 | | |
|---|
| | 558 | |
|---|
| 559 | 559 | /* Make sure initial condition does not exist in the set of per frame initial equations */ |
|---|
| 560 | 560 | if ((init_cond = splay_find(param->name, interface_shape->per_frame_init_eqn_tree)) != NULL) |
|---|
| 561 | 561 | return; |
|---|
| 562 | | |
|---|
| | 562 | |
|---|
| 563 | 563 | if (param->type == P_TYPE_BOOL) |
|---|
| 564 | 564 | init_val.bool_val = 0; |
|---|
| 565 | | |
|---|
| | 565 | |
|---|
| 566 | 566 | else if (param->type == P_TYPE_INT) |
|---|
| 567 | 567 | init_val.int_val = *(int*)param->engine_val; |
|---|
| … | … | |
| 574 | 574 | if ((init_cond = new_init_cond(param, init_val)) == NULL) |
|---|
| 575 | 575 | return; |
|---|
| 576 | | |
|---|
| | 576 | |
|---|
| 577 | 577 | /* Insert the initial condition into this presets tree */ |
|---|
| 578 | 578 | if (splay_insert(init_cond, init_cond->param->name, interface_shape->init_cond_tree) < 0) { |
|---|
| … | … | |
| 580 | 580 | return; |
|---|
| 581 | 581 | } |
|---|
| 582 | | |
|---|
| | 582 | |
|---|
| 583 | 583 | } |
|---|
| 584 | 584 | |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 24 | 24 | double tex_zoom; |
|---|
| 25 | 25 | double tex_ang; |
|---|
| 26 | | |
|---|
| | 26 | |
|---|
| 27 | 27 | double x; /* x position for per point equations */ |
|---|
| 28 | 28 | double y; /* y position for per point equations */ |
|---|
| … | … | |
| 68 | 68 | char per_frame_init_eqn_string_buffer[STRING_BUFFER_SIZE]; |
|---|
| 69 | 69 | /* Per point equation array */ |
|---|
| 70 | | |
|---|
| 71 | | |
|---|
| | 70 | |
|---|
| | 71 | |
|---|
| 72 | 72 | } custom_shape_t; |
|---|
| 73 | 73 | |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 73 | 73 | custom_wave_t * custom_wave; |
|---|
| 74 | 74 | param_t * param; |
|---|
| 75 | | |
|---|
| | 75 | |
|---|
| 76 | 76 | if ((custom_wave = (custom_wave_t*)malloc(sizeof(custom_wave_t))) == NULL) |
|---|
| 77 | 77 | return NULL; |
|---|
| … | … | |
| 104 | 104 | |
|---|
| 105 | 105 | /* Initialize tree data structures */ |
|---|
| 106 | | |
|---|
| 107 | | if ((custom_wave->param_tree = |
|---|
| | 106 | |
|---|
| | 107 | if ((custom_wave->param_tree = |
|---|
| 108 | 108 | create_splaytree(compare_string, copy_string, free_string)) == NULL) { |
|---|
| 109 | 109 | free_custom_wave(custom_wave); |
|---|
| … | … | |
| 111 | 111 | } |
|---|
| 112 | 112 | |
|---|
| 113 | | if ((custom_wave->per_point_eqn_tree = |
|---|
| | 113 | if ((custom_wave->per_point_eqn_tree = |
|---|
| 114 | 114 | create_splaytree(compare_int, copy_int, free_int)) == NULL) { |
|---|
| 115 | 115 | free_custom_wave(custom_wave); |
|---|
| … | … | |
| 117 | 117 | } |
|---|
| 118 | 118 | |
|---|
| 119 | | if ((custom_wave->per_frame_eqn_tree = |
|---|
| | 119 | if ((custom_wave->per_frame_eqn_tree = |
|---|
| 120 | 120 | create_splaytree(compare_int, copy_int, free_int)) == NULL) { |
|---|
| 121 | 121 | free_custom_wave(custom_wave); |
|---|
| … | … | |
| 123 | 123 | } |
|---|
| 124 | 124 | |
|---|
| 125 | | if ((custom_wave->init_cond_tree = |
|---|
| | 125 | if ((custom_wave->init_cond_tree = |
|---|
| 126 | 126 | create_splaytree(compare_string, copy_string, free_string)) == NULL) { |
|---|
| 127 | 127 | free_custom_wave(custom_wave); |
|---|
| 128 | 128 | return NULL; |
|---|
| 129 | 129 | } |
|---|
| 130 | | |
|---|
| 131 | | if ((custom_wave->per_frame_init_eqn_tree = |
|---|
| | 130 | |
|---|
| | 131 | if ((custom_wave->per_frame_init_eqn_tree = |
|---|
| 132 | 132 | create_splaytree(compare_string, copy_string, free_string)) == NULL) { |
|---|
| 133 | 133 | free_custom_wave(custom_wave); |
|---|
| … | … | |
| 135 | 135 | } |
|---|
| 136 | 136 | |
|---|
| 137 | | |
|---|
| | 137 | |
|---|
| 138 | 138 | /* Start: Load custom wave parameters */ |
|---|
| 139 | 139 | |
|---|
| … | … | |
| 160 | 160 | if ((param = new_param_double("b", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &custom_wave->b, custom_wave->b_mesh, 1.0, 0.0, .5)) == NULL){ |
|---|
| 161 | 161 | free_custom_wave(custom_wave); |
|---|
| 162 | | return NULL; |
|---|
| | 162 | return NULL; |
|---|
| 163 | 163 | } |
|---|
| 164 | 164 | |
|---|
| … | … | |
| 172 | 172 | return NULL; |
|---|
| 173 | 173 | } |
|---|
| 174 | | |
|---|
| | 174 | |
|---|
| 175 | 175 | if (insert_param(param, custom_wave->param_tree) < 0) { |
|---|
| 176 | 176 | free_custom_wave(custom_wave); |
|---|
| … | … | |
| 269 | 269 | |
|---|
| 270 | 270 | if ((param = new_param_double("sample", P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT, |
|---|
| 271 | | &custom_wave->sample, custom_wave->sample_mesh, 1.0, 0.0, 0.0)) == NULL) { |
|---|
| | 271 | &custom_wave->sample, custom_wave->sample_mesh, 1.0, 0.0, 0.0)) == NULL) { |
|---|
| 272 | 272 | free_custom_wave(custom_wave); |
|---|
| 273 | 273 | return NULL; |
|---|
| … | … | |
| 395 | 395 | return NULL; |
|---|
| 396 | 396 | } |
|---|
| 397 | | |
|---|
| | 397 | |
|---|
| 398 | 398 | /* End of parameter loading. Note that the read only parameters associated |
|---|
| 399 | | with custom waves (ie, sample) are global variables, and not specific to |
|---|
| | 399 | with custom waves (ie, sample) are global variables, and not specific to |
|---|
| 400 | 400 | the custom wave datastructure. */ |
|---|
| 401 | 401 | |
|---|
| … | … | |
| 499 | 499 | /* Argument checks */ |
|---|
| 500 | 500 | if (custom_wave == NULL) |
|---|
| 501 | | return FAILURE; |
|---|
| | 501 | return FAILURE; |
|---|
| 502 | 502 | if (gen_expr == NULL) |
|---|
| 503 | | return FAILURE; |
|---|
| | 503 | return FAILURE; |
|---|
| 504 | 504 | if (name == NULL) |
|---|
| 505 | | return FAILURE; |
|---|
| 506 | | |
|---|
| | 505 | return FAILURE; |
|---|
| | 506 | |
|---|
| 507 | 507 | if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: per pixel equation (name = \"%s\")\n", name); |
|---|
| 508 | 508 | |
|---|
| … | … | |
| 513 | 513 | return FAILURE; |
|---|
| 514 | 514 | |
|---|
| 515 | | } |
|---|
| | 515 | } |
|---|
| 516 | 516 | |
|---|
| 517 | 517 | /* Find most largest index in the splaytree */ |
|---|
| … | … | |
| 523 | 523 | /* Create the per pixel equation given the index, parameter, and general expression */ |
|---|
| 524 | 524 | if ((per_point_eqn = new_per_point_eqn(index, param, gen_expr)) == NULL) |
|---|
| 525 | | return FAILURE; |
|---|
| 526 | | if (CUSTOM_WAVE_DEBUG) |
|---|
| | 525 | return FAILURE; |
|---|
| | 526 | if (CUSTOM_WAVE_DEBUG) |
|---|
| 527 | 527 | printf("add_per_point_eqn: created new equation (index = %d) (name = \"%s\")\n", per_point_eqn->index, per_point_eqn->param->name); |
|---|
| 528 | 528 | /* Insert the per pixel equation into the preset per pixel database */ |
|---|
| 529 | 529 | if (splay_insert(per_point_eqn, &per_point_eqn->index, custom_wave->per_point_eqn_tree) < 0) { |
|---|
| 530 | | free_per_point_eqn(per_point_eqn); |
|---|
| 531 | | return FAILURE; |
|---|
| | 530 | free_per_point_eqn(per_point_eqn); |
|---|
| | 531 | return FAILURE; |
|---|
| 532 | 532 | } |
|---|
| 533 | | |
|---|
| 534 | | /* Done */ |
|---|
| | 533 | |
|---|
| | 534 | /* Done */ |
|---|
| 535 | 535 | return SUCCESS; |
|---|
| 536 | 536 | } |
|---|
| … | … | |
| 538 | 538 | per_point_eqn_t * new_per_point_eqn(int index, param_t * param, gen_expr_t * gen_expr) { |
|---|
| 539 | 539 | |
|---|
| 540 | | per_point_eqn_t * per_point_eqn; |
|---|
| 541 | | |
|---|
| 542 | | if (param == NULL) |
|---|
| 543 | | return NULL; |
|---|
| 544 | | if (gen_expr == NULL) |
|---|
| 545 | | return NULL; |
|---|
| 546 | | |
|---|
| 547 | | if ((per_point_eqn = (per_point_eqn_t*)malloc(sizeof(per_point_eqn_t))) == NULL) |
|---|
| 548 | | return NULL; |
|---|
| 549 | | |
|---|
| 550 | | |
|---|
| 551 | | per_point_eqn->index = index; |
|---|
| 552 | | per_point_eqn->gen_expr = gen_expr; |
|---|
| 553 | | per_point_eqn->param = param; |
|---|
| 554 | | return per_point_eqn; |
|---|
| | 540 | per_point_eqn_t * per_point_eqn; |
|---|
| | 541 | |
|---|
| | 542 | if (param == NULL) |
|---|
| | 543 | return NULL; |
|---|
| | 544 | if (gen_expr == NULL) |
|---|
| | 545 | return NULL; |
|---|
| | 546 | |
|---|
| | 547 | if ((per_point_eqn = (per_point_eqn_t*)malloc(sizeof(per_point_eqn_t))) == NULL) |
|---|
| | 548 | return NULL; |
|---|
| | 549 | |
|---|
| | 550 | |
|---|
| | 551 | per_point_eqn->index = index; |
|---|
| | 552 | per_point_eqn->gen_expr = gen_expr; |
|---|
| | 553 | per_point_eqn->param = param; |
|---|
| | 554 | return per_point_eqn; |
|---|
| 555 | 555 | } |
|---|
| 556 | 556 | |
|---|
| … | … | |
| 558 | 558 | void free_per_point_eqn(per_point_eqn_t * per_point_eqn) { |
|---|
| 559 | 559 | |
|---|
| 560 | | if (per_point_eqn == NULL) |
|---|
| 561 | | return; |
|---|
| 562 | | |
|---|
| 563 | | free_gen_expr(per_point_eqn->gen_expr); |
|---|
| 564 | | |
|---|
| 565 | | free(per_point_eqn); |
|---|
| 566 | | |
|---|
| 567 | | return; |
|---|
| | 560 | if (per_point_eqn == NULL) |
|---|
| | 561 | return; |
|---|
| | 562 | |
|---|
| | 563 | free_gen_expr(per_point_eqn->gen_expr); |
|---|
| | 564 | |
|---|
| | 565 | free(per_point_eqn); |
|---|
| | 566 | |
|---|
| | 567 | return; |
|---|
| 568 | 568 | } |
|---|
| 569 | 569 | |
|---|
| … | … | |
| 574 | 574 | if (preset == NULL) |
|---|
| 575 | 575 | return NULL; |
|---|
| 576 | | |
|---|
| | 576 | |
|---|
| 577 | 577 | if ((custom_wave = splay_find(&id, preset->custom_wave_tree)) == NULL) { |
|---|
| 578 | 578 | |
|---|
| … | … | |
| 629 | 629 | |
|---|
| 630 | 630 | |
|---|
| 631 | | inline void evalPerPointEqns() { |
|---|
| | 631 | inline void evalPerPointEqns() { |
|---|
| 632 | 632 | |
|---|
| 633 | 633 | int x; |
|---|
| … | … | |
| 656 | 656 | /* Evaluates a per point equation for the current custom wave given by interface_wave ptr */ |
|---|
| 657 | 657 | inline void evalPerPointEqn(per_point_eqn_t * per_point_eqn) { |
|---|
| 658 | | |
|---|
| 659 | | |
|---|
| | 658 | |
|---|
| | 659 | |
|---|
| 660 | 660 | int samples, size; |
|---|
| 661 | 661 | double * param_matrix; |
|---|
| … | … | |
| 670 | 670 | memset(param_matrix, 0, size); |
|---|
| 671 | 671 | } |
|---|
| 672 | | else |
|---|
| | 672 | else |
|---|
| 673 | 673 | param_matrix = (double*)per_point_eqn->param->matrix; |
|---|
| 674 | | |
|---|
| 675 | | for (mesh_i = 0; mesh_i < samples; mesh_i++) { |
|---|
| | 674 | |
|---|
| | 675 | for (mesh_i = 0; mesh_i < samples; mesh_i++) { |
|---|
| 676 | 676 | param_matrix[mesh_i] = eval_gen_expr(eqn_ptr); |
|---|
| 677 | 677 | } |
|---|
| 678 | | |
|---|
| | 678 | |
|---|
| 679 | 679 | /* Now that this parameter has been referenced with a per |
|---|
| 680 | 680 | point equation, we let the evaluator know by setting |
|---|
| 681 | 681 | this flag */ |
|---|
| 682 | | per_point_eqn->param->matrix_flag = 1; |
|---|
| | 682 | per_point_eqn->param->matrix_flag = 1; |
|---|
| 683 | 683 | |
|---|
| 684 | 684 | } |
|---|
| … | … | |
| 711 | 711 | with the following code */ |
|---|
| 712 | 712 | if ((init_cond = splay_find(param->name, interface_wave->init_cond_tree)) == NULL) { |
|---|
| 713 | | |
|---|
| | 713 | |
|---|
| 714 | 714 | /* Make sure initial condition does not exist in the set of per frame initial equations */ |
|---|
| 715 | 715 | if ((init_cond = splay_find(param->name, interface_wave->per_frame_init_eqn_tree)) != NULL) |
|---|
| 716 | 716 | return; |
|---|
| 717 | | |
|---|
| | 717 | |
|---|
| 718 | 718 | if (param->type == P_TYPE_BOOL) |
|---|
| 719 | 719 | init_val.bool_val = 0; |
|---|
| 720 | | |
|---|
| | 720 | |
|---|
| 721 | 721 | else if (param->type == P_TYPE_INT) |
|---|
| 722 | 722 | init_val.int_val = *(int*)param->engine_val; |
|---|
| … | … | |
| 729 | 729 | if ((init_cond = new_init_cond(param, init_val)) == NULL) |
|---|
| 730 | 730 | return; |
|---|
| 731 | | |
|---|
| | 731 | |
|---|
| 732 | 732 | /* Insert the initial condition into this presets tree */ |
|---|
| 733 | 733 | if (splay_insert(init_cond, init_cond->param->name, interface_wave->init_cond_tree) < 0) { |
|---|
| … | … | |
| 735 | 735 | return; |
|---|
| 736 | 736 | } |
|---|
| 737 | | |
|---|
| 738 | | } |
|---|
| 739 | | |
|---|
| 740 | | } |
|---|
| | 737 | |
|---|
| | 738 | } |
|---|
| | 739 | |
|---|
| | 740 | } |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 16 | 16 | int index; |
|---|
| 17 | 17 | param_t * param; |
|---|
| 18 | | gen_expr_t * gen_expr; |
|---|
| | 18 | gen_expr_t * gen_expr; |
|---|
| 19 | 19 | } per_point_eqn_t; |
|---|
| 20 | 20 | |
|---|
| … | … | |
| 86 | 86 | /* Per point equation array */ |
|---|
| 87 | 87 | gen_expr_t * per_point_eqn_array[NUM_POINT_OPS]; |
|---|
| 88 | | |
|---|
| | 88 | |
|---|
| 89 | 89 | } custom_wave_t; |
|---|
| 90 | 90 | |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 73 | 73 | double mv_dy = 0.02; |
|---|
| 74 | 74 | double mv_dx = 0.02; |
|---|
| 75 | | |
|---|
| | 75 | |
|---|
| 76 | 76 | int meshx = 0; |
|---|
| 77 | 77 | int meshy = 0; |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 97 | 97 | extern int bInvert; |
|---|
| 98 | 98 | extern int bMotionVectorsOn; |
|---|
| 99 | | extern int fps; |
|---|
| | 99 | extern int fps; |
|---|
| 100 | 100 | |
|---|
| 101 | 101 | extern double fWaveAlpha ; |
|---|
| r6ee1e19 |
rd6008a8 |
|
| 51 | 51 | double l; |
|---|
| 52 | 52 | |
|---|
| 53 | | if (gen_expr == NULL) |
|---|
| 54 | | return 0; |
|---|
| 55 | | |
|---|
| | 53 | if (gen_expr == NULL) |
|---|
| | 54 | return 0; |
|---|
| | 55 | |
|---|
| 56 | 56 | switch(gen_expr->type) { |
|---|
| 57 | | case VAL_T: |
|---|
| | 57 | case VAL_T: |
|---|
| 58 | 58 | return eval_val_expr(gen_expr->item); |
|---|
| 59 | 59 | case PREFUN_T: |
|---|
| 60 | 60 | l = eval_prefun_expr(gen_expr->item); |
|---|
| 61 | 61 | //if (EVAL_DEBUG) printf("eval_gen_expr: prefix function return value: %f\n", l); |
|---|
| 62 | | return l; |
|---|
| | 62 | & |
|---|