• R/O
  • HTTP
  • SSH
  • HTTPS

cinnamon: Commit

Cinnamon audio library


Commit MetaInfo

Revision47e2d6bd1d05859e6941c89aee4e5a01d2bda59f (tree)
Zeit2019-09-10 16:20:08
AutorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Add API call to play a sound with looping, and support in dsound and openal backends

Ändern Zusammenfassung

Diff

--- a/src/cinnamon.h
+++ b/src/cinnamon.h
@@ -102,8 +102,29 @@ enum Cin_SoundError {
102102 */
103103 CIN_EXPORT(unsigned) Cin_StructSoundSize();
104104
105+/**
106+ * @brief Causes a sound to play.
107+ *
108+ * This will trigger the sound to play without looping.
109+ *
110+ * Calling play on a sound that is already playing will do nothing. To restart
111+ * a sound, use Cin_SoundStop first.
112+ */
105113 CIN_EXPORT(enum Cin_SoundError) Cin_SoundPlay(struct Cin_Sound *snd);
106114
115+/**
116+ * @brief Causes a sound to play with optional looping.
117+ *
118+ * The sound will loop if the loop param is non-zero.
119+ *
120+ * Calling play on a sound that is already playing will do nothing. To restart
121+ * a sound, use Cin_SoundStop first.
122+ *
123+ * @sa Cin_SoundPlay
124+ */
125+CIN_EXPORT(enum Cin_SoundError) Cin_SoundPlayLoop(struct Cin_Sound *snd,
126+ int loop);
127+
107128 CIN_EXPORT(enum Cin_SoundError) Cin_SoundStop(struct Cin_Sound *snd);
108129
109130 CIN_EXPORT(void) Cin_DestroySound(struct Cin_Sound *snd);
--- a/src/dsound/cin_dsound.cpp
+++ b/src/dsound/cin_dsound.cpp
@@ -65,6 +65,13 @@ CIN_EXPORT(enum Cin_SoundError) Cin_SoundPlay(Cin_Sound *snd){
6565
6666 ///////////////////////////////////////////////////////////////////////////////
6767
68+CIN_EXPORT(enum Cin_SoundError) Cin_SoundPlayLoop(Cin_Sound *snd, int loop){
69+ snd->play(!!loop);
70+ return Cin_eSoundSuccess;
71+}
72+
73+///////////////////////////////////////////////////////////////////////////////
74+
6875 CIN_EXPORT(enum Cin_SoundError) Cin_SoundStop(Cin_Sound *snd){
6976 snd->stop();
7077 return Cin_eSoundSuccess;
--- a/src/dsound/cin_dsound_sound.cpp
+++ b/src/dsound/cin_dsound_sound.cpp
@@ -7,6 +7,8 @@
77 #include "cinnamon.h"
88 #include "cin_soft_loader.h"
99
10+#include <assert.h>
11+
1012 #include <mmreg.h>
1113 #include <ks.h>
1214 #include <ksmedia.h>
@@ -105,6 +107,7 @@ Cin_Sound::Cin_Sound(IDirectSound8 *dsound, const Cin_Loader &ld)
105107 fmt.Format.wBitsPerSample = bytes_per_sample << 3;
106108
107109 // Check the size of the loader data.
110+
108111 const unsigned byte_size = ld.bytes_placed;
109112 #ifndef NDEBUG
110113 {
@@ -115,7 +118,8 @@ Cin_Sound::Cin_Sound(IDirectSound8 *dsound, const Cin_Loader &ld)
115118 assert(debug_byte_size == byte_size);
116119 }
117120 #endif
118-
121+
122+
119123 DSBUFFERDESC descriptor;
120124 descriptor.dwSize = sizeof(DSBUFFERDESC);
121125 descriptor.dwFlags = DSBCAPS_GLOBALFOCUS;
@@ -135,7 +139,11 @@ Cin_Sound::Cin_Sound(IDirectSound8 *dsound, const Cin_Loader &ld)
135139 buffer_size == byte_size){
136140
137141 Cin_LoaderMemcpy(ld.first, 0, buffer_data, byte_size);
138- m_buffer->Unlock(buffer_data, byte_size, NULL, 0);
142+ if(m_buffer->Unlock(buffer_data, byte_size, NULL, 0) != DS_OK){
143+ m_dsound->Release();
144+ m_buffer->Release();
145+ m_buffer = NULL;
146+ }
139147 }
140148 else{
141149 m_dsound->Release();
--- a/src/openal/cin_openal.c
+++ b/src/openal/cin_openal.c
@@ -356,6 +356,15 @@ enum Cin_SoundError Cin_SoundPlay(struct Cin_Sound *snd){
356356
357357 /*****************************************************************************/
358358
359+enum Cin_SoundError Cin_SoundPlayLoop(struct Cin_Sound *snd, int loop){
360+ alcMakeContextCurrent(snd->ctx);
361+ alSourcei(snd->snd, AL_LOOPING, (loop==0) ? AL_FALSE : AL_TRUE);
362+ alSourcePlay(snd->snd);
363+ return Cin_eSoundSuccess;
364+}
365+
366+/*****************************************************************************/
367+
359368 enum Cin_SoundError Cin_SoundStop(struct Cin_Sound *snd){
360369 alcMakeContextCurrent(snd->ctx);
361370 alSourceStop(snd->snd);
Show on old repository browser