bhavikparekh51
Member level 1
- Joined
- Feb 14, 2013
- Messages
- 37
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- mumbai
- Activity points
- 1,577
Hello
I am working on d project for Voice detection and Recording playback.... i have developed d code in code composer studio ..........the code is as follows...
the error in the code is
1) Error: can't allocate.far ,size 0004e47a (page 0) in IRAM (avail:0002fde0)
2) Error: error in input ./ debug detect_play.out not built.
The code is attached with the document or it is given below...
Block DC :
Please help me asap...I am a beginner ....
I am working on d project for Voice detection and Recording playback.... i have developed d code in code composer studio ..........the code is as follows...
the error in the code is
1) Error: can't allocate.far ,size 0004e47a (page 0) in IRAM (avail:0002fde0)
2) Error: error in input ./ debug detect_play.out not built.
The code is attached with the document or it is given below...
Block DC :
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 //Block the DC in input signal. //sample = current sample of input signal (16-bit:S15-bit) //returns sample - DC (16-bit) #define dc_coeff 10 //coefficient for the DC blocking filter int dc = 0; //current DC estimate (32-bit: SS30-bit) short block_dc(short sample) { short word1,word2; if (dc < 0) { word1 = -((-dc) >> 15); //retain the sign when DC < 0 word2 = -((-dc) & 0x00007fff); } else { word1 = dc >> 15; //word1=high-order 15-bit word of dc word2 = dc & 0x00007fff; //word2=low-order 15-bit word of dc } dc = word1 * (32768 - dc_coeff) + ((word2 * (32768 - dc_coeff)) >> 15) + sample * dc_coeff; //dc=dc*(1-coeff) +sample*coeff return sample - (dc >> 15); //return sample - dc } //Envelope detection routine /* Approximate the envelope of the signal by rectifying and filtering * sample = input sample (16-bit) * returns signal envelope (16-bit) */ #define env_coeff 4000 /* / 32768 envelope filter parameter */ int envelope = 0; /*current sample of signal envelope (32-bit) */ short detect_envelope(short sample) { short word1,word2; if (sample < 0) sample = -sample; /* rectify the signal */ word1 = envelope >> 15; /* high-order word */ word2 = envelope & 0x00007fff; /* low-order word */ envelope = (word1 * (32768 - env_coeff)) + ((word2 * (32768 - env_coeff)) >> 15) + sample * env_coeff; /* envelope = envelope*(1-coeff) + sample*coeff */ return envelope >> 15; } //detect_play.c //include appropriate support files #include "slevel.h" #define buffer_length 80000 #pragma DATA_SECTION(buffer,".far") short buffer[buffer_length]; #pragma DATA_SECTION(playback_buffer,".far") short playback_buffer[buffer_length]; int buffer_pos = 0; /* input buffer position */ int playback_pos = 0; /* playback buffer position */ int gain = 1; /* output gain */ int duration = 0; /* signal duration (playback on when duration > 0)*/ short buffer_data(short); /* function declarations */ void start_playback(int *); short playback(int *); interrupt void c_int11() /* interrupt service routine */ { short sample_data; int temp; sample_data = input_sample(); /* input data */ sample_data = buffer_data(sample_data); /* buffer input */ temp = signal_level(sample_data); /* analyze the signal level */ if (temp > 0 && duration == 0) { /* if signal detected and playback off */ duration = temp; start_playback(&duration); /* start playback */ } if (duration > 0) /* if playback is on */ sample_data = playback(&duration); /* play stored data backwards */ else sample_data = 0; /* output zero signal */ output_sample(sample_data); /* output data */ return; } void main() { comm_intr(); /* init DSK, codec, McBSP */ while(1); /* infinite loop */ } /* store the input sample in a circular buffer */ short buffer_data(short sample) { buffer[buffer_pos] = sample; /* store sample */ buffer_pos++; /* increment buffer position */ if (buffer_pos > buffer_length) buffer_pos = 0; /* buffer wrap-around */ return sample; } /* set up data structures for playback */ void start_playback(int *duration) { int i; if (*duration > buffer_length) *duration = buffer_length; /* adjust duration to <= buffer length */ playback_pos = buffer_pos; /* copy buffer pointer */ for (i=0;i<buffer_length;i++) /* copy buffer */ playback_buffer[i] = buffer[i]; } /* play back stored samples in reverse order */ short playback(int *duration) { short output; output = playback_buffer[playback_pos]; /* outputting samples in reverse */ output = gain * output; /* add gain to output */ playback_pos--; /* reducing the count to access the next sample */ (*duration)--; /* decrement duration (playback stops when duration == 0)*/ if (playback_pos < 0) playback_pos += buffer_length; /* buffer wrap-around */ return output; } // Signal level analysis routine #include "block_dc.h" #include "detect_envelope.h" /* * Analyze the characteristics of the input * returns 0 when no command is generated * returns a non-zero number of samples when detecting a signal of * large enough signal level, long enough duration and * the signal has been low for a specified period of time. * Returned integer indicates the duration of the detected signal. */ #define threshold_low 200 /* signal loss threshold */ #define threshold_high 400 /* signal detection threshold */ #define threshold_start 500 /* delay before turning the signal on */ #define threshold_stop 3000 /* delay before turning the signal off */ #define extra_samples 600 /* extra duration so signal is not chopped */ short signal_on = 0; /* "signal present" flag */ short signal_found = 0; /* "approved signal present" flag */ int duration1 = 0; /* approved signal duration */ int duration_lost = 0; /* signal loss duration */ int signal_level(short sample) { int signal; int ret = 0; signal = detect_envelope(block_dc(sample)); /* approx. signal envelope */ if (signal_on) { /* an approved signal is in progress */ duration1++; if (signal < threshold_low) { /* if the signal is low */ duration_lost++; /* accumulate signal loss duration */ if (duration_lost > threshold_stop) { /* signal lost: output duration */ ret = duration1 + extra_samples; /* return signal duration */ signal_on = 0; /* indicate the signal is lost */ signal_found = 0; duration1 = 0; } } else { duration_lost = 0; /* reset signal loss duration */ } } else if (signal_found) { /* a large enough signal was recently detected */ if (signal < threshold_low) { /* signal lost: reset duration */ signal_found = 0; duration1 = 0; } else { duration1++; if (duration1 > threshold_start) { /* signal is approved (not noise) */ signal_on = 1; duration_lost = 0; } } } else if (signal > threshold_high) { /* a large enough signal is observed */ signal_found = 1; /* start signal tracking */ duration1 = 1; } return ret; }
Attachments
Last edited by a moderator: