|
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 )
#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....
|
|
|
|
|
Thank you very much for your clear explanation and the code! It has been of great help and I modified it to exactly what I wanted.
Muchas Gracias!
N.
|
|
|
|
|
Does anyone know of a way to have a program (MFC) open Microsoft Word with the Pen selected instead of the cursor?
I am working on a program with a tablet PC, and want to find a way to have Windows select the pen when it opens rather than the cursor.
Any help or suggestions would be greatly appreciated.
Thanks for anything.
|
|
|
|
|
hi give your suggestion little bit more clear .i cant get what u r asking ?
Regards
Nisha.S
|
|
|
|
|
When you typically open Word, the cursor is selected to allow for immediate typing on the keyboard.
With a tablet PC, there is also a pen selection to where the user can "draw" on the screen with the stylus, instead of the normal cursor.
I am looking for a way to open Word with this pen selected as the default rather than the cursor.
|
|
|
|
|
Hello All
I have This Code [assignment] and I want the user to control over the maximum size of CSet.
using integer pointer instead of integer array and by constructor can specifies the desired size.
<br />
#include <iostream><br />
#include <conio.h><br />
using namespace std;<br />
<br />
const int maxCard = 100;<br />
<br />
class CSet <br />
{<br />
private:<br />
int elems[maxCard];<br />
int card;<br />
<br />
public:<br />
CSet()<br />
{<br />
card = 0;<br />
<br />
return;<br />
}<br />
<br />
bool Member (const int);<br />
void AddElem (const int);<br />
void RmvElem (const int);<br />
void Copy (CSet &);<br />
bool Equal (CSet &);<br />
void intersect (CSet &,CSet &);<br />
void Union (CSet &,CSet &);<br />
void print ();<br />
<br />
};<br />
<br />
bool CSet::Member(const int elem)<br />
{<br />
for (register int i = 0;i < card;++i)<br />
if (elems[i] == elem)<br />
return true;<br />
<br />
return false;<br />
}<br />
<br />
void CSet::AddElem(const int elem)<br />
{<br />
if (Member(elem))<br />
return;<br />
<br />
if (card < maxCard)<br />
elems[card++] = elem;<br />
else<br />
cout <<"Set Overflow"<<endl;<br />
}<br />
<br />
<br />
void CSet::RmvElem(const int elem)<br />
{<br />
for (register int i = 0;i <card;++i)<br />
if (elems[i] == elem)<br />
{<br />
for (;i<card - 1;++i)<br />
elems[i] = elems[i + 1];<br />
<br />
--card;<br />
}<br />
}<br />
<br />
void CSet::Copy(CSet &set)<br />
{<br />
for (register int i =0;i<card;++i)<br />
set.elems[i] = elems[i];<br />
<br />
set.card = card;<br />
<br />
return;<br />
}<br />
<br />
bool CSet::Equal(CSet &set)<br />
{<br />
if (card != set.card)<br />
return false;<br />
<br />
for (register int i = 0;i < card;++i)<br />
if (!set.Member(elems[i]))<br />
return false;<br />
<br />
return true;<br />
}<br />
<br />
void CSet::intersect(CSet & set,CSet &res)<br />
{<br />
res.card = 0;<br />
<br />
for (register int i = 0;i <card;++i)<br />
if (set.Member(elems[i]))<br />
res.elems[res.card++] = elems[i];<br />
<br />
return;<br />
}<br />
<br />
void CSet::Union(CSet &set,CSet &res)<br />
{<br />
set.Copy(res);<br />
<br />
for (register int i=0;i <card;++i)<br />
res.AddElem(elems[i]);<br />
<br />
return;<br />
}<br />
<br />
void CSet::print()<br />
{<br />
cout <<"{";<br />
<br />
for (int i=0;i<card-1;++i)<br />
cout <<elems[i] <<",";<br />
<br />
if (card > 0)<br />
cout <<elems[card - 1];<br />
cout <<"}\n";<br />
<br />
return;<br />
}<br />
<br />
int main ()<br />
{<br />
CSet s1,s2,s3;<br />
<br />
<br />
s1.AddElem(10);<br />
s1.AddElem(20);<br />
s1.AddElem(30);<br />
s1.AddElem(40);<br />
<br />
s2.AddElem(30);<br />
s2.AddElem(50);<br />
s2.AddElem(10);<br />
s2.AddElem(60);<br />
<br />
cout <<"S1 = ";<br />
s1.print();<br />
<br />
cout <<"\nS2 = ";<br />
s2.print();<br />
cout <<endl;<br />
<br />
if (s1.Member(20))<br />
cout <<"20 is in s1"<<endl;<br />
<br />
s1.intersect(s2,s3);<br />
cout <<"s1 intersection s2=";<br />
s3.print();<br />
<br />
s1.Union(s2,s3);<br />
cout <<"s1 union s2 = ";<br />
s3.print();<br />
<br />
if (!s1.Equal(s2))<br />
cout <<"s1 !=s2"<<endl;<br />
<br />
<br />
getch ();<br />
return 0;<br />
}<br />
Thank's For all
-*-*-*-*-*-*-*-*-*
To Be Or Not To Be
(KARFER)
-*-*-*-*-*-*-*-*-*
|
|
|
|
|
Making a pointer array is basic stuff.
Look into your book where the new and delete operators are explained. Also check the chapter which explains constructor s, and the answer to your question should be clear to you.
These are the basics for programming C++ so finding the answer on your own is really best for you in this case, just read these 2 chapters.
The only hint I'll give you is to use a parameter in the constructor and the elems will be a pointer in stead of an array. Have fun finding the answer, it should be quite easy with the hints I gave you and if you read about the points I mentioned.
Regards,
Davy
|
|
|
|
|
Hello
I want to build a multiband (from 60 Hz to 3 kHZ ) audio equalizer using Directshow and sample grabber.
1. I guess I must build band-pass filters ( I will work with FIR filters) to equalize sound.
Is there any sample or advice for that task ? For ex. what should number of taps in my filter be ?
2. Let's assume that I added ParamEq DMO to my graph. How can I change parameters for this filter ?
Regards,
Akin
|
|
|
|
|
Can anyone please tell me how to correct it.
Here is the code.
std::string strASCIIText;<br />
strASCIIText = "Hø";
But when i debug that i find that value of strASCIIText becomes"Hø", can anyone please tell me how to fix that.
This happens when i want to initialize std::string with extended ascii code.
Thanks,
Mushq
|
|
|
|
|
I have already explained to you the difference between ASCII and the extended version in this post[^].
I have already explained that the these extended codes display different characters depending on the code page being utilized. The debugger is interpreting the code as UTF-8 so displays the character à on your computer. Which by the way... displays correctly on mine. Probably because the codepage I am using is Western European Windows-1252[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Once again Thanks a lot.
Regards,
Mushq
|
|
|
|
|
I created a dialog-based program, inserted a new dialog, placed a CMonthCalendar Control on the new dialog. I used the varavle wizard and created a varable for the CMonthCalendar Control. EVERYTHING worked when I checked it in Debug.
I then inserted a CListCtrl listbox, created a varable for it. I then compiled without any errors. I again checked the CMonthCalendar Control and found that I had NO hwnd, ie hwnd=00000000. Naturally upon the GetCurSel(CTime ct) I received a "Access Violation" because the first thing done is check for IsWindow() in MFC and naturally it didn't have hwnd.
Has anyone else had this or a simular problem with VS2008 Professtional?
I had no problem with this in VS2008 Professional BETA 2.
Help!!!
A C++ programming language novice, but striving to learn
|
|
|
|
|
Did you call InitCommonControlsEx() to register that control's window class?
|
|
|
|
|
Here's the code from my "theApp" objerct:
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
I don't know if this is right/wrong. It's what the wizzard put in the programs .cpp file
some more code:
CMonthCalCtrl m_cMonCtrl;
CListCtrl m_cLstCtrl;
DDX_Control(pDX, IDC_MONTHCAL, m_cMonCtrl);
DDX_Control(pDX, IDC_LOG_ENTRY_EDTLOG, m_cLstCtrl);
CTime ct;
/**************************************** ERROR *******************************/
m_cMonCtrl.GetCurSel(ct);// "Access Violation" error (no hwnd, ie hwnd=00000000)
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: InitCommonControlsEx(&InitCtrls);
DDX_Control(pDX, IDC_LOG_ENTRY_EDTLOG, m_cLstCtrl);
Just for grins, what happens if you comment out these two statements?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Larry Mills Sr wrote: ...when I checked it in Debug.
Checked what?
Larry Mills Sr wrote: Naturally upon the GetCurSel(CTime ct)
Which is called from where?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Here's the code:
CMonthCalCtrl m_cMonCtrl;
CListCtrl m_cLstCtrl;
DDX_Control(pDX, IDC_MONTHCAL, m_cMonCtrl);
DDX_Control(pDX, IDC_LOG_ENTRY_EDTLOG, m_cLstCtrl);
/**************************************** ERROR *******************************/
CTime ct;
m_cMonCtrl.GetCurSel(ct);// "Access Violation" error (no hwnd, ie hwnd=00000000)
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: m_cMonCtrl.GetCurSel(ct);// "Access Violation" error (no hwnd, ie hwnd=00000000)
Where is this called from?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Here's the code again:
void CEditLog::OnMcnSelectMonthcal(NMHDR *pNMHDR, LRESULT *pResult)
{
/**************************************** ERROR *******************************/
//LPNMSELCHANGE pSelChange = reinterpret_cast<LPNMSELCHANGE>(pNMHDR);
// TODO: Add your control notification handler code here
//m_cMonCtrl
CString str;
CString csFileName;
CString csTmp;
int nMonth, nDay, nYear;
nMonth = nDay = nYear = 0;
CTime ct;
/**************************************** ERROR *******************************/
m_cMonCtrl.GetCurSel(ct);// "Access Violation" error (no hwnd, ie hwnd=00000000)
it's called when the user selects a date in the control.
A C++ programming language novice, but striving to learn
|
|
|
|
|
I just tried this (the only control on the dialog template was a Month Calendar) with VS6 and it worked fine. I suggest you do the same, and then start re-introducing your other code until the problem comes back.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yes, I've done this several times. Still the same result if I also include a ListCtrl on the same dialog. Try doling so yourself: ie, add a listctrl then try to add column headers (Report View). either the MonthCalendar will throw an Access vioalation or the ListCtrl will!
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: Try doling so yourself: ie, add a listctrl then try to add column headers (Report View). either the MonthCalendar will throw an Access vioalation or the ListCtrl will!
Did it. No errors.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
It has to be myh bad install then. I created another dialog-based project, put a MonthCal control and ListControl on the same dialog and this time the listcontrol can up with hwnd=00000000. (It was called before the monthcal control.)
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: It has to be myh bad install then.
If you care to send me your e-mail address via private reply, I'll send you my VS project for you to compare.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Okay: larryamillssr@hughes.net
By-the-way, I'd like to send you my complete project so you can check it out.(the project for checking for the error.) The original project compiled and worked correctly under VS2008 Pro BETA 2. This retail version has given me nothing but trouble from the start. And I can't get any help from microsoft. I think it didn't load something/or didn't merge something right. I've reinstalled it 4 times with the same results.
Like I said, the program was created under VS2008 APro BETA 2 and everything worked correctly until I installed the retail version.
A C++ programming language novice, but striving to learn
|
|
|
|