Merged 15170:15635 from trunk (no conflicts or even merges)
[blender.git] / source / blender / src / editsound.c
index 8f384da000b8bcb341b596dfb32f78c6e7b961e2..05eb094a7c21a3b13b8533eb62c27ed623afb719 100644 (file)
@@ -1,15 +1,12 @@
 /**
  * $Id$
  *
- * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. The Blender
- * Foundation also sells licenses for use in proprietary software under
- * the Blender License.  See http://www.blender.org/BL/ for information
- * about this.
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,7 +24,7 @@
  *
  * Contributor(s): none yet.
  *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * ***** END GPL LICENSE BLOCK *****
  */
 
 #include <stdio.h>
 
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
+#include "DNA_space_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_sound_types.h"
 #include "DNA_packedFile_types.h"
+#include "DNA_userdef_types.h"
 
 #include "BKE_utildefines.h"
 #include "BKE_global.h"
 #include "BIF_interface.h"
 #include "BIF_editsound.h"
 #include "BIF_mywindow.h"
+#include "BIF_toolbox.h"
 
 #include "BSE_drawipo.h"
 #include "BSE_headerbuttons.h"
+#include "BSE_time.h"
+
+#include "BDR_editobject.h"
 
 #include "blendef.h"
 
@@ -84,6 +87,9 @@
 
 #include "SYS_System.h"
 
+#include "PIL_time.h"
+
+
 /* this might move to the external header */
 void* sound_get_libraryinterface(void);
 
@@ -108,12 +114,24 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
        float dx, dy;
        int doredraw= 0, cfra, first = 0;
        short mval[2], nr;
+       short mousebut = L_MOUSE;
        
        if(curarea->win==0) return;
 
        if(val) {
                
-               if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
+               if( uiDoBlocks(&curarea->uiblocks, event, 1)!=UI_NOTHING ) event= 0;
+
+               /* swap mouse buttons based on user preference */
+               if (U.flag & USER_LMOUSESELECT) {
+                       if (event == LEFTMOUSE) {
+                               event = RIGHTMOUSE;
+                               mousebut = L_MOUSE;
+                       } else if (event == RIGHTMOUSE) {
+                               event = LEFTMOUSE;
+                               mousebut = R_MOUSE;
+                       }
+               }
 
                switch(event) {
                case LEFTMOUSE:
@@ -122,7 +140,7 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                getmouseco_areawin(mval);
                                areamouseco_to_ipoco(G.v2d, mval, &dx, &dy);
                                
-                               cfra = (int)dx;
+                               cfra = (int)(dx+0.5f);
                                if(cfra< 1) cfra= 1;
                                
                                if( cfra!=CFRA || first )
@@ -130,10 +148,11 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        first= 0;
                                        CFRA= cfra;
                                        update_for_newframe();
-                                       force_draw_plus(SPACE_VIEW3D);
+                                       force_draw_all(0);
                                }
+                               else PIL_sleep_ms(30);
                        
-                       } while(get_mbut()&L_MOUSE);
+                       } while(get_mbut() & mousebut);
                        ssound->flag &= ~SND_CFRA_NUM;
                        
                        doredraw= 1;
@@ -145,20 +164,34 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        view2dmove(event);      /* in drawipo.c */
                        break;
                case RIGHTMOUSE:
-                       nr= pupmenu("Time value%t|Frames %x1|Seconds%x2");
-                       if (nr>0) {
-                               if(nr==1) ssound->flag |= SND_DRAWFRAMES;
-                               else ssound->flag &= ~SND_DRAWFRAMES;
-                               doredraw= 1;
-                       }
+                       {
+                               TimeMarker *marker;
+                               
+                               getmouseco_areawin(mval);
+                               areamouseco_to_ipoco(G.v2d, mval, &dx, &dy);
 
+                               marker = find_nearest_marker(SCE_MARKERS, 0);
+                               if (marker) {
+                                       if ((G.qual & LR_SHIFTKEY)==0)
+                                               deselect_markers(0, 0);
+                                               
+                                       if (marker->flag & SELECT)
+                                               marker->flag &= ~SELECT;
+                                       else
+                                               marker->flag |= SELECT;
+                               }
+                               
+                               force_draw(0);
+                               std_rmouse_transform(transform_markers);
+                       }
                        break;
+                       
                case PADPLUSKEY:
                        dx= (float)(0.1154*(G.v2d->cur.xmax-G.v2d->cur.xmin));
                        G.v2d->cur.xmin+= dx;
                        G.v2d->cur.xmax-= dx;
                        test_view2d(G.v2d, curarea->winx, curarea->winy);
-
+                       view2d_do_locks(curarea, V2D_LOCK_COPY);
                        doredraw= 1;
                        break;
                case PADMINUS:
@@ -166,12 +199,68 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        G.v2d->cur.xmin-= dx;
                        G.v2d->cur.xmax+= dx;
                        test_view2d(G.v2d, curarea->winx, curarea->winy);
-
+                       view2d_do_locks(curarea, V2D_LOCK_COPY);
                        doredraw= 1;
                        break;
                case HOMEKEY:
                        do_sound_buttons(B_SOUNDHOME);
                        break;
+                       
+               case PAGEUPKEY: /* cfra to next marker */
+                       nextprev_marker(1);
+                       break;
+               case PAGEDOWNKEY: /* cfra to prev marker */
+                       nextprev_marker(-1);
+                       break;
+               
+               case AKEY: /* select/deselect all  */
+                       deselect_markers(1, 0);
+                       
+                       allqueue(REDRAWMARKER, 0);
+                       break;
+                       
+               case BKEY: /* borderselect markers */
+                       borderselect_markers();
+                       break;
+               
+               case DKEY: /* duplicate selected marker(s) */
+                       if (G.qual & LR_SHIFTKEY) {
+                               duplicate_marker();
+                               
+                               allqueue(REDRAWMARKER, 0);
+                       }
+                       break;
+                       
+               case GKEY:
+                       transform_markers('g', 0);
+                       break;
+                       
+               case MKEY: /* add marker or rename first selected */
+                       if (G.qual & LR_CTRLKEY)
+                               rename_marker();
+                       else
+                               add_marker(CFRA);
+                       
+                       allqueue(REDRAWMARKER, 0);
+                       break;          
+               
+               case TKEY: /* toggle time display */
+                       nr= pupmenu("Time value%t|Frames %x1|Seconds%x2");
+                       if (nr>0) {
+                               if(nr==1) ssound->flag |= SND_DRAWFRAMES;
+                               else ssound->flag &= ~SND_DRAWFRAMES;
+                               doredraw= 1;
+                       }
+
+                       break;
+                       
+               case DELKEY: /* delete selected markers */
+               case XKEY:
+                       if (okee("Erase selected")) {
+                               remove_marker();
+                               allqueue(REDRAWMARKER, 0);
+                       }
+                       break;
                }
        }
 
@@ -183,29 +272,28 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 
 void sound_initialize_sounds(void)
 {
-       bSoundsound;
+       bSound *sound;
 
        if(ghSoundScene) {
 
                /* clear the soundscene */
                SND_RemoveAllSounds(ghSoundScene);
                SND_RemoveAllSamples(ghSoundScene);
+       }
        
-               /* initialize sounds */
-               sound = G.main->sound.first;
-               while (sound)
-               {
-                       sound_sample_is_null(sound);
-                       sound = (bSound *) sound->id.next;
-               }
+       /* initialize sample blocks (doesnt call audio system, needs to be done once after load */
+       sound = G.main->sound.first;
+       while (sound) {
+               sound_sample_is_null(sound);
+               sound = (bSound *) sound->id.next;
        }
 }
 
 
 
-bSound* sound_make_copy(bSound* originalsound)
+bSound *sound_make_copy(bSound *originalsound)
 {
-       bSoundsound = NULL;
+       bSound *sound = NULL;
        char name[160];
        int len;
        
@@ -255,7 +343,7 @@ bSound* sound_make_copy(bSound* originalsound)
 
 
 
-void sound_initialize_sample(bSoundsound)
+void sound_initialize_sample(bSound *sound)
 {
        if(ghSoundScene==NULL) sound_init_audio();
 
@@ -264,7 +352,7 @@ void sound_initialize_sample(bSound* sound)
 }
 
 
-void sound_read_wav_data(bSound* sound, PackedFile* pf)
+void sound_read_wav_data(bSound *sound, PackedFile *pf)
 {
        int i, temp;
        short shortbuf, *temps;
@@ -281,46 +369,31 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
        rewindPackedFile(pf);
 
        /* check to see if it is a file in "RIFF WAVE fmt" format */
-       if (readPackedFile(pf, buffer, 16) != 16)
-       {
+       if (readPackedFile(pf, buffer, 16) != 16) {
                if (G.f & G_DEBUG) printf("File too short\n");
                return;
        }
 
-       if(!(memcmp(buffer, "RIFF", 4) && memcmp(&(buffer[8]), "WAVEfmt ", 8)))
-       {
+       if(!(memcmp(buffer, "RIFF", 4) && memcmp(&(buffer[8]), "WAVEfmt ", 8))) {
                readPackedFile(pf, &i, 4);// start of data
                if(G.order==B_ENDIAN)
                        SWITCH_INT(i);
 
                /* read the sampleformat */
                readPackedFile(pf, &shortbuf, 2);
-               if(G.order==B_ENDIAN)
-               {
-                       /* was SWITCH_SHORT before */
-                       char s_i, *p_i;
-                       p_i= (char *)&(shortbuf);
-                       s_i= p_i[0];
-                       p_i[0]= p_i[1];
-                       p_i[1]= s_i;
+               if(G.order==B_ENDIAN) {
+                       SWITCH_SHORT(shortbuf);
                }
 
                /* read the number of channels */
                readPackedFile(pf, &shortbuf, 2);
 
-               if(G.order==B_ENDIAN)
-               {
-                       /* was SWITCH_SHORT before */
-                       char s_i, *p_i;
-                       p_i= (char *)&(shortbuf);
-                       s_i= p_i[0];
-                       p_i[0]= p_i[1];
-                       p_i[1]= s_i;
+               if(G.order==B_ENDIAN) {
+                       SWITCH_SHORT(shortbuf);
                }
 
                /* check the number of channels */
-               if(shortbuf != 1 && shortbuf != 2)
-               {
+               if(shortbuf != 1 && shortbuf != 2) {
                        if (G.f & G_DEBUG) printf("Unsupported number of channels\n");
                        return;
                }
@@ -348,22 +421,15 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
 
                readPackedFile(pf, &shortbuf, 2);
                readPackedFile(pf, &shortbuf, 2);
-               if(G.order==B_ENDIAN)
-               {
-                       /* was SWITCH_SHORT before */
-                       char s_i, *p_i;
-                       p_i= (char *)&(shortbuf);
-                       s_i= p_i[0];
-                       p_i[0]= p_i[1];
-                       p_i[1]= s_i;
+               if(G.order==B_ENDIAN) {
+                       SWITCH_SHORT(shortbuf);
                }
                bits = shortbuf;
                
                seekPackedFile(pf, i-16, SEEK_CUR);
                readPackedFile(pf, buffer, 4);
                /* check if we have a 'data' chunk */
-               while(memcmp(buffer, "data", 4)!=0)
-               {
+               while(memcmp(buffer, "data", 4)!=0) {
                        if (readPackedFile(pf, &i, 4) != 4)
                                break;
                        
@@ -376,13 +442,11 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
                }
                
                /* guess not */
-               if (memcmp(buffer, "data", 4) !=0)
-               {
+               if (memcmp(buffer, "data", 4) !=0) {
                        if (G.f & G_DEBUG) printf("No data found\n");
                }
                /* or maybe we do! */
-               else
-               {
+               else {
                        readPackedFile(pf, &longbuf, 4); 
                        if(G.order==B_ENDIAN) SWITCH_INT(longbuf);
                        
@@ -396,21 +460,17 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
                        len = longbuf /*/ 4.0*/; /* for some strange reason the sample length is off by a factor of 4... */
                        /* intrr's comment: Funny eh, how one 16-bit stereo sample is 4 bytes? :-) */
                        
-                       if(data)
-                       {
+                       if(data) {
                                readPackedFile(pf, data, len);
                                /* data is only used to draw! */
-                               if (bits == 8)
-                               {
+                               if (bits == 8) {
                                        temps = (short *) data;
                                        tempc = (char *) data;
                                        for (i = len - 1; i >= 0; i--)
                                                temps[i] = tempc[i] << 8;
                                }
-                               else
-                               {
-                                       if(G.order==B_ENDIAN)
-                                       {
+                               else {
+                                       if(G.order==B_ENDIAN) {
                                                swab(data, data, len);
                                        }
                                }
@@ -425,8 +485,7 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
                        }
                }
        }
-       else
-       {
+       else {
                sound->sample->type = SAMPLE_INVALID;
                if (G.f & G_DEBUG) printf("Unsupported sound format: %s\n", sound->name);
        }
@@ -435,7 +494,7 @@ void sound_read_wav_data(bSound* sound, PackedFile* pf)
 
 
 /* ugly, but it works (for now) */
-int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
+static int sound_get_filetype_from_header(bSound *sound, PackedFile *pf)
 {
        int filetype = SAMPLE_INVALID;
        int i;
@@ -444,22 +503,19 @@ int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
        
        rewindPackedFile(pf);
        
-       if (readPackedFile(pf, buffer, 16) != 16)
-       {
+       if (readPackedFile(pf, buffer, 16) != 16) {
                if (G.f & G_DEBUG) printf("File too short\n");
                return filetype;
        }
        
-       if(!(memcmp(buffer, "RIFF", 4) && memcmp(&(buffer[8]), "WAVEfmt ", 8)))
-       {
+       if(!(memcmp(buffer, "RIFF", 4) && memcmp(&(buffer[8]), "WAVEfmt ", 8))) {
                readPackedFile(pf, &i, 4);
                if(G.order==B_ENDIAN)
                        SWITCH_INT(i);
                
                /* read the sampleformat */
                readPackedFile(pf, &shortbuf, 2);
-               if(G.order==B_ENDIAN)
-               {
+               if(G.order==B_ENDIAN) {
                        char s_i, *p_i;
                        p_i= (char *)&(shortbuf);
                        s_i= p_i[0];
@@ -467,8 +523,7 @@ int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
                        p_i[1]= s_i;
                }
                
-               if (shortbuf == SND_WAVE_FORMAT_PCM)
-               {
+               if (shortbuf == SND_WAVE_FORMAT_PCM) {
                        filetype = SAMPLE_WAV;
                }
                else
@@ -497,17 +552,14 @@ int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
 #ifdef USE_FMOD
                }
        }
-       else if (!memcmp(buffer, "OggS", 4))
-       {
+       else if (!memcmp(buffer, "OggS", 4)) {
                filetype = SAMPLE_OGG_VORBIS;
        }
-       else if ((!memcmp(buffer, "ID3", 3)) || (!memcmp(buffer, "ÿû", 2)))
-       {
+       else if ((!memcmp(buffer, "ID3", 3)) || (!memcmp(buffer, "", 2))) {
                filetype = SAMPLE_MP3;
        }
 #endif
-       else
-       {
+       else {
                filetype = SAMPLE_INVALID;
                if (G.f & G_DEBUG) printf("Unsupported sound format: %s\n", sound->name);
        }
@@ -517,7 +569,7 @@ int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
 
 
 
-int check_filetype(bSound* sound, PackedFile* pf)
+static int check_filetype(bSound *sound, PackedFile *pf)
 {
 //     char* pdest;
        sound->sample->type = SAMPLE_INVALID;
@@ -547,8 +599,7 @@ int check_filetype(bSound* sound, PackedFile* pf)
        sound->sample->type = sound_get_filetype_from_header(sound, pf);
 
        /* get some info from the sample */
-       switch (sound->sample->type)
-       {
+       switch (sound->sample->type) {
        case SAMPLE_WAV:
                {
                        sound_read_wav_data(sound, pf);
@@ -573,24 +624,22 @@ int check_filetype(bSound* sound, PackedFile* pf)
 
 
 
-int sound_load_sample(bSoundsound)
+int sound_load_sample(bSound *sound)
 {
        int result = FALSE;
-       PackedFilepf;
+       PackedFile *pf;
        int freePF = FALSE;
        int buffer = -1;
 
        if(ghSoundScene==NULL) sound_init_audio();
 
        /* check the sample (valid?) */
-       if (sound->sample->type == SAMPLE_UNKNOWN || sound->snd_sound == NULL)
-       {
+       if (sound->sample->type == SAMPLE_UNKNOWN || sound->snd_sound == NULL) {
                /* find... */
                pf = sound_find_packedfile(sound);
 
                /* ...or create a (temp)packedfile */
-               if (pf == NULL)
-               {
+               if (pf == NULL) {
                        pf = newPackedFile(sound->name);
                        
                        /* if autopack is off, free the pf afterwards */
@@ -599,14 +648,12 @@ int sound_load_sample(bSound* sound)
                }
                
                /* if we have a valid pf... */
-               if (pf)
-               {
+               if (pf) {
                        /* check the content of the pf */
                        check_filetype(sound, pf);
 
                        /* check if the sampletype is supported */
-                       if (sound->sample->type != SAMPLE_INVALID && sound->sample->type != SAMPLE_UNKNOWN)
-                       {
+                       if (sound->sample->type != SAMPLE_INVALID && sound->sample->type != SAMPLE_UNKNOWN) {
                                /* register the sample at the audiodevice */
                                buffer = SND_AddSample(ghSoundScene, sound->sample->name, pf->data, pf->size);
 
@@ -625,33 +672,28 @@ int sound_load_sample(bSound* sound)
                                        result = TRUE;
                        }
                        /* if not, free the pf */
-                       else
-                       {
+                       else {
                                freePF = TRUE;
                        }
                        
                        /* if you want it freed, make it so */
-                       if (freePF)
-                       {
+                       if (freePF) {
                                freePackedFile(pf);
                                pf = NULL;
                        } 
                        /* or else connect the pf to the sound and sample */
-//                     else
-//                     {
+//                     else {
                                sound->newpackedfile = pf;
                                sound->sample->packedfile = pf;
 //                     }
                }
-               else 
-               {
+               else  {
                        if (G.f & G_DEBUG) printf("%s: File not found!\n", sound->name);
                        sound->sample->type = SAMPLE_INVALID;
                }
        }
        /* if the sample ain't invalid, we're ready to go! */
-       else if (sound->sample->type != SAMPLE_INVALID)
-       {
+       else if (sound->sample->type != SAMPLE_INVALID) {
                result = TRUE;
        }
 
@@ -660,7 +702,7 @@ int sound_load_sample(bSound* sound)
 
 
 
-bSound* sound_new_sound(char* name)
+bSound *sound_new_sound(char *name)
 {
        bSound *sound = NULL;
        int len, file;
@@ -671,13 +713,12 @@ bSound* sound_new_sound(char* name)
        if (!G.scene->audio.mixrate) G.scene->audio.mixrate = 44100;
        /* convert the name to absolute path */
        strcpy(str, name);
-       BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
+       BLI_convertstringcode(str, G.sce);
 
        /* check if the sample on disk can be opened */
        file = open(str, O_BINARY|O_RDONLY);
        
-       if (file != -1)
-       {
+       if (file != -1) {
                close(file);
 
 
@@ -696,8 +737,7 @@ bSound* sound_new_sound(char* name)
                /* load the sample & check if this blender supports the sound format */
 //             sound_load_sample(sound);
 
-               if (sound->sample->type == SAMPLE_INVALID)
-               {
+               if (sound->sample->type == SAMPLE_INVALID) {
                        free_libblock(&G.main->sound, sound);
                        sound = NULL;
                } 
@@ -722,13 +762,8 @@ int sound_set_sample(bSound *sound, bSample *sample)
        
        if(ghSoundScene==NULL) sound_init_audio();
        
-       /* decrease the usernumber for this sample */
-       if (sound->sample)
-               sound->sample->id.us--;
-
        /* delete the soundobject */
-       if (sound->snd_sound)
-       {
+       if (sound->snd_sound) {
                SND_RemoveSound(ghSoundScene, sound->snd_sound);
                sound->snd_sound = NULL;
        }
@@ -737,22 +772,17 @@ int sound_set_sample(bSound *sound, bSample *sample)
        sound->sample = sample;
        sound->newpackedfile = NULL;
        
-       /* increase the usercount */
-       if (sound->sample)
-       {
-               sound->sample->id.us++;
+       if (sound->sample) {
 
                /* and set the right pf */
                sound->newpackedfile = sample->packedfile;
 
                /* if the sampletype is unknown initialize it */
-               if (sound->sample->type == SAMPLE_UNKNOWN)
-               {
+               if (sound->sample->type == SAMPLE_UNKNOWN) {
                        sound_initialize_sample(sound);
                        
                        /* load the sample & check if this blender supports the sound format */
-                       if (!sound_load_sample(sound))
-                       {
+                       if (!sound_load_sample(sound)) {
                                result = FALSE;
                        }
                }
@@ -763,14 +793,14 @@ int sound_set_sample(bSound *sound, bSample *sample)
 
 
 
-bSample *sound_new_sample(bSound * sound)
+bSample *sound_new_sample(bSound *sound)
 {
+       char samplename[FILE_MAX];
        bSample *sample = NULL;
        int len;
        char *name;
        
-       if (sound != NULL)
-       {
+       if (sound != NULL) {
                name = sound->name;     
                len = strlen(name);
                /* do some name magic */
@@ -778,7 +808,10 @@ bSample *sound_new_sample(bSound * sound)
                        len--;
                
                /* allocate the memory for the sample */
-               sample = alloc_libblock(samples, ID_SAMPLE, name + len);
+               sample = MEM_callocN(sizeof(bSample), "sample");
+               BLI_strncpy(sample->id.name+2, name+len, 20);
+               BLI_addtail(samples, sample);   /* samples is ugly global */
+               
                sample->data = &sample->fakedata[0];
                sample->type = SAMPLE_UNKNOWN;
                
@@ -789,9 +822,12 @@ bSample *sound_new_sample(bSound * sound)
                sample->alindex = SAMPLE_INVALID;
 
                /* convert sound->name to abolute filename */
-               strcpy(sample->name, sound->name);
-               BLI_convertstringcode(sample->name, G.sce, G.scene->r.cfra);
-               
+               /* TODO: increase sound->name, sample->name and strip->name to FILE_MAX, to avoid
+                  cutting off sample name here - elubie */
+               BLI_strncpy(samplename, sound->name, FILE_MAX);         
+               BLI_convertstringcode(samplename, G.sce);
+               BLI_strncpy(sample->name, samplename, FILE_MAXDIR);
+
                /* connect the pf to the sample */
                if (sound->newpackedfile)
                        sample->packedfile = sound->newpackedfile;
@@ -805,26 +841,23 @@ bSample *sound_new_sample(bSound * sound)
 
 
 /* find a sample that might already be loaded */
-bSample* sound_find_sample(bSound* sound)
+bSample *sound_find_sample(bSound *sound)
 {
-       bSamplesample;
+       bSample *sample;
        char name[FILE_MAXDIR + FILE_MAXFILE];
        char samplename[FILE_MAXDIR + FILE_MAXFILE];
        
        // convert sound->name to abolute filename
        strcpy(name, sound->name);
-       BLI_convertstringcode(name, G.sce, G.scene->r.cfra);
+       BLI_convertstringcode(name, G.sce);
        
        /* search through the list of loaded samples */
        sample = samples->first;
-       
-       while (sample)
-       {
+       while (sample) {
                strcpy(samplename, sample->name);
-               BLI_convertstringcode(samplename, G.sce, G.scene->r.cfra);
+               BLI_convertstringcode(samplename, G.sce);
                
-               if (strcmp(name, samplename) == 0)
-               {
+               if (strcmp(name, samplename) == 0)      {
                        break;
                }
                sample = sample->id.next;
@@ -835,16 +868,15 @@ bSample* sound_find_sample(bSound* sound)
 
 
 
-int sound_sample_is_null(bSoundsound)
+int sound_sample_is_null(bSound *sound)
 {
        int result = FALSE;
-       bSamplesample;
+       bSample *sample;
        
        if(ghSoundScene==NULL) sound_init_audio();
        
        /* find the right sample or else create one */
-       if (sound->sample == NULL)
-       {
+       if (sound->sample == NULL) {
                /* find... */
                sample = sound_find_sample(sound);
 
@@ -885,7 +917,7 @@ void sound_end_all_sounds(void)
 
 
 
-void sound_play_sound(bSoundsound)
+void sound_play_sound(bSound *sound)
 {
 #if GAMEBLENDER == 1
        if(ghSoundScene==NULL) sound_init_audio();
@@ -1002,9 +1034,6 @@ void sound_init_audio(void)
        SYS_SystemHandle hSystem = NULL;
        
        if(ghSoundScene==NULL) {
-               
-               printf("sound init audio\n");
-       
                hSystem = SYS_GetSystem();
                noaudio = SYS_GetCommandLineInt(hSystem,"noaudio",0);
                
@@ -1030,5 +1059,6 @@ void sound_exit_audio(void)
        if(ghSoundScene) {
                SND_DeleteScene(ghSoundScene);
                SND_ReleaseDevice();
+               ghSoundScene = NULL;
        }
 }