Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorJoerg Mueller <nexyon@gmail.com>2009-07-24 22:28:09 +0400
committerJoerg Mueller <nexyon@gmail.com>2009-07-24 22:28:09 +0400
commit25aa8d37b5cfcbf3d318ec26d3dcb7d5694199e5 (patch)
tree089261dff61f91bd2ccdb4f675a3fc0991d6c1de /intern
parent4d1d1480ebb998356212c46aa5133fc0a0bcbadd (diff)
Initial (ugly) sequencer sound support.
Diffstat (limited to 'intern')
-rw-r--r--intern/audaspace/AUD_C-API.h17
-rw-r--r--intern/audaspace/OpenAL/AUD_OpenALDevice.cpp53
-rw-r--r--intern/audaspace/intern/AUD_BufferReader.cpp2
-rw-r--r--intern/audaspace/intern/AUD_C-API.cpp36
4 files changed, 79 insertions, 29 deletions
diff --git a/intern/audaspace/AUD_C-API.h b/intern/audaspace/AUD_C-API.h
index d7cbe888910..a1418a989b1 100644
--- a/intern/audaspace/AUD_C-API.h
+++ b/intern/audaspace/AUD_C-API.h
@@ -39,6 +39,12 @@ typedef enum
AUD_OPENAL_DEVICE
} AUD_DeviceType;
+typedef struct
+{
+ AUD_Specs specs;
+ float length;
+} AUD_SoundInfo;
+
#ifndef AUD_CAPI_IMPLEMENTATION
typedef void AUD_Sound;
typedef void AUD_Handle;
@@ -66,6 +72,13 @@ extern int* AUD_enumDevices();
extern void AUD_exit();
/**
+ * Returns information about a sound.
+ * \param sound The sound to get the info about.
+ * \return The AUD_SoundInfo structure with filled in data.
+ */
+extern AUD_SoundInfo AUD_getInfo(AUD_Sound* sound);
+
+/**
* Loads a sound file.
* \param filename The filename of the sound file.
* \return A handle of the sound file.
@@ -174,11 +187,9 @@ extern int AUD_setKeep(AUD_Handle* handle, int keep);
* Seeks a playing or paused sound.
* \param handle The handle to the sound.
* \param seekTo From where the sound file should be played back in seconds.
- * A negative value indicates the seconds that should be waited
- * before playback starts.
* \return Whether the handle has been valid or not.
*/
-extern int AUD_seek(AUD_Handle* handle, int seekTo);
+extern int AUD_seek(AUD_Handle* handle, float seekTo);
/**
* Returns the status of a playing, paused or stopped sound.
diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
index 6db35b7d578..8587dae027f 100644
--- a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
+++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
@@ -61,6 +61,9 @@ struct AUD_OpenALHandle : AUD_Handle
/// The first buffer to be read next.
int current;
+
+ /// Whether the stream doesn't return any more data.
+ bool data_end;
};
struct AUD_OpenALBufferedFactory
@@ -145,7 +148,7 @@ void AUD_OpenALDevice::updateStreams()
while(info--)
{
// if there's still data to play back
- if(sound->current >= 0)
+ if(!sound->data_end)
{
// read data
length = m_buffersize;
@@ -154,7 +157,7 @@ void AUD_OpenALDevice::updateStreams()
// read nothing?
if(length == 0)
{
- sound->current = -1;
+ sound->data_end = true;
break;
}
@@ -164,7 +167,7 @@ void AUD_OpenALDevice::updateStreams()
ALenum err;
if((err = alGetError()) != AL_NO_ERROR)
{
- sound->current = -1;
+ sound->data_end = true;
break;
}
@@ -177,7 +180,7 @@ void AUD_OpenALDevice::updateStreams()
if(alGetError() != AL_NO_ERROR)
{
- sound->current = -1;
+ sound->data_end = true;
break;
}
@@ -186,7 +189,7 @@ void AUD_OpenALDevice::updateStreams()
&sound->buffers[sound->current]);
if(alGetError() != AL_NO_ERROR)
{
- sound->current = -1;
+ sound->data_end = true;
break;
}
@@ -204,14 +207,11 @@ void AUD_OpenALDevice::updateStreams()
if(info == AL_STOPPED)
{
// if it really stopped
- if(sound->current < 0)
+ if(sound->data_end)
{
// pause or
if(sound->keep)
- {
- alSourceRewind(sound->source);
pause(sound);
- }
// stop
else
stop(sound);
@@ -332,7 +332,6 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
delete sound; AUD_DELETE("handle")
m_playingSounds->erase(m_playingSounds->begin());
}
- delete m_playingSounds; AUD_DELETE("list")
// delete all paused sounds
while(!m_pausedSounds->empty())
@@ -347,7 +346,6 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
delete sound; AUD_DELETE("handle")
m_pausedSounds->erase(m_pausedSounds->begin());
}
- delete m_pausedSounds; AUD_DELETE("list")
// delete all buffered factories
while(!m_bufferedFactories->empty())
@@ -356,11 +354,14 @@ AUD_OpenALDevice::~AUD_OpenALDevice()
delete *m_bufferedFactories->begin(); AUD_DELETE("bufferedfactory");
m_bufferedFactories->erase(m_bufferedFactories->begin());
}
- delete m_bufferedFactories; AUD_DELETE("list")
alcProcessContext(m_context);
unlock();
+ delete m_playingSounds; AUD_DELETE("list")
+ delete m_pausedSounds; AUD_DELETE("list")
+ delete m_bufferedFactories; AUD_DELETE("list")
+
// wait for the thread to stop
if(m_thread != 0)
pthread_join(m_thread, NULL);
@@ -521,6 +522,7 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
sound->keep = keep;
sound->current = -1;
sound->isBuffered = true;
+ sound->data_end = true;
alcSuspendContext(m_context);
@@ -598,6 +600,7 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep)
sound->reader = reader;
sound->current = 0;
sound->isBuffered = false;
+ sound->data_end = false;
valid &= getFormat(sound->format, specs);
@@ -702,15 +705,30 @@ bool AUD_OpenALDevice::pause(AUD_Handle* handle)
bool AUD_OpenALDevice::resume(AUD_Handle* handle)
{
- // only songs that are paused can be resumed
+ ALint info;
lock();
+
+ // only songs that are paused can be resumed
for(AUD_HandleIterator i = m_pausedSounds->begin();
i != m_pausedSounds->end(); i++)
{
if(*i == handle)
{
m_playingSounds->push_back(*i);
- alSourcePlay((*i)->source);
+
+ alGetSourcei((*i)->source, AL_SOURCE_STATE, &info);
+
+ switch(info)
+ {
+ case AL_PLAYING:
+ break;
+ case AL_STOPPED:
+// alSourceRewind((*i)->source);
+ default:
+// alSourcePlay((*i)->source);
+ break;
+ }
+
start();
m_pausedSounds->erase(i);
unlock();
@@ -813,8 +831,11 @@ bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
if(alhandle->isBuffered)
alSourcef(alhandle->source, AL_SEC_OFFSET, position);
else
+ {
alhandle->reader->seek((int)(position *
alhandle->reader->getSpecs().rate));
+ alhandle->data_end = false;
+ }
unlock();
return true;
}
@@ -1098,6 +1119,8 @@ bool AUD_OpenALDevice::updateListener(AUD_3DData &data)
alListenerfv(AL_POSITION, (ALfloat*)data.position);
alListenerfv(AL_VELOCITY, (ALfloat*)data.velocity);
alListenerfv(AL_ORIENTATION, (ALfloat*)&(data.orientation[3]));
+
+ return true;
}
bool AUD_OpenALDevice::setSetting(AUD_3DSetting setting, float value)
@@ -1162,8 +1185,6 @@ float AUD_OpenALDevice::getSetting(AUD_3DSetting setting)
return std::numeric_limits<float>::quiet_NaN();
}
-#include <stdio.h>
-
bool AUD_OpenALDevice::updateSource(AUD_Handle* handle, AUD_3DData &data)
{
lock();
diff --git a/intern/audaspace/intern/AUD_BufferReader.cpp b/intern/audaspace/intern/AUD_BufferReader.cpp
index 1e828cfb0f1..47bf5d3d171 100644
--- a/intern/audaspace/intern/AUD_BufferReader.cpp
+++ b/intern/audaspace/intern/AUD_BufferReader.cpp
@@ -45,7 +45,7 @@ void AUD_BufferReader::seek(int position)
if(position < 0)
m_position = 0;
else if(position > m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs))
- position = m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs);
+ m_position = m_buffer.get()->getSize() / AUD_SAMPLE_SIZE(m_specs);
else
m_position = position;
}
diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp
index 4dc3c34e94c..ccf3ca3c6a1 100644
--- a/intern/audaspace/intern/AUD_C-API.cpp
+++ b/intern/audaspace/intern/AUD_C-API.cpp
@@ -36,12 +36,7 @@
#include "AUD_LoopFactory.h"
#include "AUD_ReadDevice.h"
#include "AUD_SourceCaps.h"
-
-/*
-#define WITH_SDL
-#define WITH_OPENAL
-#define WITH_FFMPEG
-//*/
+#include "AUD_IReader.h"
#ifdef WITH_SDL
#include "AUD_SDLDevice.h"
@@ -138,6 +133,30 @@ void AUD_exit()
AUD_3ddevice = NULL;
}
+AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
+{
+ assert(sound);
+
+ AUD_IReader* reader = sound->createReader();
+
+ AUD_SoundInfo info;
+
+ if(reader)
+ {
+ info.specs = reader->getSpecs();
+ info.length = reader->getLength() / (float) info.specs.rate;
+ }
+ else
+ {
+ info.specs.channels = AUD_CHANNELS_INVALID;
+ info.specs.format = AUD_FORMAT_INVALID;
+ info.specs.rate = AUD_RATE_INVALID;
+ info.length = 0.0;
+ }
+
+ return info;
+}
+
AUD_Sound* AUD_load(const char* filename)
{
assert(filename);
@@ -291,11 +310,10 @@ int AUD_setKeep(AUD_Handle* handle, int keep)
return AUD_device->setKeep(handle, keep);
}
-int AUD_seek(AUD_Handle* handle, double seekTo)
+int AUD_seek(AUD_Handle* handle, float seekTo)
{
assert(AUD_device);
- int position = (int)(seekTo * AUD_device->getSpecs().rate);
- return AUD_device->seek(handle, position);
+ return AUD_device->seek(handle, seekTo);
}
AUD_Status AUD_getStatus(AUD_Handle* handle)