#!/usr/bin/perl
# Copyright © 2012 Adam Nilsson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# This script decodes FLAC files into RAM up to the limit defined in
# $disk_size. The $total variable is used to count the total amount
# of data decoded and stored in RAM at any time.
# The script looks for the CPU core count in /proc/cpuinfo and starts
# as many threads of 'lame' as it finds cores. The threads are left
# waiting for files to be enqueued.
use 5.14.0;
use strict;
use warnings;
use Cwd qw(abs_path);
use File::Path qw(make_path);
use File::Basename qw(basename);
use threads qw(yield);
use threads::shared;
use Thread::Queue;
my $total :shared = 0;
my $disk_size = 1000000000;
my $end :shared;
my %decoded :shared;
my @dirs;
my %pcm :shared;
my @opts = ('-q 0', '-V 2', '--silent', '--id3v2-only');
my $q = Thread::Queue->new();
chomp(my $cpu_count = `grep -c "^processor" /proc/cpuinfo`);
if (!$ARGV[0] || ! -d $ARGV[0]) {
say "Usage: " . basename($0) .
" [FLAC directory 1] .. [FLAC directory n]";
exit;
}
foreach my $arg (@ARGV) {
my $src = abs_path($arg);
if (-d $src) {
getdirs($src);
}
}
sub gettags {
my $fn = shift;
my (%t, @mflac);
open(OUTPUT, '-|',
qq{metaflac --no-utf8-convert --export-tags-to=- "$fn"})
or die "can't run metaflac: $!";
chomp(@mflac = (