Author Topic: i want to get decoded 5.1 channel data from ac3 file  (Read 3217 times)

1lee123

  • Guest
Hi,

I want to get 5.1 each channel memory pointer from decoded 5.1 channel ac3 file, using bass_ac3.dll.
But I don't know how to get each channel memory pointer.
My temporary code that I am considering is below.

BASS_SetConfig(BASS_CONFIG_AC3_DYNRNG,TRUE);
BASS_Init(-1,48000,0,win,NULL)   //test source file's sampling rate is 48000Hz
BASS_StreamCreate(48000,6,BASS_SAMPLE_FLOAT,NULL,0);
BASS_AC3_StreamCreateFile(FALSE,file,0,0,BASS_AC3_DYNAMIC_RANGE);
BASS_ChannelGetInfo(chan,&info); // Check info.chans = 6
BASS_ChannelSetDSP(chan,&MyCallBack_Func,0,2);

//MyCallBack_Func code...
void CALLBACK MyCallBack_Func(HDSP handle, DWORD channel, void *buffer, DWORD length, DWORD user)
{
   float *d = (float*)buffer;
   DWORD a;
   short front_left, front_right, center, rear_left, rear_right, subwoofer;

//I want to get each channel data, but I don't know how to get each channel data.
   for (a = 0 ; a < length / 4 ; a += 6)
   {
      front_left=d[a];
      front_right=d[a+1];
      center=d[a+2];
      rear_left=d[a+3];
      rear_right=d[a+4];
      subwoofer=d[a+5];

//DSP processing... Now, I want to play only front left speaker, however all speaker played sound.

      front_right = center = rear_left = rear_right = subwoofer = 0;
      d[a] = front_left;
      d[a+1] = front_right;
      d[a+2] = center;
      d[a+3] = rear_left;
      d[a+4] = rear_right;
      d[a+5] = subwoofer;
   }
}

BASS_ChannelPlay(chan,true);

Would you give me a help?
Thank you in advance.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: i want to get decoded 5.1 channel data from ac3 file
« Reply #1 on: 14 Dec '05 - 20:26 »
Is that the entire code? It looks basically ok, but a few things...

BASS_StreamCreate(48000,6,BASS_SAMPLE_FLOAT,NULL,0);

What's this for? :)

   float *d = (float*)buffer;
   DWORD a;
   short front_left, front_right, center, rear_left, rear_right, subwoofer;

Is the sample data floating-point or 16-bit? :)

"front_left"/etc should be the same type as "d".

      front_left=d[a];
      front_right=d[a+1];
      center=d[a+2];
      rear_left=d[a+3];
      rear_right=d[a+4];
      subwoofer=d[a+5];

The channel order will be front_left, front_right, center, subwoofer, rear_left, rear_right. See the STREAMPROC docs for details.