aufnahme von wavdateien mit callback function

N

nullstring

Hallo Leute,
gerade sitze ich vor dem problem, das ich eine
Klasse schreiben muss dir mir ne Wav datei vom mikro aufnimmt und
wieder abspielt.

Mein Problem ist nun, das mir meine callbackfunction nie ein
MM_WIM_DATA liefert
und augenscheinlich auch nix aufnimmt.

Tja und wie es halt so ist, bin ein newbie was Winprogrammierung
angeht.
vielen dank schonmal


ich verwende folgenden code

Die ausgabe ist bisher:

hierher0012FF40
blub:958 //<--- ausgabe UINT uMsg in der
callbackfunktion
wimopen0
hwavein:00162A08
waveinhatgeklappt
resulstprepere0
resulstprepere0
resultaddbuffer0
resultaddbuffer0
result waveInStart0
dorthinPress any key to continue . . .



Sound.h
#pragma once



class GSound
{
public:
static BOOL CALLBACK GSound::GVoiceWaveInProc(
HWAVEIN hwi,
UINT uMsg,
DWORD dwInstance,
DWORD dwParam1,
DWORD dwParam2
);
public:
GSound(void);
public:
~GSound(void);
public:
void play(void);
public:
void record(void);
public:
void setRecordTime(int milliSec);
public:
void setBits(int bits);
public:
void setSampleRate(int sampleRate);
public:
void setChannels(int channels);
public:
// bool setFile(QString fileName);
public:
// bool createFile(QString fileName);
public:
void setPlaybackDevice(int deviceId);
public:
void setRecordDevice(int deviceId);
void printMe();
void open();
public:
MMRESULT res;
HWAVEIN hWaveIn;
PWAVEHDR header1;
PWAVEHDR header2;
PBYTE saveBuffer;
private:
PBYTE soundBuffer;
};

Die dazugehoerige
sound.cpp

#include "StdAfx.h"
#include <mmsystem.h>
#include <windows.h>
#include "Sound.h"
#include <iostream>
#define INP_BUFFER_SIZE 16384

BOOL CALLBACK GSound::GVoiceWaveInProc(HWAVEIN hwi, UINT uMsg, DWORD
dwInstance, DWORD dwParam1, DWORD dwParam2)
{

GSound* s = (GSound*) dwInstance;
std::cout << s;
std::cout << "\n";

MMRESULT result;
std::cout <<"blub:";
std::cout << uMsg;
if (uMsg==MM_WIM_OPEN)
{
std::cout << "wimopen";
return true;
}

if (uMsg==MM_WIM_DATA) // signal daten kommen
{
std::cout << "wimdata";
//Sound* pVoice=(Sound*) dwInstance;
s->printMe();
//pVoice->res=waveInUnprepareHeader(pVoice->hWaveIn,
&pVoice-
header1, sizeof(WAVEHDR));
//pVoice->GetMMResult(pVoice->res);
//pVoice->RecordFinished();

//if (pVoice->res!=MMSYSERR_NOERROR)
// return FALSE;
//else
return TRUE;
}

return TRUE;
}

GSound::GSound(void)
{
}

GSound::~GSound(void)
{
}
void GSound::eek:pen(){
}
void GSound::play(void)
{
}
void GSound::printMe(void)
{
std::cout << "juhu\n";
}
void GSound::record(void)
{
PBYTE pBuffer1;
PBYTE pBuffer2;

WAVEFORMATEX waveform;
MMRESULT result;
header1 = (PWAVEHDR)malloc(sizeof(WAVEHDR));
header2 = (PWAVEHDR)malloc(sizeof(WAVEHDR));

saveBuffer = (PBYTE) malloc(1);
pBuffer1 = (PBYTE )malloc(INP_BUFFER_SIZE);
pBuffer2 = (PBYTE )malloc(INP_BUFFER_SIZE);

waveform.wFormatTag = WAVE_FORMAT_PCM;
waveform.nChannels = 1;
waveform.nSamplesPerSec = 11025;
waveform.nAvgBytesPerSec = 11025;
waveform.nBlockAlign = 1;
waveform.wBitsPerSample = 8;
waveform.cbSize = 0;

std::cout << "hierher";
MMRESULT tmp = waveInOpen(&hWaveIn, WAVE_MAPPER, &waveform,
(DWORD)
GSound::GVoiceWaveInProc,(DWORD ) this, CALLBACK_FUNCTION);
std::cout << tmp;
std::cout << "\n";
std::cout << "hwavein:";
std::cout << hWaveIn;
std::cout << "\n";
if ( tmp == 0 ){
std::cout << "waveinhatgeklappt";
// Set up and prepare header for input
header1->lpData = (LPSTR)pBuffer1;
header1->dwBufferLength = INP_BUFFER_SIZE;
header1->dwBytesRecorded=0;
header1->dwUser = 0L;
header1->dwFlags = 0L;
header1->dwLoops = 1;
header1->lpNext = NULL;
header1->reserved =0;

header2->lpData = (LPSTR) pBuffer2;
header2->dwBufferLength = INP_BUFFER_SIZE;
header2->dwBytesRecorded=0;
header2->dwUser = 0L;
header2->dwFlags = 0L;
header2->dwLoops = 1;
header2->lpNext = NULL;
header2->reserved =0;


result = waveInPrepareHeader(
hWaveIn,header1,sizeof(WAVEHDR) );
std::cout << "resulstprepere" << result;
result = waveInPrepareHeader(
hWaveIn,header2,sizeof(WAVEHDR) );
std::cout << "resulstprepere" << result << "\n";

result = waveInAddBuffer( hWaveIn,header1,sizeof(WAVEHDR));
std::cout << "resultaddbuffer" << result << "\n";

result = waveInAddBuffer(
hWaveIn,header2,sizeof(WAVEHDR));
std::cout << "resultaddbuffer" << result << "\n";
result = waveInStart(hWaveIn);
std::cout << "result waveInStart" << result << "\n";

}
std::cout << "dorthin";
}

void GSound::setRecordTime(int milliSec)
{
}

void GSound::setBits(int bits)
{
}

void GSound::setSampleRate(int sampleRate)
{
}

void GSound::setChannels(int channels)
{
}

//bool Sound::setFile(QString fileName)
//{/
// return false;
//}

//bool Sound::createFile(QString fileName)
//{/
// return false;
//}

void GSound::setPlaybackDevice(int deviceId)
{
}

void GSound::setRecordDevice(int deviceId)
{
}


und last but not least
meine main
// GSound.cpp : Definiert den Einstiegspunkt für die
Konsolenanwendung.
//

#include "stdafx.h"
#include <iostream>
#include "sound.h"
#include "VoicePlaying.h"
#include "VoiceRecording.h"

int _tmain(int argc, _TCHAR* argv[])
{
GSound s;
s.record();
return 0;
}

Das ganze soll unter der konsole laufen.

Uber gute Dokuhinweise wuerd ich mich auch schon freuen
 
K

kwikius

nullstring wrote:

Guten Tag nullstring,

Ich kann nicht sehr gut Deutsche sprechen so ich habe machen diene
'text' in Englisch mitt diese 'cool sites'.

Aber ich kann nicht helfen? mitt diener problem . Ich denke das sie
muss gehen nach die 'microsoft newsgroup'.

http://translation2.paralink.com/

Hello people,
just I sit before problem, which I one
Class must write to you to me ne Wav datei from mikro takes up and
again passes the ball.

Now my problem never is, to me mine callbackfunction one
MM_WIM_DATA delivers
and seemingly also nothing takes up.


Well and how it is just in such a way, am newbie what Winprogrammierung

it begins.
to many thanks to schonmal


I use following code

------------------

http://babelfish.altavista.com/tr

Hello of people, straight I sit before the problem, which I must write
a class you me ne Wav file of the micro take up and again play. My
problem is now, which to me my callbackfunction never a MM_WIM_DATA
supplies with and apparently also nix takes up. Tja and like it stop
like that is, is newbie which Winprogrammierung concerns. thank you
already times I use the following code :

---------------
http://www.appliedlanguage.com/free_translation.shtml

Hello people
exactly, I sit before the problem, that I one
Class must write me ne Wav file you from the micro picks up and
passes again.

My problem now is, that never me my callbackfunction in one
MM_WIM_DATA delivers
and evidently also nothing picks up.

Well and as it is just so, is a newbie Winprogrammierung something
come on.
much thanks to already-once
I use following code

regards
Andy Little
 
O

Ondra Holub

nullstring napsal:
Hallo Leute,
gerade sitze ich vor dem problem, das ich eine
Klasse schreiben muss dir mir ne Wav datei vom mikro aufnimmt und
wieder abspielt.

Mein Problem ist nun, das mir meine callbackfunction nie ein
MM_WIM_DATA liefert
und augenscheinlich auch nix aufnimmt.

Tja und wie es halt so ist, bin ein newbie was Winprogrammierung
angeht.
vielen dank schonmal


ich verwende folgenden code

Die ausgabe ist bisher:

hierher0012FF40
blub:958 //<--- ausgabe UINT uMsg in der
callbackfunktion
wimopen0
hwavein:00162A08
waveinhatgeklappt
resulstprepere0
resulstprepere0
resultaddbuffer0
resultaddbuffer0
result waveInStart0
dorthinPress any key to continue . . .



Sound.h
#pragma once



class GSound
{
public:
static BOOL CALLBACK GSound::GVoiceWaveInProc(
HWAVEIN hwi,
UINT uMsg,
DWORD dwInstance,
DWORD dwParam1,
DWORD dwParam2
);
public:
GSound(void);
public:
~GSound(void);
public:
void play(void);
public:
void record(void);
public:
void setRecordTime(int milliSec);
public:
void setBits(int bits);
public:
void setSampleRate(int sampleRate);
public:
void setChannels(int channels);
public:
// bool setFile(QString fileName);
public:
// bool createFile(QString fileName);
public:
void setPlaybackDevice(int deviceId);
public:
void setRecordDevice(int deviceId);
void printMe();
void open();
public:
MMRESULT res;
HWAVEIN hWaveIn;
PWAVEHDR header1;
PWAVEHDR header2;
PBYTE saveBuffer;
private:
PBYTE soundBuffer;
};

Die dazugehoerige
sound.cpp

#include "StdAfx.h"
#include <mmsystem.h>
#include <windows.h>
#include "Sound.h"
#include <iostream>
#define INP_BUFFER_SIZE 16384

BOOL CALLBACK GSound::GVoiceWaveInProc(HWAVEIN hwi, UINT uMsg, DWORD
dwInstance, DWORD dwParam1, DWORD dwParam2)
{

GSound* s = (GSound*) dwInstance;
std::cout << s;
std::cout << "\n";

MMRESULT result;
std::cout <<"blub:";
std::cout << uMsg;
if (uMsg==MM_WIM_OPEN)
{
std::cout << "wimopen";
return true;
}

if (uMsg==MM_WIM_DATA) // signal daten kommen
{
std::cout << "wimdata";
//Sound* pVoice=(Sound*) dwInstance;
s->printMe();
//pVoice->res=waveInUnprepareHeader(pVoice->hWaveIn,
&pVoice-
header1, sizeof(WAVEHDR));
//pVoice->GetMMResult(pVoice->res);
//pVoice->RecordFinished();

//if (pVoice->res!=MMSYSERR_NOERROR)
// return FALSE;
//else
return TRUE;
}

return TRUE;
}

GSound::GSound(void)
{
}

GSound::~GSound(void)
{
}
void GSound::eek:pen(){
}
void GSound::play(void)
{
}
void GSound::printMe(void)
{
std::cout << "juhu\n";
}
void GSound::record(void)
{
PBYTE pBuffer1;
PBYTE pBuffer2;

WAVEFORMATEX waveform;
MMRESULT result;
header1 = (PWAVEHDR)malloc(sizeof(WAVEHDR));
header2 = (PWAVEHDR)malloc(sizeof(WAVEHDR));

saveBuffer = (PBYTE) malloc(1);
pBuffer1 = (PBYTE )malloc(INP_BUFFER_SIZE);
pBuffer2 = (PBYTE )malloc(INP_BUFFER_SIZE);

waveform.wFormatTag = WAVE_FORMAT_PCM;
waveform.nChannels = 1;
waveform.nSamplesPerSec = 11025;
waveform.nAvgBytesPerSec = 11025;
waveform.nBlockAlign = 1;
waveform.wBitsPerSample = 8;
waveform.cbSize = 0;

std::cout << "hierher";
MMRESULT tmp = waveInOpen(&hWaveIn, WAVE_MAPPER, &waveform,
(DWORD)
GSound::GVoiceWaveInProc,(DWORD ) this, CALLBACK_FUNCTION);
std::cout << tmp;
std::cout << "\n";
std::cout << "hwavein:";
std::cout << hWaveIn;
std::cout << "\n";
if ( tmp == 0 ){
std::cout << "waveinhatgeklappt";
// Set up and prepare header for input
header1->lpData = (LPSTR)pBuffer1;
header1->dwBufferLength = INP_BUFFER_SIZE;
header1->dwBytesRecorded=0;
header1->dwUser = 0L;
header1->dwFlags = 0L;
header1->dwLoops = 1;
header1->lpNext = NULL;
header1->reserved =0;

header2->lpData = (LPSTR) pBuffer2;
header2->dwBufferLength = INP_BUFFER_SIZE;
header2->dwBytesRecorded=0;
header2->dwUser = 0L;
header2->dwFlags = 0L;
header2->dwLoops = 1;
header2->lpNext = NULL;
header2->reserved =0;


result = waveInPrepareHeader(
hWaveIn,header1,sizeof(WAVEHDR) );
std::cout << "resulstprepere" << result;
result = waveInPrepareHeader(
hWaveIn,header2,sizeof(WAVEHDR) );
std::cout << "resulstprepere" << result << "\n";

result = waveInAddBuffer( hWaveIn,header1,sizeof(WAVEHDR));
std::cout << "resultaddbuffer" << result << "\n";

result = waveInAddBuffer(
hWaveIn,header2,sizeof(WAVEHDR));
std::cout << "resultaddbuffer" << result << "\n";
result = waveInStart(hWaveIn);
std::cout << "result waveInStart" << result << "\n";

}
std::cout << "dorthin";
}

void GSound::setRecordTime(int milliSec)
{
}

void GSound::setBits(int bits)
{
}

void GSound::setSampleRate(int sampleRate)
{
}

void GSound::setChannels(int channels)
{
}

//bool Sound::setFile(QString fileName)
//{/
// return false;
//}

//bool Sound::createFile(QString fileName)
//{/
// return false;
//}

void GSound::setPlaybackDevice(int deviceId)
{
}

void GSound::setRecordDevice(int deviceId)
{
}


und last but not least
meine main
// GSound.cpp : Definiert den Einstiegspunkt für die
Konsolenanwendung.
//

#include "stdafx.h"
#include <iostream>
#include "sound.h"
#include "VoicePlaying.h"
#include "VoiceRecording.h"

int _tmain(int argc, _TCHAR* argv[])
{
GSound s;
s.record();
return 0;
}

Das ganze soll unter der konsole laufen.

Uber gute Dokuhinweise wuerd ich mich auch schon freuen

Please, have a look to some Windows API conference (maybe in german
language or ask in english).
 
R

Rolf Magnus

nullstring said:
Hallo Leute,
gerade sitze ich vor dem problem, das ich eine
Klasse schreiben muss dir mir ne Wav datei vom mikro aufnimmt und
wieder abspielt.

Mein Problem ist nun, das mir meine callbackfunction nie ein
MM_WIM_DATA liefert
und augenscheinlich auch nix aufnimmt.

Tja und wie es halt so ist, bin ein newbie was Winprogrammierung
angeht.

Du bist hier ziemlich falsch. Für deutschsprachige C++-Fragen wäre
de.comp.lang.iso-c++ besser geeignet, aber du kannst dir das Posten dort
sparen, da die Frage dort genauso off-topic ist wie hier. Beide Newsgroups
beschäftigen sich ausschließlich mit der Sprache C++, wie es von ISO/IEC
14882 definiert wird, und dort gibt es keinerlei Audio-Funktionalität.
Deine Frage ist Windows-spezifisch und sollte daher in einer Newsgroup über
Windows-Programmierung gestellt werden.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top