|
Do your assignment yourself.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Try seraching for "C Tutorials" on Google, and look at some examples u will get an idea to start-up.
|
|
|
|
|
Hi,
I managed to compile this audio recording code but the header is corrupt. I know this because I compared the header output from this program and a neat .wav file using HexEdit.
http://www.scribd.com/doc/16336997/CPP-Code
here is the code. I din't wanna put a 5 page code in this page. So uploaded to scribd.
I need to make changes to the header. Can anyone give me some direction?
Thanks
Niks
|
|
|
|
|
It is giving so much noise that the audio it is recording is very unclear.
Thanks
|
|
|
|
|
I dared to click on the link and had a look at the code. Anyway, nobody is going to debug the code for you, you'll have to do it yourself.
Alternatively, you can have a look at the several articles on this site about sound recording.
|
|
|
|
|
Thanks. I actually did look at many articles and then asked the question.
Anyways, off to work
|
|
|
|
|
<code>#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include "aviriff.h"
#include <iostream>
#include <mmsystem.h>
using namespace std;
//WAV format def
int sps = 22050; // sample per seconds
int channels = 1; //numbers of channels
int bits = 8; //Bit rate. Why does it not works with 16?
int wav_length_sec = 60; //Rec length (sec)
int WAVBUFFERLENGTH((channels * bits * sps * wav_length_sec)/8);
WAVEFORMATEX g_WavFmt = {0};
//Wave header length
int HEADERLENGTH (sizeof(RIFFLIST) + sizeof(RIFFCHUNK) + sizeof(WAVEFORMATEX) + sizeof(RIFFCHUNK));
void InitWavFmt(void)
{
g_WavFmt.wFormatTag = WAVE_FORMAT_PCM;
g_WavFmt.nChannels = 1;
g_WavFmt.nSamplesPerSec = 8000;
g_WavFmt.wBitsPerSample = 16;
g_WavFmt.nBlockAlign = g_WavFmt.nChannels * g_WavFmt.wBitsPerSample / 8;
g_WavFmt.nAvgBytesPerSec = g_WavFmt.nChannels * g_WavFmt.wBitsPerSample / 8 * g_WavFmt.nSamplesPerSec;
g_WavFmt.cbSize = 0;
/*g_WavFmt.wFormatTag = WAVE_FORMAT_PCM;
g_WavFmt.nChannels = channels;
g_WavFmt.nSamplesPerSec = sps;
g_WavFmt.wBitsPerSample = bits;
g_WavFmt.nBlockAlign = 1;
g_WavFmt.nAvgBytesPerSec = g_WavFmt.nChannels * g_WavFmt.wBitsPerSample / bits * g_WavFmt.nSamplesPerSec;*/
// g_WavFmt.nBlockAlign = g_WavFmt.nChannels * g_WavFmt.wBitsPerSample / 8;
// g_WavFmt.nAvgBytesPerSec = g_WavFmt.nChannels * g_WavFmt.wBitsPerSample / bits * g_WavFmt.nSamplesPerSec;
// g_WavFmt.nAvgBytesPerSec = g_WavFmt.nSamplesPerSec * g_WavFmt.nBlockAlign;
g_WavFmt.cbSize = 0;
}
char* AddWavHdr(char *pinBuffer, int inWavLength)
{
BYTE *pWavHdr = NULL;
RIFFLIST *pRiffWave = NULL;
RIFFCHUNK *pRiffFmt = NULL;
RIFFCHUNK *pRiffData = NULL;
char* outWavBuffer = NULL;
if (NULL == pinBuffer)
{
return NULL;
}
pWavHdr = new BYTE[HEADERLENGTH];
if ( NULL == pWavHdr)
{
return NULL;
}
else
{
memset(pWavHdr, 0, sizeof(BYTE) * HEADERLENGTH);
}
pRiffWave = (RIFFLIST*)pWavHdr;
pRiffFmt = (RIFFCHUNK*)(pRiffWave + 1);
pRiffData = (RIFFCHUNK*)(((BYTE*)(pRiffFmt + 1)) + sizeof(WAVEFORMATEX));
pRiffWave->fcc = FCC('RIFF');
pRiffWave->cb = inWavLength + HEADERLENGTH - sizeof(RIFFCHUNK);
pRiffWave->fccListType = FCC('WAVE');
pRiffFmt->fcc = FCC('fmt ');
pRiffFmt->cb = sizeof(WAVEFORMATEX);
pRiffData->fcc = FCC('data');
// pRiffData->cb = inWavLength;
memcpy(pRiffFmt + 1, &g_WavFmt, pRiffFmt->cb);
outWavBuffer = (char*)new BYTE[inWavLength+HEADERLENGTH];
if (NULL == outWavBuffer)
{
return NULL;
}
else
{
memset(outWavBuffer, 0, sizeof(BYTE) * (inWavLength + HEADERLENGTH));
}
memcpy(outWavBuffer, pWavHdr, sizeof(BYTE) * HEADERLENGTH);
memcpy(outWavBuffer + HEADERLENGTH, pinBuffer, (sizeof(BYTE) * inWavLength));
return outWavBuffer;
}
void main ()
{
HWAVEIN hWavIn;
WAVEHDR WavHdr;
char *pBuffer = NULL;
char *pWavBuffer = NULL;
MMRESULT ret;
FILE *fpPCMFile;
FILE *fpWavFile;
MMTIME MMTime = {0};
unsigned int numwritten = 0;
MMTime.wType = TIME_BYTES;
InitWavFmt();
cout << "NumDev = " << waveInGetNumDevs() << endl;
if ( waveInGetNumDevs()==0)
{
cout << "Audio device not found!\n";
exit(0);
}
ret = waveInOpen(&hWavIn, WAVE_MAPPER, &g_WavFmt, 0, 0, WAVE_FORMAT_QUERY);
if (MMSYSERR_NOERROR != ret)
{
cout << "Unsupported WAV format.\n";
exit(0);
}
ret = waveInOpen(&hWavIn, WAVE_MAPPER, &g_WavFmt, 0, 0, CALLBACK_NULL);
if (MMSYSERR_NOERROR != ret)
{
exit(0);
}
pBuffer = (char*)malloc(WAVBUFFERLENGTH);
if ( NULL != pBuffer)
{
memset(pBuffer, 0, WAVBUFFERLENGTH);
}
else
{
exit(0);
}
WavHdr.lpData = pBuffer;
WavHdr.dwBufferLength = WAVBUFFERLENGTH;
WavHdr.dwBytesRecorded = 0;
WavHdr.dwUser = 0;
WavHdr.dwFlags = 0;
WavHdr.dwLoops = 1;
WavHdr.lpNext = 0;
WavHdr.reserved = 0;
ret = waveInPrepareHeader(hWavIn,&WavHdr,sizeof(WAVEHDR));
// res=waveInPrepareHeader(hWaveIn,&WaveHeader,sizeof(WAVEHDR));
if (MMSYSERR_NOERROR != ret)
{
free(pBuffer);
exit(0);
}
ret = waveInAddBuffer(hWavIn,&WavHdr,sizeof(WAVEHDR));
if (MMSYSERR_NOERROR != ret)
{
free(pBuffer);
exit(0);
}
cout <<"Press any key to start recording...\n";
_getch();
cout << "Recording now\n";
ret = waveInStart(hWavIn);
if (MMSYSERR_NOERROR != ret)
{
free(pBuffer);
exit(0);
}
cout << "Press any key to stop Recording\n";
_getch();
waveInGetPosition(hWavIn, &MMTime, sizeof(MMTime));
waveInReset(hWavIn);
// cout << "sizeof MMTime = " << sizeof(MMTime) << endl;
waveInUnprepareHeader(hWavIn,&WavHdr,sizeof(WAVEHDR));
waveInClose(hWavIn);
/*fpPCMFile = fopen("pcm","w");
if (NULL == fpPCMFile)
{
cout <<"Creating PCM file failed\n";
free(pBuffer);
exit(0);
}
numwritten = fwrite(pBuffer, sizeof(char), MMTime.u.cb, fpPCMFile);
cout <<"Recording done, %d bytes recorded, %d bytes written: " << MMTime.u.cb << endl << " numwritten: " << numwritten;
fclose(fpPCMFile);*/
pWavBuffer = AddWavHdr(pBuffer, MMTime.u.cb);
if ( NULL == pWavBuffer)
{
cout <<"Add header failed\n";
}
else
{
fpWavFile = fopen("testfile.wav", "w");
if (NULL == fpWavFile)
{
cout <<"Creating WAV file failed\n";
}
else
{
numwritten = fwrite(pWavBuffer, sizeof(char), sizeof(BYTE) * (HEADERLENGTH + MMTime.u.cb), fpWavFile);
// cout <<"%d bytes of WAV file written\n", numwritten;
fclose(fpWavFile);
free(pWavBuffer);
}
}
free(pBuffer);
_getch();
return;
}
here is the code. May be someone can give me directions.
Thanks
|
|
|
|
|
I'm a greenhorn when it comes to Oracle and C++.
If I want to execute a simple "Select [Field1] from [table1]" bit of SQL from C++, how would I do that for Oracle?
|
|
|
|
|
JaeBeam wrote: I'm a greenhorn when it comes to Oracle and C++.
If I want to execute a simple "Select [Field1] from [table1]" bit of SQL from C++, how would I do that for Oracle?
You might want to look at the Database Articles here on CodeProject.
|
|
|
|
|
Perhaps, you may benefit from here.[^]
Or here for C only.[^]
|
|
|
|
|
Hi
I have a project which I need to modify it to support wide character. There are so many text strings in the project. Is there an easy way to do this (add "_T()")?
Best regards,
modified on Thursday, June 11, 2009 3:56 PM
|
|
|
|
|
The Find and Replace feature in Visual Studio will accept regular expressions:
Regular Expressions (Visual Studio)[^]
To search for single and double quoted literal string and replace them with the _T macro:
1.) Backup your project! I take no responsibility for the outcome.
2.) Open Find and Replace menu.
3.) Add the following text into the find box: {:q}
4.) Add the following to the replace box: _T(\1)
5.) Iterate through the matches and selectively replace your strings. I recommend avoiding the Replace All button as undo will probably not be available.
Note that #include statements and various other unwanted positive matches will occur with this method. You should make a backup of your project just in case something goes wrong.
Hope this helps,
-David Delaune
|
|
|
|
|
|
Excellent answer, David. My 5 vote to you.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi, I have some problem with sending keystroke/keystroks to a full screen game (Counter Strike Source, if it matter). What I want to do is simply send a lot of keystroke, for example so your character jump automatics while you hold down a key.
I have try to use keybd_event and SendInput, neither of them seems to work the way I want them to. Both work with menus and chat windows but have no effect in gameplay. So I can press for example 'y' and open the chat window and then let the program write there but it can't open it by itself, or no keys like jump(blankspace) and forward(w) works neither (in gameplay).
My SendKey function look like this,
void SinKey(WORD keyCode)
{
INPUT key;
key.type = INPUT_KEYBOARD;
key.ki.wVk = keyCode;
key.ki.dwFlags = 0;
key.ki.time = 0;
key.ki.wScan = 0;
key.ki.dwExtraInfo = 0;
SendInput(1,&key,sizeof(INPUT));
key.ki.dwExtraInfo = KEYEVENTF_KEYUP;
SendInput(1,&key,sizeof(INPUT));
}
and my keybd_event function look like this.
void keyPress(unsigned char keyCode)
{
keybd_event( keyCode, 0x45, KEYEVENTF_EXTENDEDKEY, 0 );
keybd_event( keyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );
}
As I said, both work in menus and for example noteopad but not in games.
Have this something with directx to do?
If you have any idea/ideas or even better a solution please let me know .
Thanks for all help I can get.
edit: pls reply in the forum becouse the email address I have here has ceased to function.
edit2: I have got a tip to use spy++ and I working on it. I will also add the solution here as soon as I find one.
modified on Thursday, June 11, 2009 7:05 PM
|
|
|
|
|
Hello!
You can use Spy++ to see what is going on under the hood when those messages are being sent to the game. Also, is the game yours or someone else (the source code is with you or not?) If you have the source for the game, you can write the keyboard events that occurs in the game to a log file and check if the correct key strokes are received or not.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi, thanks for your awnser.
Unfortunately, I don't have the source code available. But I will definitely give Spy++ a try, good idea.
|
|
|
|
|
Hello,
I am creating a linked list. I have found that the best way to develop the linked list is to have the head and tail in another structure. My products struct will be nested inside this structure. And I should be passing the list to the function for adding and deleting. I find this concept confusing.
I have implemented the initialize, add, and clean_up. However, I am not sure that I have done that correctly.
When I add a product to the list I declare some memory using calloc. But I am thinking shouldn't I be declaring the memory for the product instead. I am really confused about this adding.
Many thanks for any suggestions,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PRODUCT_NAME_LEN 128
typedef struct product_data
{
int product_code;
char product_name[PRODUCT_NAME_LEN];
int product_cost;
struct product_data_t *next;
}product_data_t;
typedef struct list
{
product_data_t *head;
product_data_t *tail;
}list_t;
void add(list_t *list, int code, char name[], int cost);
void initialize(list_t *list);
void clean_up(list_t *list);
int main(void)
{
list_t *list = NULL;
initialize(list);
add(list, 10, "Dell Inspiron", 1500);
clean_up(list);
getchar();
return 0;
}
void add(list_t *list, int code, char name[], int cost)
{
list = calloc(1, sizeof(list_t));
if(!list)
{
fprintf(stderr, "Cannot allocated memory");
exit(1);
}
if(list)
{
list->head->product_code = code;
list->head->product_cost = cost;
strncpy(list->head->product_name, name, sizeof(list->head->product_name));
list->head->product_name[127] = '/0';
}
}
void initialize(list_t *list)
{
list = NULL;
list = NULL;
}
void clean_up(list_t *list)
{
list_t *temp = NULL;
while(list)
{
temp = list->head;
list->head = list->head->next;
free(temp);
}
list = NULL;
list = NULL;
temp = NULL;
}
|
|
|
|
|
Me think you don't need the list structure, you only need the product_data structure.
in your code, you only need a pointer to the first element in the list.
This signature was proudly tested on animals.
|
|
|
|
|
steve_rm wrote: Many thanks for any suggestions,
Compare what you have to:
typedef struct product_data
{
int product_code;
char product_name[PRODUCT_NAME_LEN];
int product_cost;
product_data *next;
} product_data_t;
typedef struct list
{
product_data_t *head;
product_data_t *tail;
} list_t;
void add(list_t *l, int code, char name[], int cost)
{
product_data_t *node;
node = new product_data_t;
node->product_code = code;
node->product_cost = cost;
strcpy(node->product_name, name);
node->next = NULL;
if (l->head == NULL)
l->head = node;
if (l->tail != NULL)
l->tail->next = node;
l->tail = node;
}
void clean_up( list_t *l )
{
while (l->head != NULL)
{
product_data_t *node = l->head;
l->head = node->next;
delete node;
node = NULL;
}
}
void main(void)
{
list_t l;
l.head = NULL;
l.tail = NULL;
add(&l, 10, "Dell Inspiron", 1500);
add(&l, 11, "Dell Inspirona", 1501);
add(&l, 12, "Dell Inspironb", 1502);
add(&l, 13, "Dell Inspironc", 1503);
clean_up(&l);
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hello,
Thanks for the source. However, I had done it a similar way like that. However, I changed to having the list_t structure as I have been informed that is not good practice to have the head and tail as global and should be contained in a structure. I think this makes it more generic.
That was why I was having some problems with my source code.
Thanks,
|
|
|
|
|
A few small changes will correct that.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
steve_rm wrote: I am creating a linked list.
Is there some reason you are not using the STL list?
|
|
|
|
|
Hello,
The reason I am not using the STL list, is I am practicing C programming and wanted to get up to speed on both pointers and lists.
Thanks,
|
|
|
|
|
steve_rm wrote: ...I am practicing C programming and wanted to get up to speed on both pointers and lists.
So did you ever get a grasp on this topic?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|