Thread: Channel number, need 12 bit

  1. #1

    Channel number, need 12 bit

    I'm using FMOD, and I am trying to retrieve the channel number that a sound is being played on. You find this by the return value of the function FSOUND_PlaySound(). The problem is, if I use an int it won't report the correct channel number, because the way the return value works. The first 12 bits is the channel number. I tried using a short int (which I think is 12 bit) and it doesn't work. I don't want to have to use a char, because that would limit me down to 256 channels, instead of 4096. Any ideas?

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Maybe a bitset with a specified number of bits?
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    161
    Short ints are often 16 bits. Have you tried storing it in a short and then shifting 4 places to the right?
    Code:
    short i = FSOUND_PlaySound();
    i >>= 4;

  4. #4
    Now it keeps reporting channel 256. The only way I can get it to report the correct channel number is to use a char.

    It's not that important anyway, because I'll never use more than 256 channels at once (that's a lot of sound going on at once)

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    1,619

    Re: Channel number, need 12 bit

    Originally posted by frenchfry164
    I'm using FMOD, and I am trying to retrieve the channel number that a sound is being played on. You find this by the return value of the function FSOUND_PlaySound(). The problem is, if I use an int it won't report the correct channel number, because the way the return value works. The first 12 bits is the channel number. I tried using a short int (which I think is 12 bit) and it doesn't work. I don't want to have to use a char, because that would limit me down to 256 channels, instead of 4096. Any ideas?
    The least significant 12 bits are the channel number? Just mask off the higher ones. E.g.:

    int channel = FSOUND_PlaySound(/*...*/) & 0x0FFF;

    This keeps the first 12 bits (bits 0-11) unchanged and zeros out all the higher order bits. (12-end).
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  2. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  3. Perfect number...
    By Argo_Jeude in forum C++ Programming
    Replies: 8
    Last Post: 07-12-2005, 01:53 PM
  4. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  5. Can't figure out why?
    By kwigibo in forum C Programming
    Replies: 10
    Last Post: 10-14-2001, 10:58 PM