I thought that there was a more precise way that waiting for the Meta Data change.
Because it's sometimes 5 seconds difference.
Is this difference allways the same, or depending on the station?
Due to buffering, there will be some difference between when the metadata is received and when its position is atually heard. You could compensate for that in the "songstart" value. It isn't possible to know exactly how much decoded PCM data the buffered encoded data will produce, but you could estimate that using the stream's bitrate. For example, something like this...
QWORD delay=BASS_StreamGetFilePosition(channel, BASS_FILEPOS_DOWNLOAD) // downloading position
-BASS_StreamGetFilePosition(channel, BASS_FILEPOS_CURRENT); // minus decoding position
delay=BASS_ChannelSeconds2Bytes(channel, (double)delay*8/bps); // translate it to decoded PCM bytes
songstart=BASS_ChannelGetPosition(channel, BASS_POS_DECODE|BASS_POS_BYTE)+delay; // update song start position (current decoding position + buffer delay)
Where "bps" is the stream's bitrate in bits per second.
Another question.
I'm recording the stream with the LAME encoder.
And i want to record full song from the begining.
How can i write recorded bytes with the lame and then continue to record same stream?
Should i use byte array or the BassBuffer in the DOWNLOADPROC?
Is there a particular reason that you want to use LAME, eg. change the format/bitrate? If not, I would suggest just saving the already encoded data received in the DOWNLOADPROC function.
One thing to be aware of is that metadata is very unlikely to be placed exactly on a song change in a Shoutcast stream. So if you want perfectly placed splits, you may need to make some manual adjustment of the split positions.