in reply to Tk Morse Code Ear tutor

Hello zentara and thanks for this useful program!

> Any comments or improvements welcome..

Why did you used aplay instead of using a more portable way to play sounds, as you already demonstrated to us in Tk Game Sound demo using SDL?

Did you considered to put this software on github? Well you have gigas of tk perl code to post there, if you want..

L*

UPDATE

ok, effectively SDL seems unable to produce sounds, but investigating I found an old module named Audio::Beep that seems fun to use: zentara can you hear me?

#linux quoting perl -MAudio::Beep -e 'for("--.. . -. - .- .-. .-"=~/./g){ /\./ ? beep +(1000,100) : /\-/ ? beep(1000,200) : sleep 1}' #double quoting perl -MAudio::Beep -e "for('--.. . -. - .- .-. .-'=~/./g){ /\./ ? beep +(1000,100) : /\-/ ? beep(1000,200) : sleep 1}"

if you install the module dont miss the oneliner that comes along docs: perl -MAudio::Beep -e 'beep(21 + rand 1000, rand 300) while 1'

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Tk Morse Code Ear tutor
by zentara (Cardinal) on Aug 27, 2018 at 11:39 UTC
    Update: Discipulus Audio::Beep requires /dev/dsp, and under Pulsaudio you would have to run any program using it with the padsp utility. Like:
    padsp ./my_audio_app
    I preferred to avoid any use of /dev/dsp, since PulseAudio dosn't really like it. /dev/dsp usage is going obsolete. Also here is an excerpt from the Audio::Beep pod. Requires either the beep program by Johnathan Nightingale (you should find sources in this tarball) SUID root or you to be root (that's because we need writing access to the /dev/console device). If you don't have the beep program this library will also assume some kernel constants which may vary from kernel to kernel (or not, i'm no kernel expert). So..... you need the beep program installed, you need the /dev/dsp and padsp cludges, and it's an obsolete module.

    END Update.

    I thought about using SDL but I could only find modules to play audio files, not raw PCM data. If I used premade dits and dahs audio files say in mp3 or ogg format, I would have been forced to use a Time::HiRes hack to get the audio files to play for the correct durations. A dit is one time unit, and a dah is 3 times the length of a dit. There is also the space required between the dits and dahs, programmed silence. That seemed like alot of computer overhead, since it is at millisecond accuracy. I stuck with the simpler method of directly generating the raw PCM. There may be a clever way in SDL but I couldn't find a way to avoid external sound files.

    I'm beginning to think that I may make an improvement by using syswrite, instead of print, to the pipe's $ah filehandle. This may help the buffer latency problem.


    I'm not really a human, but I play one on earth. ..... an animated JAPH
Re^2: Tk Morse Code Ear tutor (updated)
by zentara (Cardinal) on Aug 28, 2018 at 17:32 UTC
    Hi again Discipulus, I have found the correct alternative, its called Audio::PortAudio, but there still seems to be glitches getting it to run under the widely used PulseAudio system. I think my simple pipe to aplay is the easiest thing to do. If anyone can show a Audio::PortAudio script that works with the PulseAudio system, I would be grateful to see it posted. PortAudio c programs seems to work fine.

    UPDATE... duh.... I answered my own question. :-)

    #!/usr/bin/perl use warnings; use strict; use Audio::PortAudio; my $api = Audio::PortAudio::default_host_api(); my $device = $api->default_output_device; my $pi = 3.14159265358979323846; my $sine = pack "f*", map { sin( $pi * $_ / 100 ) / 8 } 0 .. 399; my $stream = $device->open_write_stream( { channel_count => 1, }, 44100, 400, 0 ); for (0 .. 10) { $stream->write($sine); }

    I'm not really a human, but I play one on earth. ..... an animated JAPH