Author Message

<  General tips and tricks  ~  a perl script for random music

ablablablablabla
Posted: Sat Dec 02, 2006 1:16 pm Reply with quote
Level 1 freak (n00b) Level 1 freak (n00b)
Joined: 19 Sep 2006 Posts: 40 Location: Socialism
here's a little perl script for all you hardcore computermusic people:


Code:
   #!/usr/bin/perl


$header_skip = 4;

$output_file_name = "voice.t";

$chunk_limit_max = 999999;



$chunk_limit = 1;

$chunk_min = 1;

$chunk_divider=2;

$dupe_chunk_factor = 1;

$dupe_sample_factor = 2;

$random_multiplier = 1;



$sample_output_limit = 10000000;



$main_loop_limit = 100;

$current_sample_output = 0;





&open_output;

&read_directory;

&main_loop;







sub main_loop {
                $mlx =1;

                $current_sample_output=1;



              while($mlx <=  $main_loop_limit)
                     {

                     print "Main Loop $mlx of $main_loop_limit\n" ;
                     print "Sample $current_sample_output of $sample_output_limit\n" ;

                     $mlx++;
                       
                        $chunk_limit=$chunk_limit++*2;

                        $chunk_min=$chunk_min++*1.5;

                        $chunk_divider++;

                        $dupe_chunk_factor=int(sin($dupe_chunk_factor++));

                        $dupe_sample_factor++;

                        $random_multiplier++;


                         &pick_audio_file_at_random;

                        &pick_audio_proc_at_random;

                        &pick_chunk_start_at_random;

                        &pick_chunk_size_at_random;

                        &pick_chunk_dupe_at_random;

                        &pick_sample_dupe_at_random;

                        while($current_chunk_dupe_index < $dupe_chunk_times){
                                                                        &proc_audio_write_ouput;
                                                                        $current_chunk_dupe_index++;
                                                                        }
                        $current_chunk_dupe_index=0;
                     

                     
                     }
             
              &close_output_audio;
              }




sub proc_audio_write_ouput{

   &open_current_audio_file;

   $current_sample_index=1;
   $current_chunk_index=1;
   $current_dupe_index=0;
 #  $dupe_times=int(rand(5));
 
   $edit_sample_start = 0;
   $edit_sample_end=0;
   
   $fadein_index=1; 
   $fadeout_index=1;

   $fadeins=1;
   $fadein_length=100;
   $fadein_power=1;

   $fadeouts=1;
   $fadeout_length=100;
   $fadeout_power=100;
 
   
#   &pick_sample_dupe_at_random;
   
   

   while(<IN_FILE>) {chop;chop;unless(/[a-zA-Z]/){
   
   
   $current_proccessed_sample=$_;

   $current_edit_sample=$_;

   $current_edit_sample=~ s/\-//g;




   if($current_sample_index >= $current_audio_chunk_start && $current_chunk_index <= $current_audio_chunk_size){
                      if($fadein_index < $fadein_length && $fadeins == 1){

                      #print "in $current_proccessed_sample \n";

                      $current_proccessed_sample=int(($current_proccessed_sample/$fadein_length)*$fadein_index);

                      #print "out $current_proccessed_sample \n";
                     

                      $fadein_index++;

                      while($current_dupe_index <= $dupe_sample_times){  &write_audio_ouput;$current_dupe_index++;}$current_dupe_index=0;
                                                        }else{
                      while($current_dupe_index <dupe_times> $current_audio_chunk_size && $fadeouts eq 1){
                     if($fadeout_index <= $fadeout_length ){

                     $current_proccessed_sample=int(($current_proccessed_sample/$fadeout_length)*$fadeout_power);
                     
                     $fadeout_index++;$fadeout_power--;
                     
                     while($current_dupe_index <dupe_sample_times> $sample_output_limit){print "Sample Limit Reached $current_sample_output of $sample_output_limit\n" ;&close_output_audio;}
                                         
$current_sample_output++;
$current_chunk_index++;

}



sub open_current_audio_file{

open(IN_FILE,"$current_audio_file" ) || die "Can't Open $current_audio_file: $!\n";

}


sub pick_chunk_start_at_random{

$current_audio_samples=$input_audio_samples[$current_audio_file_index];
$current_audio_chunk_start=int($fadein_length+rand($current_audio_samples));

print "Picked Chunk Start of $current_audio_chunk_start from $current_audio_samples\n";

}

sub pick_chunk_dupe_at_random{


$dupe_chunk_times=1+int(rand($dupe_chunk_factor));

print "Picked Chunk dupe $dupe_chunk_times\n";

}

sub pick_sample_dupe_at_random{

$dupe_times=int(rand(5));

$dupe_sample_times=1+int(rand($dupe_sample_factor));

print "Picked Sample dupe $dupe_sample_times\n";

}

sub pick_chunk_size_at_random{



$current_audio_samples=$input_audio_samples[$current_audio_file_index];

$current_audio_chunk_size=$chunk_min+int(rand($chunk_limit));

if(($current_audio_samples+$fadein_length+$fadeout_length) <current_audio_chunk_size>.5){$audio_proc=1;}

if($x<.5){$audio_proc=0;}

print "Picked Audio Process $audio_proc\n";

}






sub open_output{

print "Opening Output File $output_file_name\n";
open(OUT,">".$output_file_name) || die "$Warning: $!\n";

}


sub close_output_audio{

print "Closing Output File $output_file_name\n";
close(OUT);
exit;

}



sub read_directory {

                   $x=0;
                   while (</txt>) {
                                    unless($_ eq "") {$input_audio_files[$x] = $_;}
                                    print "$input_audio_files[$x]\n";$x++;
                                    }

                   $file_count=$x;
                   print "Number of files $file_count\n";


                   $y=0;

                   while ($y <= $file_count){

                          $current_sample=1;

                          $PEAK=0;

                          unless($input_audio_files[$y] eq "") {
                          print "Reading $input_audio_files[$y]\n";

                          open(FILE, $input_audio_files[$y] ) || die "Can't Open Input Audio File: $!\n";
                         
                          while(<FILE>) {
                          unless(/[a-zA-Z]/){$current_sample++; chop;if($_ > $PEAK){$PEAK = $_;}}
                                       }

                          $input_audio_peaks[$y] = $PEAK;
                          $input_audio_samples[$y] = $current_sample;
                          print "Total Samples of $input_audio_files[$y] equals $input_audio_samples[$y]\n";
                          print "Peak of $input_audio_files[$y] = $input_audio_peaks[$y]\n";

                          unless($input_audio_files[$y] eq "") {close(SE);print "Closing $input_audio_files[$y]\n\n";}

                                                              }$y++;



                                            }


print "Finished Reading Directory\n";





}






convert your sound files to txt format (ie. raw format), invoke the script and the chopping begins!


listen to Nxfxtxex' RANDOM SONG 4



credit: xdugef

rambo
View user's profile Send private message Visit poster's website MSN Messenger
meconium
Posted: Sat Dec 02, 2006 1:53 pm Reply with quote
Level 5 freak (scholar) Level 5 freak (scholar)
Joined: 19 Sep 2006 Posts: 431 Location: Cph SW
why all the white noise?
View user's profile Send private message Visit poster's website MSN Messenger
ablablablablabla
Posted: Sat Dec 02, 2006 2:26 pm Reply with quote
Level 1 freak (n00b) Level 1 freak (n00b)
Joined: 19 Sep 2006 Posts: 40 Location: Socialism
why not?
View user's profile Send private message Visit poster's website MSN Messenger
meconium
Posted: Sat Dec 02, 2006 2:54 pm Reply with quote
Level 5 freak (scholar) Level 5 freak (scholar)
Joined: 19 Sep 2006 Posts: 431 Location: Cph SW
ablablablablabla wrote:
why not?


oh so it is intentional?
View user's profile Send private message Visit poster's website MSN Messenger
Lisbeth Og Bent
Posted: Sat Dec 02, 2006 6:41 pm Reply with quote
Guest
white noise kicks ass!!

Display posts from previous:  

All times are GMT + 1 Hour
Page 1 of 1
Post new topic

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum