I recently decided to figure out how to get some sound working on the Net Yaroze. After attempting to do it from the user guide which would have been just about as helpful if it had been written in Chinese, I ended up hunting around the newsgroups and members webpages for any small snippets of information or example code. To cut a long story short, after a number of frustrating hours I finally got a standard midi format file to work. An hour or two later I managed to get a WAV file to work, it was not the painless process that it should have been !
I wrote this guide to document what I have found and to hopefully help other Net Yaroze members avoid some of the frustration that I encountered when trying to get sound to work for the first time. This guide is in no way indepth it's a quick and dirty guide to getting your Net Yaroze singing !
If you haven't done so already then I strongly suggest that you download the latest documentation from SCEE as it has far more information about sound in it than the hard copy docs that come with the Yaroze.
The first thing you need to do is to convert your file into a Playstation format file. To do this you use the smf2seq program which was supplied with your Net Yaroze. See the Net Yaroze User Guide for details. This will create a file with the extension .seq which the Net Yaroze can understand.
To get this file to play you need to load some things into the Net Yaroze's memory. Firstly you need to load sound source data attribute .vh and waveform .vb parts. Luckily, two files are supplied with the Net Yaroze which you can use with SMF files, these files are std0.vh and std0.vb. You can load these into memory in two ways;
1) You can load them through siocons exactly as you would load a .tim or .tmd file. For example;
local dload std0.vb 8009000 local dload std0.vh 800f1dd0 ....
2) You can load them from the Net Yaroze boot disk. For an example of how to do this, I suggest that you check out George Bains Starfighter source code, the bits you need to look at are in 'cdread.c' and 'sound.c'. You can find the code at http://www.netyaroze-europe.com/~gbain.
Next you need to load your .SEQ file. Using siocons you just use 'local dload filename.seq address' to load it into a memory address, just like you would a .tim or .tmd. For example;
local dload mymusic.seq 800100bf0
Now we get down to some code, the first thing that you need to do is to transmit the sound source data ( the std0.vb and std0.vh files ) to the sound processing unit sound buffer. If this is not done then you will not hear anything when you attempt to play your .seq file. The function to do this is SsVabTransfer. This function is incorrectly defined in the user manual and the definition should be as follows;
short SsVabTransfer( unsigned char *vh_addr, unsigned char *vb_addr, short vabid, short i_flag )
So assuming that you have #defined your load addresses for your std0.vb and std0.vh files as 'VB_ADDR' and 'VH_ADDR' respectively our function call looks something similar to;
short vab_id; vab_id = SsVabTransfer( ( u_char * ) VH_ADDR, ( u_char * ) VB_ADDR, -1, 1 );
Ok, the next thing that we do is to get the Net Yaroze ready to play our .seq file, we do this using the SsSeqOpen function and for this we need the vab_id that we obtained using the SsVabTransfer function call above. Assuming that we have #defined the load address for the .seq file as 'SEQ_ADDR' we will have;
short seq_access_num; seq_access_num = SsSeqOpen( ( u_long * ) SEQ_ADDR, vab_id );
Note that you will need to keep both vab_id and seq_access_num for
use in further functions.
We are now ready to play our .seq file. This is done using the SsSeqPlay function. For example;
SsSeqPlay( seq_access_num, SSPLAY_PLAY, SSPLAY_INFINITY );
This will start playing our .seq file immediatly and will repeat for infinity.
The other Sseq... functions are pretty self explanatory and I am not going to go into them here. See the Net Yaroze Library Reference for more details.
When you have finished with your sounds, a couple of function calls will tidy everything up;
SsSeqStop( seq_access_num ); ///stop playing SsSeqClose( seq_access_num ); // closes seq data SsVabClose( vab_id ); // closes VAB data
Make sure that you load your .VB file into memory first, then your .VH file and then your .SEQ file. Otherwise you will find that your Net Yaroze locks up when you call SsVabTransfer.
Dealing with .wav files is pretty similar to dealing with SMF files, the main difference is that the conversion is a little more complicated and getting them to do anything is a lot less intuitive !
The first thing that you need to do is to convert your .wav file into a .vag file. To do this you will need the wav2vag program which can be found on the SCEE web site. Your .wav file must be PCM data and must be mono. If it is not then you can use the sound recorder program supplied with Windows to do this conversion.
Once you have your .vag file you must then create a .vab file. To do this you require an attribute definition file which is documented extremely poorly in the User Guide. If you download the latest version of the User Guide from the SCEE site then it gives a bit more information but quite frankly it is extremely confusing ! However, if you look in your \psx\bin directory you will find a file simple.def that is supplied with the Net Yaroze. This is the file that I use to convert my samples and quite frankly it seems to do the job. To create the .vab file you use the mkvab program, for example;
mkvab -f simple.def -o laser.vab laser.vag
This will create the file laser.vab from the file laser.vag.
The final stage in the file conversion is to split the sound source data ( .vb and .vh files ) from the .vab file. This is done using the vabsplit program. For example;
vabsplit laser
Will create the files laser.vb and laser.vh.
To be used, the sound source has to be loaded into the Net Yaroze's memory. Using siocons you do this exactly as you would load a .tim or .tmd file.
Now we can write the code that will be used within our program to actually play the sample. Firstly we need to transfer the sound source data to the SPU. As with playing .seq files this is done using SsVabTransfer.
So assuming that I have defined the load address for laser.vh as 'LASER_VH_ADDR' and laser.vb as 'LASER_VB_ADDR' my code would be as follows;
short laser_vab_id; laser_vab_id = SsVabTransfer( ( u_char * ) LASER_VH_ADDR, ( u_char * ) LASER_VB_ADDR, -1, 1 );
Now the sample is in memory and ready for use whenever I want to use it. To actually play it you use the SsUtKeyOn function as follows;
SsUtKeyOn(laser_vab_id, 0, 0, 60, 0, 127,127);
This would play the sample in it's entirety at the original pitch and tempo.
Once you have finished with your samples you can use SsVabClose to clean things up;
SsVabClose( vab_id ); // closes VAB data
Thats all for now. I will be supplying some demo code shortly.