Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [C++ Win32] waveInOpen (callback)

    Salve,

    continuo nello studio della waveForm API di Win32 ed oras ono arrivato alla waveInOpen con il seguente codice:

    codice:
    #include <windows.h>
    #pragma comment (lib, "winmm.lib")
    #include <mmsystem.h>
    #include <iostream>
    
    BOOL CALLBACK myCallback();
    
    int main()
    {
    	// Definisco la struttura WAVEFORMATEX
    	WAVEFORMATEX waveFormat;
    	waveFormat.wFormatTag      = WAVE_FORMAT_PCM;
    	waveFormat.wBitsPerSample  = 16;
    	waveFormat.nChannels       = 1;
    	waveFormat.nSamplesPerSec  = 44100;
    	waveFormat.nBlockAlign     = waveFormat.nChannels * waveFormat.wBitsPerSample / 8;
    	waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
    	waveFormat.cbSize          = 0;
    
    	MMRESULT mmres;   // ...
    	HWAVEIN phvi;     // Handle for the input device
    	UINT uDevice = 1; // Device id
    
    	// waveInOpen (http://msdn.microsoft.com/en-us/library/aa908147.aspx)
    	mmres = waveInOpen(&phvi, // Address filled with a handle identifying the open waveform-audio input device.
    					uDevice,  // Device identifier of the waveform-audio input device to open.
    					(LPWAVEFORMATEX)&waveFormat, // Pointer to a WAVEFORMATEX structure
    					(DWORD)myCallback, // Specifies the address of a fixed callback function, an event handle...
    					0, // Specifies user-instance data passed to the callback mechanism.
    					CALLBACK_EVENT // Flags for opening the device.
    					);
    
    	return 0;
    }
    Solo che non ho trovato come (con quali parametri) devo definire la callback che riceverà messaggi dal sistema...quali sono questi messaggi??

    grazie
    Alla batteria dai retta ballA

  2. #2

    waveInPrepareHeader

    allora per adesso non ho impostato alcuna callback ed ora ho il seguente codice:

    codice:
    #include <windows.h>
    #pragma comment (lib, "winmm.lib")
    #include <mmsystem.h>
    #include <iostream>
    #define system_buf_len 4096
    
    BOOL CALLBACK myCallback();
    
    int main()
    {
    	// Definisco la struttura WAVEFORMATEX
    	WAVEFORMATEX waveFormat;
    	waveFormat.wFormatTag      = WAVE_FORMAT_PCM;
    	waveFormat.wBitsPerSample  = 16;
    	waveFormat.nChannels       = 1;
    	waveFormat.nSamplesPerSec  = 44100;
    	waveFormat.nBlockAlign     = waveFormat.nChannels * waveFormat.wBitsPerSample / 8;
    	waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
    	waveFormat.cbSize          = 0;
    
    	MMRESULT mmres;   // ...
    	HWAVEIN phvi;     // Handle for the input device
    	UINT uDevice = 0; // Device id "Gruppo Microfoni"
    
    	// waveInOpen
    	mmres = waveInOpen(&phvi,
    					uDevice,
    					(LPWAVEFORMATEX)&waveFormat,
    					0,
    					0,
    					CALLBACK_EVENT
    					);
    
    	// Prepare Buffer
    	char buf[system_buf_len];
    	WAVEHDR buffer;
    	buffer.lpData          = &buf;
    	buffer.dwBufferLength  = system_buf_len;
    	buffer.dwBytesRecorded = 0;
    	buffer.dwUser          = 0;
    	buffer.dwFlags         = 0;
    	buffer.dwLoops         = 0;
    
    	// waveInPrepareHeader
    	waveInPrepareHeader(phvi, &buffer, sizeof(WAVEHDR));
    
    	// waveInAddBuffer
    	waveInAddBuffer(phvi, &buffer, sizeof(WAVEHDR));
    
    	return 0;
    }
    mi ritorna questo errore alla riga di codice:

    codice:
    buffer.lpData          = &buf;
    cannot convert from 'char (*)[4096]' to 'LPSTR'

    credevo dovessi passargli un pointer al buffer (buf)...

    così ho letto su:
    http://msdn.microsoft.com/en-us/library/aa909814.aspx
    lpData

    Long pointer to the address of the waveform buffer. This buffer must be block-aligned according to the nBlockAlign member of the WAVEFORMATEX structure used to open the device.

    codice:
    typedef struct {
      LPSTR lpData;
      DWORD dwBufferLength;
      DWORD dwBytesRecorded;
      DWORD dwUser;
      DWORD dwFlags;
      DWORD dwLoops;
      struct wavehdr_tag* lpNext;
      DWORD reserved;}
    WAVEHDR;
    Alla batteria dai retta ballA

  3. #3
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    buffer.lpData = buf;
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  4. #4
    ok, a questo punto avevo pensate di allocare dinamicamente buf così:

    codice:
    char *buf = (char *)malloc(4096)
    vale la pena?
    Alla batteria dai retta ballA

  5. #5
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Originariamente inviato da gianvituzzi
    ok, a questo punto avevo pensate di allocare dinamicamente buf così:

    codice:
    char *buf = (char *)malloc(4096)
    vale la pena?
    Perchè lo hai pensato?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.