codebook generation