aufnahme von wavdateien mit callback function

Discussion in 'C++' started by nullstring, Nov 29, 2006.

  1. nullstring

    nullstring Guest

    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
     
    nullstring, Nov 29, 2006
    #1
    1. Advertising

  2. nullstring

    kwikius Guest

    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
     
    kwikius, Nov 29, 2006
    #2
    1. Advertising

  3. nullstring

    Ondra Holub Guest

    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).
     
    Ondra Holub, Nov 29, 2006
    #3
  4. nullstring

    Rolf Magnus Guest

    nullstring wrote:

    > 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.
     
    Rolf Magnus, Nov 29, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karolin Spill
    Replies:
    1
    Views:
    2,769
    Karolin Spill
    Sep 2, 2003
  2. Johannes Eble
    Replies:
    0
    Views:
    386
    Johannes Eble
    May 25, 2004
  3. Phane01

    auslesen von Controls

    Phane01, Nov 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    551
  4. Replies:
    2
    Views:
    701
  5. Zor
    Replies:
    1
    Views:
    93
    Richard Cornford
    Nov 20, 2003
Loading...

Share This Page