It's so easy as VGM Logging, but there are some moments to note them.
Then get the ROM of your game. For example, I will use the ROM of Highlander (CPC).
Emulate it (choose the ROM file in your computer, type cat and then run"highland - exactly, with quote sign!).
Then choose the option File => Record YM... and give the name for your music file.
Go to the place where the music you need will be played. If it's the first music you'll meet, don't bother with beginning of logging - YM file will contain music only from beginning of it and won't record blank sound.
After your track is completed, clear the YM Logging checkbox. Check if your files are proper with the program like YM Decoder.
The only problem when you need to stop the logging in the certain place if the track goes after the previous or it's looping. If you stop logging after the end of the track you need to record, the excess music will be recorded. As for YM files, there are no programs to edit them, so keep in mind about this!
The second problem that's technically impossible to trim YM file for now, while AY can be looped to be played normally. So you'll have only files without loops. If you find the trimming way for them, describe it here. For now, just record it once without any looping - even if it's looping.
The most noticeable difference between AY and YM is the feature to contain many tracks in one file for AY, when YM is only single file for single track.