Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hi,

wie kann ich in einer Win32 Anwendung Sound abspielen?

Es soll nichts besonderes sein, ich brauche nur eine Funktion mit der ich einen Sound abspielen kann ...

  • 3 Wochen später...

Hallo,

ich weiss nicht, ob es zu dieser Frage oder ob es zu der "Soundausgabe auf der Konsole" besser passen würde, aber ich habe da mal eine Frage:

Wie kann ich die Soundausgabe mit Hilfe von den waveOut-Funktionen programmieren?

PlaySound ist zwar für das einfache absielen ganz nett, aber wenn man die Daten auslesen und verändern will, dann reicht es halt nicht.

Ich habe mir verschiedene Beispiele für VisualC++ angeschaut (u.a. eine "Reverse.C" bei der Autoren-Edition) und habe versucht es nachzuprogrammieren, aber es funktioniert irgendwie nicht (ich bekomme immer wieder Fehler, dass der wave-Handler ungültig sei bei "waveOutPrepareHeader()" usw., das Gerät jedoch ordentlich geöffnet wurde.)

Danke schon im Vorfeld.

Hallo,

hier die Funktion, die das Rückwärtsspielen erledigen soll:

void ReversePlay()

{

HMMIO hmmio;

MMCKINFO mmckinfoParent;

MMCKINFO mmckinfoSubchunk;

DWORD dwFmtSize;

char szFileName[ MAX_FILENAME_SIZE ];

DWORD dwResult;

HANDLE hFormat;

WAVEFORMATEX *pFormat;

DWORD dwDataSize;

HPSTR hpch1, hpch2;

WORD wBlockSize;

HANDLE hData = NULL;

/* Get the filename from the edit control.

*/

if (!GetWindowText( hwndName, (LPSTR)szFileName, MAX_FILENAME_SIZE))

{

LoadString(hInstApp, IDS_FAILEDTOGETFNAME, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

return;

}

/* Open the given file for reading using buffered I/O.

*/

if(!(hmmio = mmioOpen(szFileName, NULL, MMIO_READ | MMIO_ALLOCBUF)))

{

LoadString(hInstApp, IDS_FAILEDTOOPENFILE, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

return;

}

/* Locate a 'RIFF' chunk with a 'WAVE' form type

* to make sure it's a WAVE file.

*/

mmckinfoParent.fccType = mmioFOURCC('W', 'A', 'V', 'E');

if (mmioDescend(hmmio, &mmckinfoParent, NULL, MMIO_FINDRIFF))

{

LoadString(hInstApp, IDS_NOTAWAVEFILE, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

mmioClose(hmmio, 0);

return;

}

/* Now, find the format chunk (form type 'fmt '). It should be

* a subchunk of the 'RIFF' parent chunk.

*/

mmckinfoSubchunk.ckid = mmioFOURCC('f', 'm', 't', ' ');

if (mmioDescend(hmmio, &mmckinfoSubchunk, &mmckinfoParent,

MMIO_FINDCHUNK))

{

LoadString(hInstApp, IDS_WAVEFILECORRUPT, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

mmioClose(hmmio, 0);

return;

}

/* Get the size of the format chunk, allocate and lock memory for it.

*/

dwFmtSize = mmckinfoSubchunk.cksize;

hFormat = LocalAlloc(LMEM_MOVEABLE, LOWORD(dwFmtSize));

if (!hFormat)

{

MessageBox(hwndApp, GetStringRes(IDS_NOMEM),

NULL, MB_OK | MB_ICONEXCLAMATION);

mmioClose(hmmio, 0);

return;

}

pFormat = (WAVEFORMATEX *) LocalLock(hFormat);

if (!pFormat)

{

MessageBox(hwndApp, GetStringRes(IDS_NOMEM_LK),

NULL, MB_OK | MB_ICONEXCLAMATION);

LocalFree( hFormat );

mmioClose(hmmio, 0);

return;

}

/* Read the format chunk.

*/

if (mmioRead(hmmio, (HPSTR) pFormat, dwFmtSize) != (LONG) dwFmtSize)

{

LoadString(hInstApp, IDS_FAILEDREADFMTCHNK, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

LocalUnlock( hFormat );

LocalFree( hFormat );

mmioClose(hmmio, 0);

return;

}

/* Make sure it's a PCM file.

*/

if (pFormat->wFormatTag != WAVE_FORMAT_PCM)

{

LocalUnlock( hFormat );

LocalFree( hFormat );

mmioClose(hmmio, 0);

LoadString(hInstApp, IDS_NOTAPCMFILE, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

return;

}

/* Make sure a waveform output device supports this format.

*/

#if (WINVER >= 0x0400)

if (waveOutOpen(&hWaveOut, WAVE_MAPPER, pFormat, 0, 0L,

WAVE_FORMAT_QUERY))

#else

if (waveOutOpen(&hWaveOut, WAVE_MAPPER, (LPWAVEFORMAT)pFormat, 0, 0L,

WAVE_FORMAT_QUERY))

#endif

{

LocalUnlock( hFormat );

LocalFree( hFormat );

mmioClose(hmmio, 0);

LoadString(hInstApp, IDS_CANTPLAYFORMAT, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

return;

}

/* Ascend out of the format subchunk.

*/

mmioAscend(hmmio, &mmckinfoSubchunk, 0);

/* Find the data subchunk.

*/

mmckinfoSubchunk.ckid = mmioFOURCC('d', 'a', 't', 'a');

if (mmioDescend(hmmio, &mmckinfoSubchunk, &mmckinfoParent,

MMIO_FINDCHUNK))

{

LoadString(hInstApp, IDS_NODATACHUNK, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

LocalUnlock( hFormat );

LocalFree( hFormat );

mmioClose(hmmio, 0);

return;

}

/* Get the size of the data subchunk.

*/

dwDataSize = mmckinfoSubchunk.cksize;

if (dwDataSize == 0L)

{

LoadString(hInstApp, IDS_CHUNKHASNODATA, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

LocalUnlock( hFormat );

LocalFree( hFormat );

mmioClose(hmmio, 0);

return;

}

/* Open a waveform output device.

*/

#if (WINVER >= 0x0400)

if (waveOutOpen(&hWaveOut, WAVE_MAPPER,

pFormat, (UINT)hwndApp, 0L, CALLBACK_WINDOW))

#else

if (waveOutOpen(&hWaveOut, WAVE_MAPPER,

(LPWAVEFORMAT)pFormat, (UINT)hwndApp, 0L, CALLBACK_WINDOW))

#endif

{

LoadString(hInstApp, IDS_FAILEDOPENDEVICE, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

LocalUnlock( hFormat );

LocalFree( hFormat );

mmioClose(hmmio, 0);

return;

}

/* Save block alignment info for later use.

*/

wBlockSize = pFormat->nBlockAlign;

/* We're done with the format header, free it.

*/

LocalUnlock( hFormat );

LocalFree( hFormat );

/* Allocate and lock memory for the waveform data.

*/

lpData = GlobalAllocPtr(GMEM_MOVEABLE | GMEM_SHARE, dwDataSize );

if (!lpData)

{

MessageBox(hwndApp, GetStringRes(IDS_NOMEM_DT),

NULL, MB_OK | MB_ICONEXCLAMATION);

mmioClose(hmmio, 0);

return;

}

/* Read the waveform data subchunk.

*/

if(mmioRead(hmmio, lpData, dwDataSize) != (LONG) dwDataSize)

{

LoadString(hInstApp, IDS_FAILEDREADCHUNK, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

GlobalFreePtr( lpData );

mmioClose(hmmio, 0);

return;

}

/* We're done with the file, close it.

*/

mmioClose(hmmio, 0);

/* Reverse the sound for playing.

*/

hpch1 = lpData;

hpch2 = lpData + dwDataSize - 1;

while (hpch1 < hpch2)

{

Interchange( hpch1, hpch2, wBlockSize );

hpch1 += wBlockSize;

hpch2 -= wBlockSize;

}

/* Allocate a waveform data header. The WAVEHDR must be

* globally allocated and locked.

*/

lpWaveHdr = (LPWAVEHDR)GlobalAllocPtr(GMEM_MOVEABLE | GMEM_SHARE,

(DWORD) sizeof(WAVEHDR));

if (!lpWaveHdr)

{

GlobalFreePtr( lpData );

MessageBox(hwndApp, GetStringRes(IDS_NOMEM_HR),

NULL, MB_OK | MB_ICONEXCLAMATION);

return;

}

/* If you need instance data for a waveform data block, allocate some

* memory and store the pointer in lpWaveHdr->dwUser, before the call

* to waveOutPrepareHeader(). The code inside the #if 0 / #endif, and

* the commented-out lpWaveHdr->dwUser = ... illustrate this.

* Don't forget to free the instance memory when you're done with it,

* or on error bailout.

*/

#if 0

lpYourData = GlobalAllocPtr(GMEM_MOVEABLE | GMEM_SHARE, sizeof(YOURDATA));

if (!lpYourData)

{

GlobalFreePtr( lpData );

GlobalFreePtr( lpWaveHdr );

MessageBox(hwndApp, GetStringRes(IDS_NOMEM_IS),

NULL, MB_OK | MB_ICONEXCLAMATION);

return;

}

#endif

/* Set up WAVEHDR structure and prepare it to be written to wave device.

*/

lpWaveHdr->lpData = lpData;

lpWaveHdr->dwBufferLength = dwDataSize;

lpWaveHdr->dwFlags = 0L;

lpWaveHdr->dwLoops = 0L;

// lpWaveHdr->dwUser = (DWORD) lpYourData; // save instance data ptr

if(waveOutPrepareHeader(hWaveOut, lpWaveHdr, sizeof(WAVEHDR)))

{

cleanup();

LoadString(hInstApp, IDS_UNABLEPREPAREHDR, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

return;

}

/* Then the data block can be sent to the output device.

*/

dwResult = waveOutWrite(hWaveOut, lpWaveHdr, sizeof(WAVEHDR));

if (dwResult != 0)

{

waveOutUnprepareHeader( hWaveOut, lpWaveHdr, sizeof(WAVEHDR));

cleanup();

LoadString(hInstApp, IDS_FAILEDWRITEDEVICE, lpstrLoadStrBuf,

LOADSTRBUFSIZE);

MessageBox(hwndApp, lpstrLoadStrBuf,

NULL, MB_OK | MB_ICONEXCLAMATION);

return;

}

/* Disable input to the button controls.

*/

EnableWindow(hwndPlay, FALSE);

EnableWindow(hwndQuit, FALSE);

}

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.