Click here to Skip to main content
15,905,316 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ntdll.dll not found Pin
nisha0000013-Apr-08 19:16
nisha0000013-Apr-08 19:16 
GeneralRe: ntdll.dll not found Pin
Anu_Bala13-Apr-08 19:23
Anu_Bala13-Apr-08 19:23 
GeneralRe: ntdll.dll not found Pin
nisha0000013-Apr-08 19:44
nisha0000013-Apr-08 19:44 
GeneralRe: ntdll.dll not found Pin
Hamid_RT14-Apr-08 20:33
Hamid_RT14-Apr-08 20:33 
Questionwall message in windows Pin
vineeshV13-Apr-08 17:49
vineeshV13-Apr-08 17:49 
QuestionRe: wall message in windows Pin
David Crow24-Apr-08 10:36
David Crow24-Apr-08 10:36 
GeneralReading in 16 and 24-bit audio data into (32-bit) integer buffers Pin
TheBlindWatchmaker13-Apr-08 17:46
TheBlindWatchmaker13-Apr-08 17:46 
GeneralRe: Reading in 16 and 24-bit audio data into (32-bit) integer buffers Pin
enhzflep14-Apr-08 4:00
enhzflep14-Apr-08 4:00 
G'day,

You know sometimes pseudo code just seems too hard, hope code's okay

Something else you could consider is logical-ORing each byte as it's read into a variable of suitable length. You then bit-shift left by 8 bits and then OR in the next byte, and so on and so forth.

I can't remember the format of WAV files off-hand, I forget if they're little-endian or big-endian, but heres just one of many ways you could implement it.

Consider the code that follows. When executed, it produces the output:
Putting buffer into array of 24 bit nums
0x00010203
0x00040506
Putting buffer into array of 16 bit nums
0x00000102
0x00000304
0x00000506


Putting buffer into array of 24 bit nums - ROUND 2
0x03020100
0x06050400
Putting buffer into array of 16 bit nums - ROUND 2
0x02010000
0x04030000
0x06050000


** PORTABILITY WARNING **
I have not actually checked at runtime the sizeof different datatypes. (const int bitsInLong = 32) As well as the use of longs to store the elements of your converted and stored buffer. Long's are 64 bit in some systems.
This really must be done to avoid the code becoming broken. (it's late & I'm tired Blush | :O )
#include < stdio.h >

int main()
{
    char soundBuffer[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
    long buf24[2];
    long buf16[3];

    const int bufLen = 6;
    const int bytesIn24Bits = 3;
    const int bytesIn16Bits = 2;
    const int bitsInByte = 8;
    const int bitsInLong = 32;

    long iam16Bits, iam24Bits;

    long i, j, k;
    char *ptr;

    printf("Putting buffer into array of 24 bit nums\n");
    ptr = soundBuffer;
    k = 0;
    for (i=0; i < bufLen/bytesIn24Bits; i++)
    {
        iam24Bits = 0;
        for (j=0; j < bytesIn24Bits; j++)
        {
            iam24Bits <<= bitsInByte;
            iam24Bits |= *ptr++;
        }
        buf24[k++] = iam24Bits;
        printf("0x%08x\n", iam24Bits);
    }

    printf("Putting buffer into array of 16 bit nums\n");
    ptr = soundBuffer;
    k = 0;
    for (i=0; i < bufLen/bytesIn16Bits; i++)
    {
        iam16Bits = 0;
        for (j=0; j < bytesIn16Bits; j++)
        {
            iam16Bits <<= bitsInByte;
            iam16Bits |= *ptr++;
        }
        buf16[k++] = iam16Bits;
        printf("0x%08x\n", iam16Bits);
    }
    printf("\n\n");

    printf("Putting buffer into array of 24 bit nums - ROUND 2\n");
    ptr = soundBuffer;
    k = 0;
    for (i=0; i < bufLen/bytesIn24Bits; i++)
    {
        iam24Bits = 0;
        for (j=0; j < bytesIn24Bits; j++)
        {
            iam24Bits >>= bitsInByte;
            iam24Bits |= *ptr++<<(bitsInLong-bitsInByte);
        }
        buf24[k++] = iam24Bits;
        printf("0x%08x\n", iam24Bits);
    }

    printf("Putting buffer into array of 16 bit nums - ROUND 2\n");
    ptr = soundBuffer;
    k = 0;
    for (i=0; i < bufLen/bytesIn16Bits; i++)
    {
        iam16Bits = 0;
        for (j=0; j < bytesIn16Bits; j++)
        {
            iam16Bits >>= bitsInByte;
            iam16Bits |= *ptr++<<(bitsInLong-bitsInByte);
        }
        buf16[k++] = iam16Bits;
        printf("0x%08x\n", iam16Bits);
    }

    return 0;
}


The easiest way to make the world a better place is to refuse to help those that wreck it....

GeneralRe: Reading in 16 and 24-bit audio data into (32-bit) integer buffers Pin
TheBlindWatchmaker14-Apr-08 18:22
TheBlindWatchmaker14-Apr-08 18:22 
GeneralOpening Word with "Pen" selected instead of cursor Pin
goodoljosh198013-Apr-08 14:57
goodoljosh198013-Apr-08 14:57 
GeneralRe: Opening Word with "Pen" selected instead of cursor Pin
nisha0000013-Apr-08 19:08
nisha0000013-Apr-08 19:08 
GeneralRe: Opening Word with "Pen" selected instead of cursor Pin
goodoljosh198014-Apr-08 7:58
goodoljosh198014-Apr-08 7:58 
GeneralConvert array to pointers Pin
KARFER13-Apr-08 12:26
KARFER13-Apr-08 12:26 
GeneralRe: Convert array to pointers Pin
GDavy13-Apr-08 22:18
GDavy13-Apr-08 22:18 
GeneralAudio Equalizer With and Without DirectSound(ParamEq DMO) Pin
Akin Ocal13-Apr-08 11:38
Akin Ocal13-Apr-08 11:38 
QuestionInitializing std::string with "Extended ASCII Codes" Pin
Mushtaque Nizamani13-Apr-08 9:34
Mushtaque Nizamani13-Apr-08 9:34 
GeneralRe: Initializing std::string with "Extended ASCII Codes" Pin
Randor 13-Apr-08 14:06
professional Randor 13-Apr-08 14:06 
GeneralRe: Initializing std::string with "Extended ASCII Codes" Pin
Mushtaque Nizamani13-Apr-08 16:05
Mushtaque Nizamani13-Apr-08 16:05 
GeneralNo hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Larry Mills Sr13-Apr-08 9:03
Larry Mills Sr13-Apr-08 9:03 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Michael Dunn13-Apr-08 12:59
sitebuilderMichael Dunn13-Apr-08 12:59 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Larry Mills Sr14-Apr-08 6:02
Larry Mills Sr14-Apr-08 6:02 
QuestionRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
David Crow14-Apr-08 10:31
David Crow14-Apr-08 10:31 
QuestionRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
David Crow14-Apr-08 4:30
David Crow14-Apr-08 4:30 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Larry Mills Sr14-Apr-08 5:33
Larry Mills Sr14-Apr-08 5:33 
QuestionRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
David Crow14-Apr-08 5:39
David Crow14-Apr-08 5:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.