PlaySound synchron abspielen ?

Für allgemeine Fragen zur Programmierung mit PureBasic.
pickelrobert
Beiträge: 207
Registriert: 09.12.2004 22:09

PlaySound synchron abspielen ?

Beitrag von pickelrobert »

Ich schon wieder. Wie spiele ich einen Sound unter Verwendung von PlaySound synchron (einem nach dem anderen, bei mehreren PlaySounds hintereinander) ab ?

Danke
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Beitrag von ts-soft »

Versuchs mal so:

Code: Alles auswählen

PlaySound_(File$, 0, #SND_FILENAME|#SND_SYNC|#SND_NODEFAULT)
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Kaeru Gaman
Beiträge: 17389
Registriert: 10.11.2004 03:22

Beitrag von Kaeru Gaman »

ts-soft hat geschrieben:Versuchs mal so:

Code: Alles auswählen

PlaySound_(File$, 0, #SND_FILENAME|#SND_SYNC|#SND_NODEFAULT)
eine weitergehende erklärung wäre nett, ts...
Der Narr denkt er sei ein weiser Mann.
Der Weise weiß, dass er ein Narr ist.
pickelrobert
Beiträge: 207
Registriert: 09.12.2004 22:09

Beitrag von pickelrobert »

Ich meine den "eingebauten" PlaySound-Befehl. Der hat, lt.Doku, nur zwei Parameter. Außerdem habe ich den Sound "gecatcht" und somit fällt File$ schonmal flach
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Beitrag von ts-soft »

Im PSDK unter: ms-help://MS.PSDK.1033/multimed/mmfunc_9uxw.htm
Ansonsten in der dir zu verfügungstehenden API-Hilfe unter PlaySound nachschauen
PlaySound
The PlaySound function plays a sound specified by the given filename, resource, or system event. (A system event may be associated with a sound in the registry or in the WIN.INI file.)

BOOL PlaySound(
LPCSTR pszSound,
HMODULE hmod,
DWORD fdwSound
);
Parameters
pszSound
A string that specifies the sound to play. If this parameter is NULL, any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE in the fdwSound parameter.
Three flags in fdwSound (SND_ALIAS, SND_FILENAME, and SND_RESOURCE) determine whether the name is interpreted as an alias for a system event, a filename, or a resource identifier. If none of these flags are specified, PlaySound searches the registry or the WIN.INI file for an association with the specified sound name. If an association is found, the sound event is played. If no association is found in the registry, the name is interpreted as a filename.

hmod
Handle to the executable file that contains the resource to be loaded. This parameter must be NULL unless SND_RESOURCE is specified in fdwSound.
fdwSound
Flags for playing the sound. The following values are defined. Value Meaning
SND_APPLICATION The sound is played using an application-specific association.
SND_ALIAS The pszSound parameter is a system-event alias in the registry or the WIN.INI file. Do not use with either SND_FILENAME or SND_RESOURCE.
SND_ALIAS_ID The pszSound parameter is a predefined sound identifier.
SND_ASYNC The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL.
SND_FILENAME The pszSound parameter is a filename.
SND_LOOP The sound plays repeatedly until PlaySound is called again with the pszSound parameter set to NULL. You must also specify the SND_ASYNC flag to indicate an asynchronous sound event.
SND_MEMORY A sound event's file is loaded in RAM. The parameter specified by pszSound must point to an image of a sound in memory.
SND_NODEFAULT No default sound event is used. If the sound cannot be found, PlaySound returns silently without playing the default sound.
SND_NOSTOP The specified sound event will yield to another sound event that is already playing. If a sound cannot be played because the resource needed to generate that sound is busy playing another sound, the function immediately returns FALSE without playing the requested sound.
If this flag is not specified, PlaySound attempts to stop the currently playing sound so that the device can be used to play the new sound.

SND_NOWAIT If the driver is busy, return immediately without playing the sound.
SND_PURGE Sounds are to be stopped for the calling task. If pszSound is not NULL, all instances of the specified sound are stopped. If pszSound is NULL, all sounds that are playing on behalf of the calling task are stopped.
You must also specify the instance handle to stop SND_RESOURCE events.

SND_RESOURCE The pszSound parameter is a resource identifier; hmod must identify the instance that contains the resource.
SND_SYNC Synchronous playback of a sound event. PlaySound returns after the sound event completes.
Der eingebaute Befehl unterstützt das Wohl nicht
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Beitrag von ts-soft »

Wenn Du jaPBe verwendest, kannste den Sound als Resource hinzufügen, und dann per API abspielen
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Benutzeravatar
Froggerprogger
Badmin
Beiträge: 855
Registriert: 08.09.2004 20:02

Beitrag von Froggerprogger »

@pickelrobert:
Was meinst Du mit synchron. Synchron zu was ?
synchron (einem nach dem anderen, bei mehreren PlaySounds hintereinander)
Die Klammer erklärt nicht den Begriff 'synchron', sondern 'sequentiell'.
Meinst Du das ? Wenn, dann würde Dir bei PB leider ein Befehl IsPlaying() fehlen, Du müßtest also vorher die Länge des Sounds in ms haben, und dann einfach solange bis zum Start des nächsten abwarten, was aber vage Resultate liefern könnte, und sicher nicht ganz nahtlose Übergänge erzeugt.
...oder halt auf PB's PlaySound verzichten.
Stichwort audiere, fmod, bass, ...
!UD2
Benutzeravatar
Dostej
Beiträge: 529
Registriert: 01.10.2004 10:02
Kontaktdaten:

Beitrag von Dostej »

Läuft irgendeines der "plugins" auch unter Linux u/o. Mac? - So wegen der portierbarkeit von code...
Benutzeravatar
Froggerprogger
Badmin
Beiträge: 855
Registriert: 08.09.2004 20:02

Beitrag von Froggerprogger »

@Dostej
Meinst Du das UseOGGSoundDecoder() - PlugIn ?
Das geht laut PB-Hilfe unter Windows und Linux.

Oder meinst Du die externen audioengines ?

fmod läuft auf Windows (32/64 Bit), Linux, Macintosh (Carbon based. Codewarrior CFM und GCC Mach-O Compatible), Windows CE, PocketPC, Smart Phone, GameCube, PS2 & XBox.
Die nehmens ernst mit cross-plattform :allright:

Wie das bei bass oder audiere ist, weiß ich nicht. (bin da ein bißchen einseitig, da ich immer nur fmod nutze.)
!UD2
pickelrobert
Beiträge: 207
Registriert: 09.12.2004 22:09

Beitrag von pickelrobert »

@Froggerprogger

Synchron im klassischen Sinne bedeutet, das das Programm so lange wartet, bis der Sound abgespielt ist. Wenn ich mehrere Sounds hintereinander abspiele ist das zwar sequentiell, führt aber beim asynchronen Abspielen zur Überlagerung der Sounds, was manchmal unerwünscht ist. Es gibt zwar ein paar Includedateien mit den ich die Länge und die aktuelle Position ermitteln kann, das setzt jedoch eine aufwendige Programmierung mit einem Zeitgeber voraus, was die Sache unnötig kompliziert. Das wäre das synchrone Abspielen von Sounds (als Option) doch wesentlich einfacher ...

Gruß
Antworten