Frage deutsch
~~~~~~~~~~~~~
Wie kann ich WAV-Dateien im Hintergrund abspielen, ohne mein Programm
anzuhalten?
Frage englisch
~~~~~~~~~~~~~
How do I create background music from a WAV file without interrupting my main
program?
Antwort 1
~~~~~~~~
[ von Thomas Antoni, 18.6.2002 ]
Dazu benötigst Du einen sogenannten "DMA-Player" (siehe den Eintrag
FAQ-Eintrag "LEXIKON ->
DMA" ). Einige gute DMA-Soundplayer zum
Abspielen von WAV-Dateien Soundplayer findest Du auf www.qbasic.de unter
"QBasic -> Download -> Sound"
*** Anmerkung von Johannes Weißl [
johannes.weissl*gmx.de ]
Ich hatte mit den DMA-Playern von Deiner Seite die folgenden Probleme:
1. Der dmaplay6 von deiner Homepage funktioniert tadellos bei Dateien,
die schon auf der Festplatte sind, aber sobald ich eine neue Datei abspeichere,
sagt er, dass diese Datei keine data chunk sei oder so ähnlich! Mit welchem
Programm muss ich meine Wave-Dateien abspeichern, oder, welches nimmst du
her?
2. Der wavplay3 von deiner Homepage funktioniert nur eingeschränkt: Er
spielt nur die ersten 32k einer Datei! Das steht zwar auch drauf, aber
befriedigen kann das nicht, da frühere Versionen (z.B. wavplay) das schon
konnten!
3. Gibt es einen zu empfehlenden Sound-Driver (für einen
Standart-Soundblaster), den du mir mailen könntest!
Ich habe jetzt alle durchgetestet und auch Toshi befragt: Mit dem Editor
"CoolEdit 96" Kann man Wave-Dateien für die Programme abspielbar machen.
Außerdem: Bei mir musste (per BAT-Datei) ein Soundtreiber mitgeladen werden!
Antwort 2
~~~~~~~~
[ von Tobias Doerffel ("todo"; mailtodo*web.de ) , per
mail, 29.4.02 ]
.
Wenn man aber Wave-Dateien abspielen möchte, ist dies möglich. Zum einen gibt
es DMAPlay von Mike Huff, welches inzwischen (dank vieler anderer
Personen) die Versionsnummer 6 besitzt. In den meisten Fällen reicht jedoch
Version 4. DMAPlay gibt es auf den meisten QB-Seiten zum Download,
z.B. bei www.antonis.de unter der
Rubrik Download/Sound. Es kann Wave-Daten bis zu einer Größ von 32 KB im
Hintergrund spielen. Das heißt, man muss dafür sorgen, dass es regelmäßig
"Nachschub" gibt.
Eine weitere Möglichkeit ist die Verwendung des folgenden Programms:
'*********************************************************
' WavPlay1.bas - Einfacher WAV-Player - Simple WAV-Player
' ============
' (c) Tobias Doerffel ("todo"; todosoft*gmx.de) 29.4.02
'*********************************************************
DEFINT A-Z
CLS
PRINT "Please enter path and filename of the WAV file"
INPUT "e.g. c:\windows\media\chimes.wav : "; FileName$
PRINT "Please wait, loading file into virtual memory"
OPEN FileName$ FOR BINARY AS #1
DO
aa$ = SPACE$(1024)
GET #1, , aa$
LOOP UNTIL LOF(1) = LOC(1)
CLOSE #1
'
PRINT "playing wave file..."
Delay% = 100 'Wert an die Geschw. des PCs anpassen
'adapt to the CPU speed.
'Set to the approx. MHz
OPEN FileName$ FOR BINARY AS #1
Dummy$ = INPUT$(100, #1)
BytesRemaining& = LOF(1) - 100
BufferMax% = 100
WAIT 556, 128, 255
OUT 556, &HD1
'
DO
IF BufferMax% > BytesRemaining& THEN
BufferMax% = BytesRemaining&
BytesTemaining& = 0
ELSE
BytesRemaining& = BytesRemaining& - BufferMax%
END IF
Buffer$ = INPUT$(BufferMax%, #1)
FOR i% = 1 TO BufferMax%
WAIT 556, 128, 255
OUT &H22C, &H10
WAIT 556, 128, 255
OUT &H22C, ASC(MID$(Buffer$, i%, 1))
FOR j% = 1 TO Delay%: NEXT j%
NEXT i%
LOOP UNTIL BytesRemaining& < 100
WAIT 556, 128, 255
OUT &H22C, &H3D
CLOSE #1
END
Das obige Programm steht im Verzeichnis Progs\ zur Verfügung sowie online
unter www.antonis.de/faq/progs/wavplay1.bas .
Dieses Programm sendet die Wave-Daten direkt zur Soundkarte. Die Qualität ist
jedoch nicht so berauschend. Deshalb ist in jedem Fall DMAPlay
vorzuziehen. Um Wave-Dateien über den PC-Speaker abzuspielen, ist mir nur
ein QB-Programm bekannt, Speak von Sebastian Mate.
Antwort 3
~~~~~~~~
[ von Andy ( andyb*planet-interkom.de ) ]
Andy
Sound im Hintergrund
Tue Nov 16 17:45:55 1999
Hallo nochmal,
zum Thema Sound im Hintergrund, ja, da kann ich mal was dazu sagen, weil ich
gerade dabei bin etwas "rumzuspielern" wie man für QB eine ECHTE Grafische
Oberfläche schreibt die ausschließlich unter DOS läuft aber fast die gleiche
Oberfläche wie Windows, XWindows usw. bietet.
Um einen Sound im Hintergrund zu realisieren, MUSS man einen sogenannten
Kernel schreiben. Dieses habe ich bereits unter QBasic vor ein paar Tagen
realisiert.
Der Kernel ist sozusagen eine Routine, die völlig gelangweilt ein und
dasselbe macht:
Soll ein Sound abgespielt werden ? Ja, dann rufe mal Sound_Playwave_Task
auf.
Antwort 4
~~~~~~~~
[ von Matthias Becker (alias "Helium" alias "Beckah"; M.Beckah*gmx.de ), 19.4.02 ]
Verwende Die Bibliothek DS4QB++ von Lithium, die auf http://lithium.zext.net
und http://www.antonis.de zum Download
bereitsteht.
DS4QB steht für "Direct Sound 4 (for) QuickBasic" und
bietet einen Zugriff auf die DirectX Sound-Schnittstelle von Windows,
funktioniert also auch bei exotischen Soundkarten.
Antwort 5
~~~~~~~~~
Wie kann ich MP3, WAV und MIDI zu Gehör bringen?
*** WAV
Wave Dateien abzuspielen ist kein Problem. Man findet dazu überall im
Internet Quellcode. Es gibt 3 Möglichkeiten:
o über den eingebauten Speaker (klingt nicht mal sooo schlecht!)
o über die Soundkarte "byte-weise"
o via DMA. Klingt am besten und das abspielen geht im Hintergrund.
*** MIDI
MIDI ist auch kein Thema mehr. Früher musste man einen Treiber laden, der
die Datei dann abspielt. Mitlerweile gibt
es direktes MIDI (siehe RealMIDI auf www.sm-gimi.de ). Damit ist MIDI
kein
Thema mehr. Man kann auch das Keyboard
ansteurern. Ist für Spiele weniger geeignet!
*** MP3
MP3... Tja, prinzipiell möglich, da es nur eine "einfache" Datei ist die
wie
jede andere mit QB ausgelesen werden kann. Könnte... Das Format ist
eigentlich zu komplex um es zu verstehen. Es gibt mitterweile Versuche,
eine
QB-Audioprogrammierung zu schreiben. (Bei Fragen bitte Mail
an
sebmate*arcor.de )
*** VOC
VOCs kannmamn z.B. mit Hilfe der Bibliothek AP2.0 abspielen.
Answer 6
~~~~~~~~
How do I create repeating background music?
Download the demo program PLAY.BAS for information on PLAY event
trapping.
Answer 7
~~~~~~~~~~~
*** Question
How to play a .WAV file in Windows?
*** Answer
Use:
PlayWav "c:\windows\media\chimes.wav"
This will only work when QB is started Windows, but causes no problems in
DOS.
There are no restrictions on the size and even compressed .WAVs are
supported.
Even if the user doesn't have a soundcard, it will work if s/he has the
SPEAKER.DRV installed!
SUB PlayWav (Filename$)
IF ENVIRON$("windir") <> "" THEN
SHELL "if exist " + Filename$ + " start /m /w sndrec32 /play /close
/embedding " + Filename$
END IF
END SUB
*** Comment
A lot of newbies come by asking: "how do you play a .WAV file in QBasic."
They expect a simple answer, a single command perhaps. But unfortunately the
usual answers were: 'use a library, use this enormous assembler program...
etc.'
They probably use QBasic 1.1 from school, so that wouldn't even work. And if
they use QB4.5 and it does work, the .WAV file must be within tight
restrictions: not larger than 32K, not compressed, etc...
So I wanted to provide them with a safe and effective way to play .WAV files
of ANY size and ANY format. Without complex commands, assembler and in all
versions of QB.
I did advice using the SHELL command, but soon realized that it isn't very
safe to use: used in a loop it can soon fill up the memory with SoundRecorders.
If you just use SHELL "Start Filename.WAV" you cannot be certain that
SoundRecorder removes itself from memory.
Also, if the file does not exist, the QBasic program is halted, The computer
switches back to Windows and SoundRecorder gives an error message. That's not
very nice: I thought it would be better if the program tested for the existence
of the file before trying to play it.
I decided to make a single SUB that checked whether Windows was active, to
make sure it doesn't cause any trouble when started in DOS, and played a .WAV
file if it existed, but doesn't cause any troubles when it is accidentely
(re)moved or something. Newbies do stuff like that.
If you think the routine is childishly simple: great! That's what it is meant
to be! It is however the fourth version: all other versions were more
complicated, but still got much praise by other forum members (so there are
others who DID think this was relevant!) This version is extemely short and
simple, but it did take a lot of thinking and experimenting: just like a lot of
stuff in the history of science, it took a lot of effort to come up with a
solution that seems so obvious.
If you can make a QB program that can decode and play compressed 16 bit
stereo .WAVs of 100MB, then great, I couldn't do that. But then I didn't write
this routine for you. It is not relevant FOR YOU, but it maybe for others.
Yes, I can also make a thread about launching other windows applications. But
can you think of any windows applications that might be interesting, for a
newbie for example? Especially running it in the background?
Also: .WAV files need to be handled differently than other files, so it is
usefull to make a routine especially for them.
[ The QBasic-MonsterFAQ --- Start Page: www.antonis.de/faq ]