Zum Inhalt springen

floppy

Mitglieder
  • Gesamte Inhalte

    6
  • Benutzer seit

  • Letzter Besuch

Alle Inhalte von floppy

  1. 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); }
  2. 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.
  3. Übrigens, auf http://www.josef-k.net/mim/MidiFileFormat.html findest Du C-Codefragmente, wie man 8-bit und 7-bit ineinader wandeln kann.
  4. Ich habe nur mal einen Text2MIDI-Programm geschrieben, nur so für mich zum herumtesten. Momentan schreibe ich einen Programm, der das ganze andersrum machen soll (MIDI2Text), habe aber schon meine Probleme, auch wegen den ganzen Formaten. Quellcodes findest Du überall im Netz (unter anderem auch auf den Seiten, die ich aufgeschrieben habe), da kann man sich halt mal angucken, wie man sowas machen müsste, ich versuche es aber selber zu programmieren, damit ich erstmal das Programmieren richtig lerne und auch etwas über MIDI erfahre. Leider habe ich von dem, was Du speziell suchst keine Ahnung. Ich würde mich aber freuen, wenn wir ein paar Erfahrungen austauschen könnten.
  5. Das kommt darauf an, was Du für Controler-Befehle (BnHEX) verarbeiten willst. Controler 0..31 sind MSB, 32..64 LSB. Probleme soll es wohl beim Übergang zwischen 2 MSB-Werten kommen. Hier ein paar Internet-Seiten: http://iem.kug.ac.at/ritsch/Vorlesungen/sn/node11.html http://home.snafu.de/sicpaul/midi/midiy.htm www.midi.org www.harmony-central.com/MIDI/Doc/doc.html www.zem-college.de/midi/index.html www.tu-chemnitz.de/informatik/RA/kompendium/vortraege_97/sound/sound_kap3_1.html
  6. Hi! Ich bin neu hier, aber Dein Problem ist mir gleich aufgefallen. Soweit ich das verstehe, willst Du MIDI programmieren, ist das richtig? Ich habe nur einen "kurzen" Einblick in die MIDI-Welt bekommen, am besten Du suchst mal mit google nach MIDI, da findest Du ein paar Seiten in deutsch und viele in englisch zu dem Thema MIDI-Spezifikationen. Da findest Du auch manchmal Codefragmente, wie man 8-bit und 7-bit Zahlen ineinader konvertieren kann (meisstens macht man das mit Bit-shifting), aber Vorsicht: überprüfe den Code, ob er auch wirklich das tut, was Du willst. Die 7-bit Codierung brauchst Du allerdings nur bei Angaben von Zeiten (delta-times), sonst sind alle Steuernachrichten (SysEx, ControlChange...) grösser 128, also 8-bit-Werte und alle "normale" Nachrichten (Noten zum Beispiel) kleiner 128, also 7-bit Werte. Ich hoffe, es hilft Dir erstmal weiter, falls ich die Internetseiten noch irgendwo finde, kann ich sie Dir nochmal schicken.

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...