Hello,
Please excuse my lack of knowledge here, but I am new to both C and
Inline (but not perl). I am attempting to create a C function which returns
a string of 16bit values that map a sinewave, simple stuff, really, but I'm
having trouble getting the proper output back from the C function.
I took some advice from the post :
http://www.mail-archive.com/[email protected]/msg01261.html where I kind of
just inverted the instructions (rather than passing a string, I wanted a
string back)... But, it still doesn't seem to work for me.
I would use arrays, but I'm doing this to minimize both CPU and memory
usage, and the size of the data will be huge (and perl arrays grow way too
big).
I'm on a Win2k platform with MSVC++ and ActivePerl 5.6.1.
Any ideas as to what I'm doing wrong?
Here's the code:
---snip---
use Inline (C => <<'END_C');
char * sinewave2(double samplerate, double frequency) {
int i;
double cnt = 0;
double incr = frequency / samplerate;
double pi = 3.1415;
short cur_val = 0;
short array[44100];
char *output;
for (i = 0; i <= 44099 ; i++) {
cur_val = sin(cnt / 2*3.1415) * 32768;
array[i] = cur_val;
cnt += incr;
}
output = (char *)array;
return(output);
}
END_C
;
my $output = sinewave2(44100,440);
# just determine if there is any data in the string..
my $len = length($output);
print("\nOut: $output : $len\n");
# print the values.
foreach (unpack("s!*",$output)) {
print("$_\n");
}
---snip---
This prints :
'Out: : 0'
Thanks in advance,
!c
C. Church
http://www.digitalKOMA.com/church/
http://www.DroneColony.com/