J
J
jov2012-06-11 16:23:21
ALSA
jov, 2012-06-11 16:23:21

Internet broadcasting of several radio stations through a bunch of alsa & darkice & libfaac?

Good day. There is a background to the question in the form of a question on Habré , which remained unanswered. Since then, I have made some progress in solving my problem, through a series of patches to darkice - now one instance of the program has exclusive access to the audio, reads all 8 channels and programmatically separates the necessary channels into the necessary codecs, and then icecast streams. Now it works with mp3/vorbis. I would very much like to achieve this with aac / aac +, in the same way, without crutches like streamTranscoderv3. So this is the essence of the question - tell me what is wrong in this code? Again, this approach works great with mp3/vorbis.

/** оригинальный код **/
unsigned int FaacEncoder :: write (  const void    * buf, unsigned int len ) throw ( Exception )
{
    if ( !isOpen() || len == 0 ) {
        return 0;
    }
    unsigned int    channels         = getInChannel();
    unsigned int    bitsPerSample    = getInBitsPerSample();
    unsigned int    sampleSize       = (bitsPerSample / 8) * channels;
    unsigned char * b                = (unsigned char*) buf;
    unsigned int    processed        = len - (len % sampleSize);
    unsigned int    nSamples         = processed / sampleSize;
    unsigned char * faacBuf          = new unsigned char[maxOutputBytes];
    int             samples          = (int) nSamples * channels;
    int             processedSamples = 0;
    /** патч **/
    unsigned char *multichannel = new unsigned char[processed * 2 / channels];
    signed char left = getLeftChannel(), right = getRightChannel();
    if (isMultichannelToStereo()) {		
    int i, j;
    for (i = 0, j = 0;i < nSamples;i++) {
      multichannel[j++] = b[i * sampleSize + (bitsPerSample / 8) * left];
      multichannel[j++] = b[i * sampleSize + (bitsPerSample / 8) * left + 1];
      multichannel[j++] = b[i * sampleSize + (bitsPerSample / 8) * right];
      multichannel[j++] = b[i * sampleSize + (bitsPerSample / 8) * right + 1];
    }
                channels = 2;
                sampleSize = (bitsPerSample / 8) * channels;
                processed = processed * 2 / channels;
                nSamples  = processed / sampleSize;
                samples = (int) nSamples * channels;
        }
         /** конец **/
         while (processedSamples < samples) {		
                int outputBytes;
                int  inSamples = samples - processedSamples < (int) inputSamples ? samples - processedSamples : inputSamples;
               /** ну и здесь разумеется тоже **/
               if (isMultichannelToStereo()) {
                       outputBytes = faacEncEncode(encoderHandle, (int32_t*) (multichannel + processedSamples/sampleSize), inSamples, faacBuf, maxOutputBytes);
               /** оригинальный код **/
               } else {
                       outputBytes = faacEncEncode(encoderHandle, (int32_t*) (b + processedSamples/sampleSize), inSamples, faacBuf, maxOutputBytes);
               }
            	getSink()->write(faacBuf, outputBytes);
            	processedSamples += inSamples;		
        }
}
PS Praise open source software!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question