Bug 82

Summary: Saving gig from live mode corrupts the sound
Product: gigedit Reporter: Anders Dahnielson <anders>
Component: gigeditAssignee: Christian Schoenebeck <cuse>
Status: CLOSED FIXED    
Severity: blocker    
Priority: P2    
Version: SVN Trunk   
Hardware: PC   
OS: Linux   
URL: https://bb.linuxsampler.org/viewtopic.php?f=2&t=44&p=283#p275

Description Anders Dahnielson 2008-02-10 00:58:22 CET
Saving gig from live mode corrupts the sound.

What I did:

1.) Created a new gig in standalone gigedit.
2.) Added five samples.
3.) Added a region on C3.
4.) Added a velocity dimension split in eight zones.
5.) Saved everything to test.gig
6.) Loaded my newly created gig in LinuxSampler and opened the plugin gigedit.
7.) Added the samples to the zones.
8.) Sat the unity note for all dimension parts to C3.
9.) Made sure everything sounded fine.
10.) Saved everything, replacing test.gig
11.) Now everything sounds weird.

Then I redid the test completely in the standalone gigedit and everything worked
as expected. Don't know if this is a bug in gigedit or linuxsampler.
Comment 1 Andreas Persson 2008-02-10 17:14:45 CET
This is, at least, a bug in libgig, in the RIFF:Save() function. A fix is in CVS
now. I'll keep the report open until I hear if it works for you.
Comment 2 Anders Dahnielson 2008-02-10 20:54:05 CET
1) Created a new gig in stand alone mode: a velocity dimensions with two zones
at C3, added one sample to the gig and first zone, saved it. 
2) Loaded it in LinuxSampler, opened gigedit in live mode and added a second
sample to the gig and second zone.
3) Hit the C3 key on my keyboard lightly, producing the first sample as expected.
4) Hit the C3 key again, this time harder, producing a corrupt playback of the
second zone.
5) Get XRUN when LinuxSampler segfaults:


Loading instrument editor plugins...OK
Found matching editor 'gigedit' for instrument
('/home/anders/Studio/instruments/gig/Dahnielson/test.gig', 0) having data
structure ('libgig','3.2.1')
InstrumentEditor::Launch(instr=68f190,type=libgig,version=3.2.1)
InstrumentEditor::Main()
Entered Gigedit Main() loop :)
Initializing 3rd party services needed by gigedit.
Adding sample /home/anders/Studio/instruments/wav/TDH/wav/ff10.wav
dim=1 z=1 dimensionsource=130 split_type=0 zones=2 zone_size=64.000000
Drop received sample "ff10"
Unable to cache sample - maybe memory full!
>>> FATAL ERROR: Segmentation fault (SIGSEGV) occured! <<<
Comment 3 Anders Dahnielson 2008-02-10 20:55:15 CET
Forget that. I haven't built you fix yet!!! Sorry.
Comment 4 Anders Dahnielson 2008-02-10 21:15:55 CET
Nope. Get the segfault result above with the fix. No suprise since I don't even
use "Save". Well, I used it in stand alone mode and it worked as expected. It's
the adding of samples in live mode that's causing the corruption and now segfault.

It's pretty obvious why: I've added samples but they are not yet saved to the
gig that is loaded, hence no samples to stream. But that's something the user
should be protected from and not need to think about. So I guess it's a bug to
let something bad happen.

Will now proceed to save the gig before hitting any keys.
Comment 5 Anders Dahnielson 2008-02-10 21:28:50 CET
1) Add a region and a sample to the gig in live mode.
2) Saving it as a new file using "Save as" (have to, it's an "Unsaved gig" when
opened live).
3) Add a second sample to the gig and the new region.
4) Saving it using "Save".
5) Loading the new gig in LinuxSampler.
6) Works dandy.
Comment 6 Anders Dahnielson 2008-02-10 21:39:47 CET
(In reply to comment #5)
> 1) Add a region and a sample to the gig in live mode.
> 2) Saving it as a new file using "Save as" (have to, it's an "Unsaved gig" when
> opened live).
> 3) Add a second sample to the gig and the new region.
> 4) Saving it using "Save".
> 5) Loading the new gig in LinuxSampler.
> 6) Works dandy.

Of course, if I don't reload it (step 5) before hitting a key LS will use the
edited in memory meta data that doesn't match with the sample data in the gig.
If I overwrite the old gig when saving (in hope to get everything to match) it
will still fail. This synchronization business between what's in memory, whats
in a gig on disk and what LS thinks is in the gig, is a bit confusing to a user.
Comment 7 Christian Schoenebeck 2008-12-14 14:19:46 CET
Marking this one as blocker, as it should be fixed before the upcoming 
release.
Comment 8 Christian Schoenebeck 2009-01-10 13:52:31 CET
Ok, I try to fix this issue soon ...

(In reply to comment #6)
> (In reply to comment #5)
> > 1) Add a region and a sample to the gig in live mode.
> > 2) Saving it as a new file using "Save as" (have to, it's an "Unsaved gig" 
when
> > opened live).
> > 3) Add a second sample to the gig and the new region.
> > 4) Saving it using "Save".
> > 5) Loading the new gig in LinuxSampler.
> > 6) Works dandy.
> 
> Of course, if I don't reload it (step 5) before hitting a key LS will use 
the
> edited in memory meta data that doesn't match with the sample data in the 
gig.
> If I overwrite the old gig when saving (in hope to get everything to match) 
it
> will still fail. This synchronization business between what's in memory, 
whats
> in a gig on disk and what LS thinks is in the gig, is a bit confusing to a 
user.
>

If you omit step 5 (reloading the gig), LS will play the old (crap) sample 
data, but it will _not_ crash, right?
Comment 9 Anders Dahnielson 2009-01-10 14:14:27 CET
(In reply to comment #8)
> If you omit step 5 (reloading the gig), LS will play the old (crap) sample 
> data, but it will _not_ crash, right?

No, it has never crashed for me.
Comment 10 Christian Schoenebeck 2009-03-01 23:35:28 CET
I just commited fixes all over the place (libgig, linuxsampler, gigedit) to 
CVS. Please check if those fixes finally resolve this issue!

Now when adding a new sample in live-mode in gigedit, you will hear nothing 
but silence when triggering that sample (before you save your changes that is) 
and it shouldn't crash either. But I'm not absolutely sure if it's really 
crash-safe now, because voices are still spawned for such "new" samples and I 
haven't investigated that part of code in LS yet.

Then when you save the just modified file in gigedit, the sampler will now be 
informed about the samples that have just been added and the sampler will 
automatically (re)cache those samples, so after saving the file in gigedit you 
should immediatelly be able to use the new samples while playing.

Please let me know!
Comment 11 Christian Schoenebeck 2009-03-08 11:55:25 CET
Considered to be fixed from my side now.