- 论坛徽章:
- 0
|
HELLP!!! PLEASE!!!
- extern MSG_Body julius_MsgBody;
- char *mstart;
- int mlen;
- /* declare the static variables*/
- static void *p_body = NULL;
- static boolean wav_bp = FALSE;
- static int maxlenb, nowlen;
- static SP16 bpre_data[2];
- static boolean bhas_pre = FALSE;
- static int sfreq;
-
- int mybufread(void *ptr, size_t size, size_t n)
- {
- int cnt=0,i=0;
- char *t1,*t2;
-
- t1 = (char*)ptr;
- t2 = (char*)p_body;
- if(NULL == t2)
- {
- return -2;
- }
- for(i=0;i<(size*n);i++)
- {
- *t1 = *t2;
- //t1[0] = t2[0];
- t1 = t1 +1;
- t2 = t2 +1;
- if(t2 == mstart + mlen)
- {
- break;
- }
- }
-
- cnt = i;
- if(i<=0)
- {
- cnt = -2;/* read error */
- }
- if(i<(size*n-1) && i>;0)
- {
- cnt = -1;/* end of buffer */
- }
- if(cnt>;0)
- {
- (char*)p_body = (char*)p_body + cnt;
- }
-
- return(cnt);
- }
- int adin_buffer_read(SP16 *buf, int sampnum)
- {
- printf("\nadin_buffer_read START\n");
- printf("\np_body=%x.\n",(char*)p_body);
-
- int cnt;
- if (wav_bp)
- {
- printf("\n@@WAV_BP@@wav_bp=%d,bhas_pre = %d.\n",wav_bp,bhas_pre);
-
- cnt = mybufread(buf, sizeof(SP16), sampnum);
- if (nowlen + cnt >; maxlenb)
- {
- cnt = maxlenb - nowlen;
- }
- }
- else
- {
- if (bhas_pre)
- {
- buf[0] = bpre_data[0];
- buf[1] = bpre_data[1];
- bhas_pre = FALSE;
- cnt = mybufread(&(buf[2]), sizeof(SP16), sampnum - 2);
- if (cnt >; 0) cnt += 2;
- }
- else
- {
- cnt = mybufread(&buf, sizeof(SP16), sampnum);
- }
- }
-
- if (cnt <= 0)
- { /* error or EOF */
- return cnt; /* -1 ,EOF ; -2, error*/
- }
- /* all .wav data are in little endian */
- /* assume .raw data are in big endian */
- #ifdef WORDS_BIGENDIAN
- if (wav_bp) swap_sample_bytes(buf, cnt);
- #else
- if (!wav_bp) swap_sample_bytes(buf, cnt);
- #endif
- return cnt;
-
- }
- I use it like this : cnt = adin_buffer_read(&(buffer[bp]), bpmax - bp)
复制代码 |
|