Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
    0: # WavePlayBack.pl (c) 2002 C. Church
    1: # This program is distributed under the same terms
    2: # as perl its self.
    3: #----------------------------------------
    4: 
    5: use strict;
    6: use warnings;
    7: 
    8: use Win32::Sound;
    9: use Audio::Wav;
    10: 
    11: use Tk;
    12: use Tk::Toplevel;
    13: use Tk::Frame;
    14: use Tk::Label;
    15: use Tk::Button;
    16: 
    17: my $wave_file = shift;
    18: 
    19: if(!defined($wave_file)) {
    20:   die("Usage: $0 <wave file to play>\n");
    21:   }
    22: 
    23:      # our main body
    24:      
    25: my $main_window = Tk::MainWindow->new( -title => 'PlayBack Controls');
    26: 
    27: my $is_paused = 0;
    28: 
    29: my $lbl = $main_window->Label(-text => "Please Wait While $wave_file is Read...")->pack(-side => 'top');
    30: 
    31: $main_window->update();
    32: 
    33: my $datRef = read_file($wave_file);
    34: 
    35: $lbl->destroy();
    36: $main_window->update();
    37: 
    38: play_back($datRef,$main_window);
    39: 
    40: MainLoop();
    41: 
    42: exit(0);
    43: 
    44:      # subroutines
    45:      
    46: sub read_file {
    47: 
    48:  my $file = shift;
    49:  
    50:  my $wav = Audio::Wav->new();
    51:  my $readF = $wav->read($file);
    52:  
    53:  die("Unable to read $file\n") if(!defined($readF));
    54:  
    55:  my($tmpf,$data);
    56:  
    57:  $data .= $tmpf while(defined($tmpf = $readF->read_raw(4096)));
    58:  
    59:  my $hash = $readF->details();
    60:  my %tmpH = ();
    61:  
    62:  $tmpH{'data'} = $data;
    63:  $tmpH{'srate'} = $hash->{'sample_rate'};
    64:  $tmpH{'bits'} = $hash->{'bits_sample'};
    65:  $tmpH{'channels'} = $hash->{'channels'};
    66:  
    67:  return(\%tmpH);
    68: }
    69:  
    70: sub play_back {
    71: 
    72:  my $hRef = shift;
    73:  my $mw = shift;
    74: 
    75:  my $object;
    76: 
    77:  my $dat = $hRef->{'data'};
    78:  my $srate = $hRef->{'srate'};
    79:  my $bits = $hRef->{'bits'};
    80:  my $chan = $hRef->{'channels'};
    81:  
    82:  if(!defined($dat) || !defined($srate) || !defined($bits) || !defined($chan)) {
    83:      die("ERROR: [play_back] Not enough data to playback.\n");
    84:      }
    85:      
    86:  eval { $object = new Win32::Sound::WaveOut($srate,$bits,$chan); };
    87: 
    88:  if($@) {
    89:     die("WARNING: WaveOut Returned: $@\n");
    90:     }
    91: 
    92: 
    93:      $is_paused = 0;
    94: 
    95:      my $frame1 = $mw->Frame()->pack(-side => 'top');
    96:      my $frame2 = $mw->Frame()->pack(-side => 'top');
    97:      my $frame3 = $mw->Frame()->pack(-side => 'top');
    98: 
    99:      $frame1->Label(-text => "Playback Controls")->pack();
    100: 
    101:      $frame2->Button(-text => "Play", -command => sub { if($is_paused == 0) { $object->Load($dat); $object->Write(); } else { $object->Restart(); $is_paused = 1; } })->pack(-side => "left");
    102: 
    103:      $frame2->Button(-text => "Pause", -command => sub { $object->Pause(); $is_paused = 1; })->pack(-side => "left");
    104: 
    105:      $frame2->Button(-text => "Stop", -command => sub { $object->Reset(); } )->pack(-side => 'left');
    106: 
    107:      $frame2->Button(-text => "Rew", -command => sub { $object->Reset(); })->pack(-side => 'left');
    108: 
    109:      $frame3->Button(-text => "Close", -command => sub { $object->Reset(); $object->Unload(); $object->CloseDevice(); exit(0); })->pack(-side => 'top');
    110: 
    111:  return(1);
    112: }

In reply to Wave Playback Program Using Win32::Sound and Tk by lofichurch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-06-14 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.