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

While PrimoBurner enforces a minimum pre-gap of 2 seconds at the beginning of an audio session, there is no restriction for the maximum length of the pre-gap, so it is possible to place an arbitrary audio content in the pre-gap of the first track.

Such a layout will create a CD with the a “hidden track”. It is “hidden” because normally the only way to play it is by manually seeking to before the start of the first track.

The following code uses ICDTrack to create an audio CD with a 23 second “hidden” track:

IAudioInput* AddFileInput(IAudioCD* pAudio, char_t* pFilePath)
{
    IAudioInput* ain = Library::CreateAudioInput();

        ain->SetFilePath(pFilePath);

        bool_t res = pAudio->GetAudioInputsRef()->Add(ain);

    // leaves AudioCD to be the single owner the IAudioInput instance
    ain->Release(); 

    return ain;
}

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

    AddFileInput(pAudio, L"my_file.wav");

    // 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();

    audio->Release();
}

Specifying a first track pre-gap that is longer than 3 seconds (GetStart() - GetPregapStart() > 75) violates the Audio CD standard. Some computer drives are known to have problems recognizing such Audio CDs.


Blog Comments powered by Disqus.

Search