[LAD] Cli sound file player requirements

Fons Adriaensen fons at linuxaudio.org
Sun May 9 23:41:05 CEST 2021

On Sun, May 09, 2021 at 02:55:51PM +0100, John Murphy wrote:

> I need a command line sound file player which I can somehow control,
> while playing, to go immediately to a new position in the same file
> and keep playing without missing a beat. And a way to pause/continue.

Zita-jacktools has a Python class which is an audio file player (via
Jack of course). You can control it directly from a Python prompt,
or add some code to provide a simple user interface, or have it
controlled by anything that Python can interface with.

This is the class definition:

class JackPlayer(JackClient):

    Multichannel audio file player, with high quality resampling.
    Supports up to 100 channels. 
    STOPPED = 10
    STOPLOC = 11
    PLAYING = 12
    PLAYLOC = 13
    ENDFILE = 14

    def __init__(self, nchan, client_name, server_name = None) :
        Create a new JackPlayer instance with 'nchan' outputs.

        The result should be checked using get_state().
        The optional 'server_name' allows to select between running
        self._jplayer, base = jackplayer_ext.makecaps (self, client_name, server_name, nchan)

    def get_position (self) :
        Return state, file position.

        Additional states are:

        STOPPED = 10    Player is active but stopped.
        STOPLOC = 11    Waiting for locate() to finish.    
        PLAYING = 12    Player is playing the audiofile.
        PLAYLOC = 13    Waiting for locate(), play when ready.
        ENDFILE = 14    Player stopped at end of file.

        The file position is in frames at the audio file sample rate.
        return jackplayer_ext.get_posit (self._jplayer)

    def silence(self) :
        Goto the SILENCE state.

        In this state the player outputs silence and does not respond to any
        transport commands. Use this state to connect or disconnect ports,
        and to open or close audio files.
        return jackplayer_ext.set_state (self._jplayer, JackClient.SILENCE)

    def stop(self) :
        Stop playback with transport commands enabled.
        return jackplayer_ext.set_state (self._jplayer, JackPlayer.STOPPED)

    def play(self) :
        Start playback.
        return jackplayer_ext.set_state (self._jplayer, JackPlayer.PLAYING)

    def set_gain(self, gain, time = 0) :
        Set playback gain in dB.

        Gain will change smoothly to the given value in 'time'
        seconds. Values less than -150 dB will result in a complete
        mute. The initial gain is 0 dB.
        return jackplayer_ext.set_gain (self._jplayer, gain, time)

    def locate(self, posit) :
        Locate to position in frames at the audio file sample rate.

        This can be used while stopped or while playing. If used in
        PLAYING state, playback resumes when at least one second or
        all remaining audio has been buffered.
        return jackplayer_ext.set_posit (self._jplayer, posit)

    def open_file(self, name) :  
        Open an audio file. Player must be in SILENCE state.
        Returns zero on success, non-zero otherwise.
        return jackplayer_ext.open_file (self._jplayer, name)

    def close_file(self) :  
        Close the current audio file. Player must be in SILENCE state.
        Returns zero on success, non-zero otherwise.
        return jackplayer_ext.close_file (self._jplayer)

    def get_file_info(self) :
        Returns channels, sample rate, lenght in frames.
        return jackplayer_ext.get_file_info (self._jplayer)


More information about the Linux-audio-dev mailing list