Audio-StreamGenerator
view release on metacpan or search on metacpan
lib/Audio/StreamGenerator.pm view on Meta::CPAN
=head2 skip_fade_seconds
When 'skipping' to the next song using the L</"skip"> method (for example, after a user clicked a "next song" button on some web interface), we mix less seconds than normally, simply because mixing 5+ seconds in the middle of the old track sounds pre...
=head2 sample_rate
The amount of samples per second (both incoming & outgoing), normally this is 44100 for standard CD-quality audio.
=head2 channels_amount
Amount of audio channels, this is normally 2 (stereo).
=head2 max_vol_before_mix_fraction
This tells StreamGenerator what the minimum volume of a 'loud' sample is. It is expressed as a fraction of the maximum volume.
When mixing 2 tracks, StreamGenerator needs to find out what the last loud sample of the old track is so that it can start the next song immediately after that.
=head2 skip_silence
If enabled, audio softer than L</"min_audible_vol_fraction"> at the beginning of a track, and at the end of tracks (but within the last L</"buffer_length_seconds"> seconds) will be skipped.
=head2 min_audible_vol_fraction
Audio softer than this volume fraction at the end of a track (and within the buffer) or at the beginning of a track will be skipped, if skip_silence is enabled.
=head2 debug
Log debugging information. If the value is a code reference, the logs will be passed to that sub. Otherwise the value will be treated as a boolean. If true, logs will be printed to C<STDERR> .
=head1 METHODS
=head2 stream
$streamer->stream();
Start the actual audio stream.
=head2 get_streamer
my $streamer_sub = $streamer->get_streamer($sec_per_call);
while (1) {
$streamer_sub->();
}
Get an anonymous subroutine that will produce C<$sec_per_call> seconds of a stream when called.
C<$sec_per_call> is optional, and is by default C<1>.
Use this method instead of L</"stream"> if you want to have more control over the streaming process, for example, running the streamer inside an event loop:
use Mojo::IOLoop;
my $loop = Mojo::IOLoop->singleton;
my $streamer_sub = $streamer->get_streamer(0.5);
$loop->recurring(0.05 => $streamer_sub);
$loop->start;
Note: event loop will be blocked for up to 0.5 seconds every time the timer is done. The timer/streamer ratio should be sizeable enough for the loop to run smoothly, including the mixing process. This may vary depending on the speed of the machine wh...
=head2 skip
$streamer->skip();
Skip to the next track without finishing the current one. This can be called from the L</"run_every_second"> sub, for example after checking whether a 'skip' flag was set in a database, or whether a file exists.
=head2 get_elapsed_samples
my $elapsed_samples = $streamer->get_elapsed_samples();
print "$elapsed_samples played so far\r";
Get the amount of played samples in the current track - this can be called from the L</"run_every_second"> sub.
=head2 get_elapsed_seconds
my $elapsed_seconds = $streamer->get_elapsed_seconds();
print "now at position $elapsed_seconds of the current track\r";
Get the amount of elapsed seconds in the current track - in other words the current position in the track. This equals to C<get_elapsed_samples / sample_rate > .
( run in 1.049 second using v1.01-cache-2.11-cpan-98d9bbf8dc8 )