I found the resolution of the above problem. It works though it isn’t very comfortable.
1. I open a WAV file using vim -b track.wav command. It’s important to use a binary mode because in regular mode vim adds one character at the end of the file (A0 – newline).
2. I run the external filter to convert to hexadecimal mode:
3. The filtered file looks like:
Code:
0000000: 5249 4646 44d4 e702 5741 5645 666d 7420 RIFFD...WAVEfmt
0000010: 1000 0000 0100 0200 44ac 0000 10b1 0200 ........D.......
0000020: 0400 1000 6461 7461 20d4 e702 a456 c137 ....data ....V.7
0000030: 6666 8432 8460 3a3b 9c50 1f25 a417 34fd ff.2.`:;.P.%..4.
0000040: dde3 05fd 01b8 0306 2db6 daf8 36fd c20f ........-...6...
It’s a dumb matrix. You have to edit only hexadecimal values. It’s possible to edit addresses but it produces invalid results after saving of the file.
RIFF header starts from the beginning of the file and stops four characters after “data” sequence. The garbage starts with these codes: “a456 c137”.
3a. Staying in xxd mode I defined first macro. To do it I put the cursor at the beginning of 0000030 line – at the character “66”. I assigned that macro to “z” key:
Code:
qzR0000→0000→0000→0000→0000→0000→0000→0000Esc38hjq
Arrows symbolize arrow keys. The above macro replaces characters in the current line with the null characters and jumps to the beginning of the next line.
3b. Staying in xxd mode I defined second macro. I assigned it to “a” key:
Code:
qagg9ljj30lR0000→0000Esc38hj222@zq
That macro skips the RIFF header, overwrites four last bytes in 0000020 line with null characters, jumps to the beginning of the next line and runs above “z” macro 222 times.
4. Then I exited xxd mode:
It’s important to use -r switch to return from that mode. Alone :%!xxd command runs xxd mode inside xxd mode producing a huge file full of garbage.
5. Finally I saved modified file:
Now to use these macros is enough to open WAV file in a binary mode (vim -b track.wav), switch to xxd mode (:%!xxd), run “a” macro (@a), exit xxd mode (%!xxd -r) and save file (ZZ).
***
To completely automate the work I defined one more macro:
Code:
qq:%!xxdEnter@a:%!xxd -rEnterq
After leaving vim I added in ~/.viminfo file at the end of the definition of “q” macro the sequence “ZZ”.
In result to overwrite garbage in the WAV file is enough to open it (vim -b track.wav) and run “q” macro (@q). Of course it’s possible to merge “q” and “a” macros into one big macro.
***
Vim’s xxd mode is really dumb. I don’t recommend it but in some cases it’s the only way to perform desired tasks.