How to create a hidden track at the beginning of audio CD

by Yavor N. 25. June 2010 07:33

Since PrimoBurner 3.0.8 we support hidden tracks with length more than 2-3 seconds. If you look at the documentation of ICDTrack::SetPregapStart method there is the following paragraph:

While PrimoBurner guarantees the minimum pre-gap of 2 sec. at the beginning of the session it does not restrict it to the maximum of 3 sec. This way it is possible to place an arbitrary audio content in the pre-gap of the first track. Such layout creates an Audio CD with the so called "hidden track" because normally the only way to play it is by manual rewinding before the start of track #1. Warning: Specifying the first track pre-gap to be longer than 3 sec. (GetStart() - GetPregapStart() > 75) violates the Audio CD standard. Some computer drives are known to have problems recognizing such Audio CDs.

The following code demonstrates the creation of an audio CD with one track where the first 23 seconds of that track form the ‘hidden’ track:

IAudioInput* AddFileInput(IAudioCD* pAudio, char_t* pFilePath)

{

      IAudioInput* ain = Library::CreateAudioInput();
      ain->SetFilePath(pFilePath);
      bool_t res = pAudio->GetAudioInputsRef()->Add(ain);
      // check the value of res variable
      ain->Release(); // leaves AudioCD to be the single owner the IAudioInput instance
      return ain;
}


void
WriteToCD_HiddenTrack_Simple(IAudioCD *pAudio)
{
      // the number of seconds to be 'hidden' in the first audio track
      int hiddenSeconds = 23;

     
// pFilePath should bet set to the name of the audio file that will be written on the new audio CD
      #if PRIMO_UTF8
            char_t *pFilePath = (char_t *)"my_file.wav";
      #elif PRIMO_UTF16
            char_t *pFilePath = L"my_file.wav";
      #endif
      AddFileInput(pAudio, pFilePath);
      // calculate the length of the first audio track
      int32_t len1 = audio->GetInputLength(audio->GetAudioInputsRef()->GetItemRef(0));

      ICDSession* pSession = Library::CreateCDSession();
      pSession->SetType(ST_CDDA);
      int32_t pos = 0;

      ICDTrack* pTrack = Library::CreateCDTrack();
      pTrack->SetType(TT_AUDIO);
      // set index 0 of the first track
      pTrack->SetPregapStart(0);
      // set index 1 of the first track
      // the data written in the zone between index 0 and index 1 will be 'hidden'
      pTrack->SetStart(hiddenSeconds * 75);
      pos = len1 - 1;
      pTrack->SetEnd(pos);
      pTrack->SetPostgapEnd(pos);
      pSession->GetTracksRef()->Add(pTrack);
      pTrack->Release();

      audio->SetCDSession(pSession);
      pSession->Release();

      bool_t ret = audio->WriteToCD();
      // check the value of ret variable

      audio->Release();
}

Please note that ICDSession is created manually because the hidden section must be set explicitly.

Tags: ,

PrimoBurner