2.5 Sound:
- Cleaned up DNA_sound_types.h, especially the bSound structure. - Fixed a caching bug.
This commit is contained in:
parent
c97d964064
commit
47ce314bc5
@ -570,7 +570,7 @@ void reload_sequence_new_file(Scene *scene, Sequence * seq)
|
||||
}
|
||||
seq->strip->len = seq->len;
|
||||
} else if (seq->type == SEQ_SOUND) {
|
||||
seq->len = AUD_getInfo(seq->sound->snd_sound).length * FPS;
|
||||
seq->len = AUD_getInfo(seq->sound->handle).length * FPS;
|
||||
seq->len -= seq->anim_startofs;
|
||||
seq->len -= seq->anim_endofs;
|
||||
if (seq->len < 0) {
|
||||
|
@ -79,11 +79,11 @@ struct bSound* sound_new_file(struct Main *main, char* filename)
|
||||
|
||||
sound = alloc_libblock(&main->sound, ID_SO, filename+len);
|
||||
strcpy(sound->name, filename);
|
||||
sound->type = SOUND_TYPE_FILE;
|
||||
// XXX unused currently sound->type = SOUND_TYPE_FILE;
|
||||
|
||||
sound_load(main, sound);
|
||||
|
||||
if(!sound->snd_sound)
|
||||
if(!sound->handle)
|
||||
{
|
||||
free_libblock(&main->sound, sound);
|
||||
sound = NULL;
|
||||
@ -109,7 +109,7 @@ struct bSound* sound_new_buffer(struct bContext *C, struct bSound *source)
|
||||
|
||||
sound_load(CTX_data_main(C), sound);
|
||||
|
||||
if(!sound->snd_sound)
|
||||
if(!sound->handle)
|
||||
{
|
||||
free_libblock(&CTX_data_main(C)->sound, sound);
|
||||
sound = NULL;
|
||||
@ -135,7 +135,7 @@ struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, floa
|
||||
|
||||
sound_load(CTX_data_main(C), sound);
|
||||
|
||||
if(!sound->snd_sound)
|
||||
if(!sound->handle)
|
||||
{
|
||||
free_libblock(&CTX_data_main(C)->sound, sound);
|
||||
sound = NULL;
|
||||
@ -162,22 +162,25 @@ void sound_cache(struct bSound* sound, int ignore)
|
||||
if(sound->cache && !ignore)
|
||||
AUD_unload(sound->cache);
|
||||
|
||||
sound->cache = AUD_bufferSound(sound->snd_sound);
|
||||
sound->cache = AUD_bufferSound(sound->handle);
|
||||
}
|
||||
|
||||
void sound_load(struct Main *main, struct bSound* sound)
|
||||
{
|
||||
if(sound)
|
||||
{
|
||||
if(sound->snd_sound)
|
||||
if(sound->handle)
|
||||
{
|
||||
AUD_unload(sound->snd_sound);
|
||||
sound->snd_sound = NULL;
|
||||
AUD_unload(sound->handle);
|
||||
sound->handle = NULL;
|
||||
}
|
||||
|
||||
// XXX unused currently
|
||||
#if 0
|
||||
switch(sound->type)
|
||||
{
|
||||
case SOUND_TYPE_FILE:
|
||||
#endif
|
||||
{
|
||||
char fullpath[FILE_MAX];
|
||||
char *path;
|
||||
@ -197,26 +200,25 @@ void sound_load(struct Main *main, struct bSound* sound)
|
||||
|
||||
/* but we need a packed file then */
|
||||
if (pf)
|
||||
sound->snd_sound = AUD_loadBuffer((unsigned char*) pf->data, pf->size);
|
||||
sound->handle = AUD_loadBuffer((unsigned char*) pf->data, pf->size);
|
||||
/* or else load it from disk */
|
||||
else
|
||||
sound->snd_sound = AUD_load(fullpath);
|
||||
sound->handle = AUD_load(fullpath);
|
||||
} // XXX
|
||||
// XXX unused currently
|
||||
#if 0
|
||||
break;
|
||||
}
|
||||
case SOUND_TYPE_BUFFER:
|
||||
if(sound->child_sound && sound->child_sound->snd_sound)
|
||||
sound->snd_sound = AUD_bufferSound(sound->child_sound->snd_sound);
|
||||
if(sound->child_sound && sound->child_sound->handle)
|
||||
sound->handle = AUD_bufferSound(sound->child_sound->handle);
|
||||
break;
|
||||
case SOUND_TYPE_LIMITER:
|
||||
if(sound->child_sound && sound->child_sound->snd_sound)
|
||||
sound->snd_sound = AUD_limitSound(sound->child_sound, sound->start, sound->end);
|
||||
if(sound->child_sound && sound->child_sound->handle)
|
||||
sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end);
|
||||
break;
|
||||
}
|
||||
|
||||
if(sound->cache)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,10 +230,10 @@ void sound_free(struct bSound* sound)
|
||||
sound->packedfile = NULL;
|
||||
}
|
||||
|
||||
if(sound->snd_sound)
|
||||
if(sound->handle)
|
||||
{
|
||||
AUD_unload(sound->snd_sound);
|
||||
sound->snd_sound = NULL;
|
||||
AUD_unload(sound->handle);
|
||||
sound->handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,20 +243,23 @@ void sound_unlink(struct bContext *C, struct bSound* sound)
|
||||
Scene *scene;
|
||||
SoundHandle *handle;
|
||||
|
||||
// XXX unused currently
|
||||
#if 0
|
||||
for(snd = CTX_data_main(C)->sound.first; snd; snd = snd->id.next)
|
||||
{
|
||||
if(snd->child_sound == sound)
|
||||
{
|
||||
snd->child_sound = NULL;
|
||||
if(snd->snd_sound)
|
||||
if(snd->handle)
|
||||
{
|
||||
AUD_unload(sound->snd_sound);
|
||||
snd->snd_sound = NULL;
|
||||
AUD_unload(sound->handle);
|
||||
snd->handle = NULL;
|
||||
}
|
||||
|
||||
sound_unlink(C, snd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for(scene = CTX_data_main(C)->scene.first; scene; scene = scene->id.next)
|
||||
{
|
||||
@ -372,9 +377,9 @@ void sound_update_playing(struct bContext *C)
|
||||
{
|
||||
if(handle->state == AUD_STATUS_INVALID)
|
||||
{
|
||||
if(handle->source && handle->source->snd_sound)
|
||||
if(handle->source && handle->source->handle)
|
||||
{
|
||||
AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->snd_sound, handle->frameskip / fps, (handle->frameskip + handle->endframe - handle->startframe)/fps);
|
||||
AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->handle, handle->frameskip / fps, (handle->frameskip + handle->endframe - handle->startframe)/fps);
|
||||
handle->handle = AUD_play(limiter, 1);
|
||||
AUD_unload(limiter);
|
||||
if(handle->handle)
|
||||
@ -413,10 +418,10 @@ void sound_scrub(struct bContext *C)
|
||||
{
|
||||
if(cfra >= handle->startframe && cfra < handle->endframe && !handle->mute)
|
||||
{
|
||||
if(handle->source && handle->source->snd_sound)
|
||||
if(handle->source && handle->source->handle)
|
||||
{
|
||||
int frameskip = handle->frameskip + cfra - handle->startframe;
|
||||
AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->snd_sound, frameskip / fps, (frameskip + 1)/fps);
|
||||
AUD_Sound* limiter = AUD_limitSound(handle->source->cache ? handle->source->cache : handle->source->handle, frameskip / fps, (frameskip + 1)/fps);
|
||||
AUD_play(limiter, 0);
|
||||
AUD_unload(limiter);
|
||||
}
|
||||
@ -439,7 +444,7 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_Specs specs, int start, int e
|
||||
|
||||
for(handle = scene->sound_handles.first; handle; handle = handle->next)
|
||||
{
|
||||
if(start < handle->endframe && end > handle->startframe && !handle->mute && handle->source && handle->source->snd_sound)
|
||||
if(start < handle->endframe && end > handle->startframe && !handle->mute && handle->source && handle->source->handle)
|
||||
{
|
||||
frameskip = handle->frameskip;
|
||||
s = handle->startframe - start;
|
||||
@ -451,7 +456,7 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_Specs specs, int start, int e
|
||||
s = 0;
|
||||
}
|
||||
|
||||
limiter = AUD_limitSound(handle->source->snd_sound, frameskip / fps, e / fps);
|
||||
limiter = AUD_limitSound(handle->source->handle, frameskip / fps, e / fps);
|
||||
delayer = AUD_delaySound(limiter, s / fps);
|
||||
|
||||
AUD_playDevice(mixdown, delayer);
|
||||
|
@ -5061,10 +5061,13 @@ static void fix_relpaths_library(const char *basepath, Main *main)
|
||||
|
||||
static void direct_link_sound(FileData *fd, bSound *sound)
|
||||
{
|
||||
sound->snd_sound = NULL;
|
||||
sound->handle = NULL;
|
||||
|
||||
sound->packedfile = direct_link_packedfile(fd, sound->packedfile);
|
||||
sound->newpackedfile = direct_link_packedfile(fd, sound->newpackedfile);
|
||||
|
||||
if(sound->cache)
|
||||
sound_cache(sound, 1);
|
||||
}
|
||||
|
||||
static void lib_link_sound(FileData *fd, Main *main)
|
||||
@ -5076,8 +5079,7 @@ static void lib_link_sound(FileData *fd, Main *main)
|
||||
if(sound->id.flag & LIB_NEEDLINK) {
|
||||
sound->id.flag -= LIB_NEEDLINK;
|
||||
sound->ipo= newlibadr_us(fd, sound->id.lib, sound->ipo); // XXX depreceated - old animation system
|
||||
sound->stream = 0;
|
||||
|
||||
|
||||
sound_load(main, sound);
|
||||
}
|
||||
sound= sound->id.next;
|
||||
|
@ -242,13 +242,13 @@ static Sequence* sequencer_add_sound_strip(bContext *C, wmOperator *op, int star
|
||||
|
||||
sound = sound_new_file(CTX_data_main(C), filename);
|
||||
|
||||
if (sound==NULL || sound->snd_sound == NULL) {
|
||||
if (sound==NULL || sound->handle == NULL) {
|
||||
if(op)
|
||||
BKE_report(op->reports, RPT_ERROR, "Unsupported audio format");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
info = AUD_getInfo(sound->snd_sound);
|
||||
info = AUD_getInfo(sound->handle);
|
||||
|
||||
if (info.specs.format == AUD_FORMAT_INVALID) {
|
||||
sound_delete(C, sound);
|
||||
|
@ -225,108 +225,6 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
|
||||
}
|
||||
}
|
||||
|
||||
static void drawseqwave(Scene *scene, View2D *v2d, Sequence *seq, float x1, float y1, float x2, float y2, int winx)
|
||||
{
|
||||
/*
|
||||
x1 is the starting x value to draw the wave,
|
||||
x2 the end x value, same for y1 and y2
|
||||
winx is the zoom level.
|
||||
*/
|
||||
|
||||
float
|
||||
f, /* floating point value used to store the X draw location for the wave lines when openGL drawing*/
|
||||
midy, /* fast access to the middle location (y1+y2)/2 */
|
||||
clipxmin, /* the minimum X value, clip this with the window */
|
||||
clipxmax, /* the maximum X value, clip this with the window */
|
||||
sample_step, /* steps to move per sample, floating value must later translate into an int */
|
||||
fsofs, /* steps to move per sample, floating value must later translate into an int */
|
||||
feofs_sofs, /* */
|
||||
sound_width, /* convenience: x2-x1 */
|
||||
wavemulti; /* scale the samples by this value when GL_LINE drawing so it renders the right height */
|
||||
|
||||
int
|
||||
offset, /* initial offset value for the wave drawing */
|
||||
offset_next, /* when in the wave drawing loop this value is the samples intil the next vert */
|
||||
sofs, /* Constrained offset value (~3) for the wave, start */
|
||||
eofs, /* ditto, end */
|
||||
wavesample, /* inner loop storage if the current wave sample value, used to make the 2 values below */
|
||||
wavesamplemin, /* used for finding the min and max wave peaks */
|
||||
wavesamplemax, /* ditto */
|
||||
subsample_step=4; /* when the sample step is 4 every sample of
|
||||
the wave is evaluated for min and max values used to draw the wave,
|
||||
however this is slow ehrn zoomed out so when the sample step is above
|
||||
1 (the larger the further out the zoom is) so not evaluate all samples, only some. */
|
||||
|
||||
signed short* s;
|
||||
bSound *sound;
|
||||
uint8_t *stream;
|
||||
|
||||
// XXX audio_makestream(seq->sound);
|
||||
if(seq->sound==NULL || seq->sound->stream==NULL) return;
|
||||
|
||||
if (seq->flag & SEQ_MUTE) glColor3ub(0x70, 0x80, 0x80); else glColor3ub(0x70, 0xc0, 0xc0);
|
||||
|
||||
sofs = ((int)( FRA2TIME(seq->startdisp-seq->start+seq->anim_startofs)*(float)scene->r.audio.mixrate*4.0 )) & (~3);
|
||||
eofs = ((int)( FRA2TIME(seq->enddisp-seq->start+seq->anim_startofs)*(float)scene->r.audio.mixrate*4.0 )) & (~3);
|
||||
|
||||
/* clip the drawing area to the screen bounds to save time */
|
||||
sample_step= (v2d->cur.xmax - v2d->cur.xmin)/winx;
|
||||
clipxmin= MAX2(x1, v2d->cur.xmin);
|
||||
clipxmax= MIN2(x2, v2d->cur.xmax);
|
||||
|
||||
if (sample_step > 1)
|
||||
subsample_step= ((int)(subsample_step*sample_step*8)) & (~3);
|
||||
|
||||
/* for speedy access */
|
||||
midy = (y1+y2)/2;
|
||||
fsofs= (float)sofs;
|
||||
feofs_sofs= (float)(eofs-sofs);
|
||||
sound_width= x2-x1;
|
||||
sound = seq->sound;
|
||||
stream = sound->stream;
|
||||
wavemulti = (y2-y1)/196605; /*y2-y1 is the height*/
|
||||
wavesample=0;
|
||||
|
||||
/* we need to get the starting offset value, excuse the duplicate code */
|
||||
f=clipxmin;
|
||||
offset= (int) (fsofs + ((f-x1)/sound_width) * feofs_sofs) & (~3);
|
||||
|
||||
/* start the loop, draw a line per sample_step -sample_step is about 1 line drawn per pixel */
|
||||
glBegin(GL_LINES);
|
||||
for (f=x1+sample_step; f<=clipxmax; f+=sample_step) {
|
||||
|
||||
offset_next = (int) (fsofs + ((f-x1)/sound_width) * feofs_sofs) & (~3);
|
||||
if (f > v2d->cur.xmin) {
|
||||
/* if this is close to the last sample just exit */
|
||||
if (offset_next >= sound->streamlen) break;
|
||||
|
||||
wavesamplemin = 131070;
|
||||
wavesamplemax = -131070;
|
||||
|
||||
/*find with high and low of the waveform for this draw,
|
||||
evaluate small samples to find this range */
|
||||
while (offset < offset_next) {
|
||||
s = (signed short*)(stream+offset);
|
||||
|
||||
wavesample = s[0]*2 + s[1];
|
||||
if (wavesamplemin>wavesample)
|
||||
wavesamplemin=wavesample;
|
||||
if (wavesamplemax<wavesample)
|
||||
wavesamplemax=wavesample;
|
||||
offset+=subsample_step;
|
||||
}
|
||||
/* draw the wave line, looks good up close and zoomed out */
|
||||
glVertex2f(f, midy-(wavemulti*wavesamplemin) );
|
||||
glVertex2f(f, midy-(wavemulti*wavesamplemax) );
|
||||
} else {
|
||||
while (offset < offset_next) offset+=subsample_step;
|
||||
}
|
||||
|
||||
offset=offset_next;
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/* draw a handle, for each end of a sequence strip */
|
||||
static void draw_seq_handle(View2D *v2d, Sequence *seq, float pixelx, short direction)
|
||||
{
|
||||
@ -660,10 +558,6 @@ static void draw_seq_strip(Scene *scene, ARegion *ar, SpaceSeq *sseq, Sequence *
|
||||
draw_shadedstrip(seq, background_col, x1, y1, x2, y2);
|
||||
|
||||
/* draw additional info and controls */
|
||||
// XXX
|
||||
if(0) // (seq->type == SEQ_SOUND)
|
||||
drawseqwave(scene, v2d, seq, x1, y1, x2, y2, ar->winx);
|
||||
|
||||
if (!is_single_image)
|
||||
draw_seq_extensions(scene, sseq, seq);
|
||||
|
||||
|
@ -70,57 +70,59 @@ typedef struct Sound3D
|
||||
|
||||
typedef struct bSound {
|
||||
ID id;
|
||||
char name[160];
|
||||
void *stream; // AUD_XXX deprecated
|
||||
struct PackedFile *packedfile;
|
||||
struct PackedFile *newpackedfile; // AUD_XXX deprecated
|
||||
void *snd_sound; // AUD_XXX used for AUD_Sound now
|
||||
struct Ipo *ipo; // AUD_XXX deprecated
|
||||
float volume, panning; // AUD_XXX deprecated
|
||||
/**
|
||||
* Sets the rollofffactor. The rollofffactor is a per-Source parameter
|
||||
* the application can use to increase or decrease the range of a source
|
||||
* by decreasing or increasing the attenuation, respectively. The default
|
||||
* value is 1. The implementation is free to optimize for a rollofffactor
|
||||
* value of 0, which indicates that the application does not wish any
|
||||
* distance attenuation on the respective Source.
|
||||
*/
|
||||
float attenuation; // AUD_XXX deprecated
|
||||
float pitch; // AUD_XXX deprecated
|
||||
/**
|
||||
* min_gain indicates the minimal gain which is always guaranteed for this sound
|
||||
*/
|
||||
float min_gain; // AUD_XXX deprecated
|
||||
/**
|
||||
* max_gain indicates the maximal gain which is always guaranteed for this sound
|
||||
*/
|
||||
float max_gain; // AUD_XXX deprecated
|
||||
/**
|
||||
* Sets the referencedistance at which the listener will experience gain.
|
||||
*/
|
||||
float distance; // AUD_XXX deprecated
|
||||
int flags; // AUD_XXX deprecated
|
||||
int streamlen; // AUD_XXX deprecated
|
||||
char channels; // AUD_XXX deprecated
|
||||
char highprio; // AUD_XXX deprecated
|
||||
char pad[10]; // AUD_XXX deprecated
|
||||
|
||||
// AUD_XXX NEW
|
||||
int type;
|
||||
/**
|
||||
* The path to the sound file.
|
||||
*/
|
||||
char name[160];
|
||||
|
||||
/**
|
||||
* The packed file.
|
||||
*/
|
||||
struct PackedFile *packedfile;
|
||||
|
||||
/**
|
||||
* The handle for audaspace.
|
||||
*/
|
||||
void *handle;
|
||||
|
||||
/**
|
||||
* Deprecated; used for loading pre 2.5 files.
|
||||
*/
|
||||
struct PackedFile *newpackedfile;
|
||||
struct Ipo *ipo;
|
||||
float volume;
|
||||
float attenuation;
|
||||
float pitch;
|
||||
float min_gain;
|
||||
float max_gain;
|
||||
float distance;
|
||||
int flags;
|
||||
|
||||
/** currently int type;
|
||||
struct bSound *child_sound;*/
|
||||
|
||||
/**
|
||||
* Whether the sound has been changed and must be restarted if playing.
|
||||
*/
|
||||
int changed;
|
||||
struct bSound *child_sound;
|
||||
|
||||
/**
|
||||
* The audaspace handle for cache.
|
||||
*/
|
||||
void *cache;
|
||||
|
||||
// SOUND_TYPE_LIMITER
|
||||
float start, end;
|
||||
/** XXX unused currently // SOUND_TYPE_LIMITER
|
||||
float start, end;*/
|
||||
} bSound;
|
||||
|
||||
/* XXX unused currently
|
||||
typedef enum eSound_Type {
|
||||
SOUND_TYPE_INVALID = -1,
|
||||
SOUND_TYPE_FILE = 0,
|
||||
SOUND_TYPE_BUFFER,
|
||||
SOUND_TYPE_LIMITER
|
||||
} eSound_Type;
|
||||
} eSound_Type;*/
|
||||
|
||||
/* spacesound->flag */
|
||||
#define SND_DRAWFRAMES 1
|
||||
@ -142,18 +144,7 @@ typedef struct SpaceSound {
|
||||
int pad2;
|
||||
} SpaceSound;
|
||||
|
||||
|
||||
#define SOUND_CHANNELS_STEREO 0
|
||||
#define SOUND_CHANNELS_LEFT 1
|
||||
#define SOUND_CHANNELS_RIGHT 2
|
||||
|
||||
#define SOUND_FLAGS_LOOP (1 << 0)
|
||||
#define SOUND_FLAGS_FIXED_VOLUME (1 << 1)
|
||||
#define SOUND_FLAGS_FIXED_PANNING (1 << 2)
|
||||
#define SOUND_FLAGS_3D (1 << 3)
|
||||
#define SOUND_FLAGS_BIDIRECTIONAL_LOOP (1 << 4)
|
||||
#define SOUND_FLAGS_PRIORITY (1 << 5)
|
||||
#define SOUND_FLAGS_SEQUENCE (1 << 6)
|
||||
|
||||
/* to DNA_sound_types.h*/
|
||||
|
||||
|
@ -396,7 +396,7 @@ void BL_ConvertActuators(char* maggiename,
|
||||
"\" has no sound datablock." << std::endl;
|
||||
}
|
||||
else
|
||||
snd_sound = sound->cache ? sound->cache : sound->snd_sound;
|
||||
snd_sound = sound->cache ? sound->cache : sound->handle;
|
||||
KX_SoundActuator* tmpsoundact =
|
||||
new KX_SoundActuator(gameobj,
|
||||
snd_sound,
|
||||
|
Loading…
Reference in New Issue
Block a user