Cinnamon audio library
Revision | 47e2d6bd1d05859e6941c89aee4e5a01d2bda59f (tree) |
---|---|
Zeit | 2019-09-10 16:20:08 |
Autor | AlaskanEmily <emily@alas...> |
Commiter | AlaskanEmily |
Add API call to play a sound with looping, and support in dsound and openal backends
@@ -102,8 +102,29 @@ enum Cin_SoundError { | ||
102 | 102 | */ |
103 | 103 | CIN_EXPORT(unsigned) Cin_StructSoundSize(); |
104 | 104 | |
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 | + */ | |
105 | 113 | CIN_EXPORT(enum Cin_SoundError) Cin_SoundPlay(struct Cin_Sound *snd); |
106 | 114 | |
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 | + | |
107 | 128 | CIN_EXPORT(enum Cin_SoundError) Cin_SoundStop(struct Cin_Sound *snd); |
108 | 129 | |
109 | 130 | CIN_EXPORT(void) Cin_DestroySound(struct Cin_Sound *snd); |
@@ -65,6 +65,13 @@ CIN_EXPORT(enum Cin_SoundError) Cin_SoundPlay(Cin_Sound *snd){ | ||
65 | 65 | |
66 | 66 | /////////////////////////////////////////////////////////////////////////////// |
67 | 67 | |
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 | + | |
68 | 75 | CIN_EXPORT(enum Cin_SoundError) Cin_SoundStop(Cin_Sound *snd){ |
69 | 76 | snd->stop(); |
70 | 77 | return Cin_eSoundSuccess; |
@@ -7,6 +7,8 @@ | ||
7 | 7 | #include "cinnamon.h" |
8 | 8 | #include "cin_soft_loader.h" |
9 | 9 | |
10 | +#include <assert.h> | |
11 | + | |
10 | 12 | #include <mmreg.h> |
11 | 13 | #include <ks.h> |
12 | 14 | #include <ksmedia.h> |
@@ -105,6 +107,7 @@ Cin_Sound::Cin_Sound(IDirectSound8 *dsound, const Cin_Loader &ld) | ||
105 | 107 | fmt.Format.wBitsPerSample = bytes_per_sample << 3; |
106 | 108 | |
107 | 109 | // Check the size of the loader data. |
110 | + | |
108 | 111 | const unsigned byte_size = ld.bytes_placed; |
109 | 112 | #ifndef NDEBUG |
110 | 113 | { |
@@ -115,7 +118,8 @@ Cin_Sound::Cin_Sound(IDirectSound8 *dsound, const Cin_Loader &ld) | ||
115 | 118 | assert(debug_byte_size == byte_size); |
116 | 119 | } |
117 | 120 | #endif |
118 | - | |
121 | + | |
122 | + | |
119 | 123 | DSBUFFERDESC descriptor; |
120 | 124 | descriptor.dwSize = sizeof(DSBUFFERDESC); |
121 | 125 | descriptor.dwFlags = DSBCAPS_GLOBALFOCUS; |
@@ -135,7 +139,11 @@ Cin_Sound::Cin_Sound(IDirectSound8 *dsound, const Cin_Loader &ld) | ||
135 | 139 | buffer_size == byte_size){ |
136 | 140 | |
137 | 141 | 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 | + } | |
139 | 147 | } |
140 | 148 | else{ |
141 | 149 | m_dsound->Release(); |
@@ -356,6 +356,15 @@ enum Cin_SoundError Cin_SoundPlay(struct Cin_Sound *snd){ | ||
356 | 356 | |
357 | 357 | /*****************************************************************************/ |
358 | 358 | |
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 | + | |
359 | 368 | enum Cin_SoundError Cin_SoundStop(struct Cin_Sound *snd){ |
360 | 369 | alcMakeContextCurrent(snd->ctx); |
361 | 370 | alSourceStop(snd->snd); |