Thank you all for your help and suggestions, it's appreciated. Hopefully this thread will be helpful to future users who run into this as well.
The first-bar issue is useful to know, but in fact I had noticed the out-of-sync problem as part of a much longer piece. I just cut it down to get a simple example; the problem arises no matter which bar the notes arise.
I did make a longer example that might be easier to hear than my short excerpt, and I also found some very strange things going on with the sample editor.
The audio showing the long sample is here:
http://soundcloud.com/kendracute/long-sync-problem .
The screenshot showing the project from which this audio is taken is here:
. Note that the D3-F2 chord is still out-of-sync in the bounced AIF file corresponding to this MIDI. Note that the velocities are 32. The problem does not arise with other velocities.
I found several anomalies in the sample editor corresponding to the D3 sample for Yamaha Piano Hall. I am new to the sample editor so will describe my steps in some detail.
I opened the EXS24 sample editor from the inspector, clicking "edit". I played the D3 and F2 notes in the piano bar, then clicked on the sample names. For each of the two notes, there were two samples with slightly different names.
The waveform for D3 had two anomalies. First, in one of the two samples corresponding to D3, the waveform was silent for a while at the beginning of the sample. (Not sure what the time axis is).
Second, for the D3 waveform, the text indicated the sample came from GarageBand, not from Logic!
Here is the image of the sample editor that showed up when I clicked the D3 on the piano bar:
Note that there are two samples selected, and that they are named something to do with D#3 instead of D3. Not sure why that would be.
Anyway, here is the waveform for the first of the two samples corresponding to D3:
Note that there is a delay in this waveform. This delay is obviously the cause of the out-of-sync sound. Note as well that the sample seems to come from GarageBand. How that could be, I do not know.
Here for comparison is the waveform for the second of the two samples corresponding to D3:
Note that this starts at the beginning, unlike the first of the two sample corresponding to D3, but that it also comes from GarageBand, not from Logic.
Now, here is the edit window that appears when I click on the F2 note in the piano roll:
This looks just like the D3 edit window, except that it is using F2 and not F#2 as with the case of D3.
I did not upload the F2 window, but it looked OK to me, and the file name indicated the sample came from Logic not from Garageband like the D3 sample.
I reinstalled Logic and the same problem recurred (I stupidly loaded a larger old project, which had saved audio files, after reinstalling though - could this older project have somehow corrupted the whole Logic sample set?)
Could someone possibly check their sample for D3 in Yamaha Piano Hall at velocity of 32, and see if the name and waveform is the same as the one's I showed? (Assuming you are running Logic 9.1.5 (1700.9) (32-bit) .)