Yikes,
When i try and unpack the 16bit sound value right after i pack it, i get a value which is incorrect if the initial value is less than zero. Basically, the unpack("v",...) is not working correctly. Any advice would be appreciated.
I want to unpack the value so i can use it when i read in sound. I use this code only to illustrate. This program outputs two different numbers if the initial value of v is below zero. I need it to output the same numbers so i know i am reading the sound file correctly.
use Win32::Sound;
# Create the object
my $WAV = new Win32::Sound::WaveOut(44100, 16, 1);
my $data = "";
my $counter = 0;
my $increment = 440/44100;
# Generate 44100 samples ( = 1 second)
for my $i (1..44100) {
# Calculate the pitch
# (range 0..65335 for 16 bits)
$v = int(sin($counter/2*3.14) * (65335/2));
#signed integer (v) range -32768 <-> 32767
print "$v = ".unpack("v",pack("v", $v))."\n";
$data .= pack("v", $v);
$counter += $increment;
}
$WAV->Load($data); # get it
$WAV->Write(); # hear it
1 until $WAV->Status(); # wait for completion
$WAV->Save("16.wav"); # write to disk
$WAV->Unload(); # drop it
exit;
thanks to all for help and for reading.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.