INTERACTIVE SOX Interactive sox is a preliminary work. The main goal was to have an audio player which: - works interactively and is controlled with keys (not mouse) - can do smaller and bigger jumps, forward and reverse - can change speed - can change pitch _simultaneously_ with the change of speed (sox stretch effect) - can be controlled by scripts (as e.g. alsaplayer) - can use tags which later can be used for automatic processing of the file Almost all these assumptions are fulfilled by sox - except the interactivity part. The interactivity itself was easy to implement. More difficult was to handle changes of speed. It has been done by stopping the effects, changing parameters and restarting effects. On a modern 400 MHz CPU supercomputer this processing is fast enough to not to be noticed. Since Jan 2007 the patch includes GSM seeking functionality. There is no need to uncompress WAV/GSM files before using them interactively. Since Feb 2007 the program shows the time difference between now and the currently played file. The file name must be in form aaaa...-YYYYmmddHHMMSS... Another addition: gain change by +-0.5 dB, keys: f, v. On Oct 20th 2008 Chris Bagwell, the main SoX author announced on sox-users@lists.sourceforge.net list that the current official SoX version contains the the basic infrastructure for interactivity: I've just committed some minor updates to sox.c to CVS. Search for all references to INTERACTIVE. Here I've gave hints on the places in code that would need to be modified to support interactive features based on our latest framework. Its been cleaned up greatly in the last 3 years. To test it out, uncomment the line at top that have #define INTERACTIVE and recompile. Now when playing a song type ">[Enter]" to skip ahead 30 seconds and "<[Enter]" to rewind 30 seconds. "R[Enter]" is a sample of how to restart effects chain... Its just missing the logic to update the stretch effects options like your code did. You have to hit Enter after each key press because it was just a quick hack and I didn't want to figure out the right way of doing that. I'm very tempted to give official support to the fast forward and rewind feature... I'd love to use that on a daily basis. I'd be interested to hear other peoples opinions or if thats going overboard. So the way to integrate my patches is open but Chris would prefer separating the interface wthich can introduce incompatibilities with some systems SoX is running on from the control system. The curent mechanism is the direct interaction with the program, but one could use a TCP server. REMARKS To increase responsiveness one can try: echo "sox 1 256" > ! /proc/asound/card0/pcm0p/oss Another way could be adding something -r 44100 -c 4 -w on output to drain the buffers faster. I use myplay and rmplay scripts (see scripts subdirectory). The first one is a simple wrapper for interactive sox. The second playes consecutive files matching the pattern and detects Q (finish), and B (go to the previous file) commands. PICTURE sox Version 12.17.9, interactive sox v. 20070202rzm ftp://sunsite.icm.edu.pl/private/rzm/patches/ `1234567890-=<- speeds 0.5 - 3.2 f v gain +-0.5 dB up down speed +-0.1 times p[ause] ' prev speed ^L redraw <- { [ ] } -> back/forw by 1, 4, 30 s t[ag begin] T[ag end] b[egin] e[nd] of file < > prev/next tag B[egin] q[uit] prev/next file d[elete tag] up to 5 s ago Q[uit] full stop D[elete tag] last before cursor Time 0:27:08 45.2% total: 1:00:01 file time: 2:27:09 Speed: 3.0 Gain: -18.0 dB delay: 3 19:49:17 rm20070218020001.wav -> /dev/dsp __________________________________________________________________________________________ O ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KEYS Keys, position: [ ] jump -+ 1 second { } jump -+ 3 seconds <- -> jump -+ 30 s Shift <- -> jump -+ 600 s [does not work] b e jump to 0th s or to 60th s from the end Speed: Down Up change stretch -+ 0.1 PgDown PgUp change stretch -+ 0.2 ' use previous speed `1234567890-= Backspace (upper row) set stretch to 0.6 ... 3.2 p pause ^L resize redraw q Q B quit writing that character into ~/.sox/state; wrapper script should read and delete the file first then can interpret the characters e.g. as: q play next file Q quit without playing anything else B play previous file starting close to the end (30 s from the end?) Tags (for previous, current, and next file) are displayed on the screen and kept in ~/.sox/tags/filename: HH:MM:SS.S [b|e] b and e mean beginning and ending tags so we may be able to cut range automatically. Home t set beginning tag at current position End T set ending tag P,< N.> jump to previous/next tag d delete current tag (current: left behind up to 2 s) f increase gain by 0.5 dB v decrease gain by 0.5 dB TODO - problems with stretch (toooo fast) when using -r 44100 -c 4 -w on output - socket communication (instead of pipe) - output should not appear on the screen but should be redirected to the socket so we can drop ncurses dependancy to keep the Windows compatibility - frontend script communicating via the socket - implement: Option --cursor tagN start at tag number N Control: Cn written to .soxi pipe - jump to tag n - with Linux kernel 2.6 there are problems with interactivity: it looks like buffers are larger than in 2.4. I am not able to emulate 2.4 responsiveness. It looks like echo "sox 1 256" > ! /proc/asound/card0/pcm0p/oss (sox can use only 1 [buffer?] fragment of size 256 B) helps. Adding -w -c 4 options helps too (uses more space in the buffer?). - interface for other effects - configure --with-interactive switch - --with-communication and a command line option to turn it on - comments for tags; print time difference between beginning and ending tags - level meter CHANGES 20031128 start - ncurses interface 20031205 RZM specific display 20031208 working on stop-start; functions parse_eff(), start_all_eff(), resbuf_all_eff(), relbuf_all_eff(), drain_all_eff(), stop_all_eff(), checkeffect(int *pneffects), restart_all_eff() make this easier interactive() after insteadof before flow_effect_out() ST_BUFSIZ in interactive mode lowered from 8 KB to 1 KB 20031216 rzm_off_time() changes util.c functions writing to buffer instead of screen in interactive mode 20040708 -I option rzm_off_time() changes more keys, top row speed scale making both -DINTERACTIVE and -I working 2005xxxx separate interactive.[ch] #define ST_BUFSIZ 128 wav.c - preliminary work on seekable GSM 20050528 - ported to CVS sox 20050207 (discovered that sound split into 2 or 4 channels loses beginnings of buffer [?]) - added communication interface via ~/.soxi The key as in src/interactive.c:interactive() can be sent via the ~/.soxi pipe. The codes are available in /usr/include/curses.h . E.g. #define KEY_RIGHT 0405 /* right-arrow key */ can be sent with echo interpreting octal codes (0405 == 0x105, bytes in octal: 01 05, also note swapped bytes): echo -n '\05\01' >> ~/.soxi Alternative way: cat << EOF | uudecode >> ~rzm/.soxi begin-base64 644 - BQE= ==== EOF - added pause ("p", echo -n 'p\0') 20050912 Chris Bagwell likes my patch 20050917 - repatching current version of sox - more general name for error messages buffering (CB request) 200510xx tagging 20061230 - 20070103 GSM seeking; myplay and rmplay included 20070107 tag_display_not_beinteractive.patch - -DINTERACTIVE crashing without -I option 20070202, 20070203, 20070208 interactive-print-delay.patch - printing the time difference for files with names in aaaa...-YYYYmmddHHMMSS... format 20070221 vol effect; scripts changes; preliminary support for start without any effects; short keys description on the screen; print PAUSE The program contains embedded start stretch and gain values. If the interactive sox starts with effects (manually or via myplay script) the values should match the compiled in numbers to make the program behaviour consistent. .