Lines 566-609
Link Here
|
566 |
|
566 |
|
567 |
void esd_stop_recording() {stop_recording=1;} |
567 |
void esd_stop_recording() {stop_recording=1;} |
568 |
|
568 |
|
569 |
char *esd_record_sound(int len, int rate_hz, int channelsd, int formatd) { |
569 |
/* |
570 |
int nread=-1; |
570 |
function: esd_record_sound |
571 |
char rbuf[ESD_BUF_SIZE]; /* ESD_BUF_SIZE */ |
571 |
rewritten for bug fixes and concise-ness |
572 |
char *rbuf2=rbuf; |
572 |
by Marvin Otto - sivunguvungu at cox.net |
573 |
char buffer[len+1]; |
573 |
on 9 April 2005. |
574 |
char *buffer_d=buffer; |
574 |
|
575 |
int cursor=1; |
575 |
output: returns a pointer to allocated memory or NULL if error |
576 |
int copyi; |
576 |
be sure to free it when finished. |
577 |
int space_left; |
577 |
*/ |
578 |
|
578 |
|
579 |
/* FILE *target; */ |
579 |
char *esd_record_sound(int len, int rate_hz, int channelsd, int formatd) { |
580 |
space_left=len-cursor; |
580 |
char *buffer = NULL; |
|
|
581 |
int cursor = 0; |
581 |
|
582 |
|
582 |
if (init_esd_record( rate_hz, channelsd, formatd)) { |
583 |
if (init_esd_record( rate_hz, channelsd, formatd)) { |
583 |
|
584 |
buffer = malloc(len + 1); |
584 |
/* target = fopen( "aggy.raw", "w" ); */ |
585 |
memset(buffer, 0, len + 1); // ZeroMemory |
585 |
sprintf(buffer,"%s",""); |
|
|
586 |
stop_recording=0; |
586 |
stop_recording=0; |
587 |
|
587 |
|
588 |
while (space_left>0) { |
588 |
while (!stop_recording && (cursor += record(buffer + cursor, len - cursor)) < len) |
589 |
nread=record(rbuf,ESD_BUF_SIZE); |
|
|
590 |
if (! nread) {break;} |
591 |
copyi=nread; |
592 |
if (copyi>space_left) {copyi=space_left;} |
593 |
|
594 |
/* fwrite( buf2, 1, nread, target ); */ |
595 |
strncat(buffer,rbuf,copyi); |
596 |
cursor=cursor+copyi; |
597 |
space_left=len-cursor; |
598 |
sleep(0.007); |
589 |
sleep(0.007); |
599 |
if (stop_recording==1) {break;} |
590 |
} |
600 |
} |
|
|
601 |
/* fclose(target); */ |
602 |
|
603 |
|
604 |
} else {return NULL; } |
605 |
|
591 |
|
606 |
return buffer_d; |
592 |
return buffer; |
607 |
} |
593 |
} |
608 |
|
594 |
|
609 |
|
595 |
|
Lines 667-673
Link Here
|
667 |
free(myptr); |
653 |
free(myptr); |
668 |
return written; |
654 |
return written; |
669 |
} |
655 |
} |
670 |
|
|
|
671 |
|
672 |
|
673 |
|