Author Topic: BASS_ChannelGetData  (Read 3390 times)

Irrational86

  • Posts: 960
BASS_ChannelGetData
« on: 24 Jul '03 - 16:57 »
Is there a way of always retrieving one kind of PCM data from BASS_ChannelGetData?? For example, I want to always retrieve 8bit or 16bit data, but the channel is a 32bit FloatingPoint channel. How can I do this?

Ian @ un4seen

  • Administrator
  • Posts: 23386
Re: BASS_ChannelGetData
« Reply #1 on: 25 Jul '03 - 13:45 »
To convert floating-point sample data to 16-bit, simply multiply each sample by 32768, and restrict the result to between -32768 and 32767. For example...
Code: [Select]
void float2short(float *src,short *dst,int count)
{
     int a;
     for (a=0;a<count;a++) {
           int b=src[a]*32768;
           if (b<-32768) b=-32768;
           else if (b>32767) b=32767;
           dst[a]=(short)b;
     }
}


For 8-bit, multiply by 128, add 128 (because 8-bit PCM is unsigned), and restrict the result to between 0 and 255.