- if (ch->sfx->format.width == 1)
- {
- const signed char *sfx = (signed char *)sb->data + (ch->pos - sb->offset) * ch->sfx->format.channels;
- // Stereo sound support
- if (ch->sfx->format.channels == 2)
- {
- if (vol[6] + vol[7] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 8;
- paintbuffer[i].sample[1] += (sfx[1] * vol[1]) >> 8;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 8;
- paintbuffer[i].sample[3] += (sfx[1] * vol[3]) >> 8;
- paintbuffer[i].sample[4] += ((sfx[0]+sfx[1]) * vol[4]) >> 9;
- paintbuffer[i].sample[5] += ((sfx[0]+sfx[1]) * vol[5]) >> 9;
- paintbuffer[i].sample[6] += (sfx[0] * vol[6]) >> 8;
- paintbuffer[i].sample[7] += (sfx[1] * vol[7]) >> 8;
- sfx += 2;
- }
- }
- else if (vol[4] + vol[5] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 8;
- paintbuffer[i].sample[1] += (sfx[1] * vol[1]) >> 8;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 8;
- paintbuffer[i].sample[3] += (sfx[1] * vol[3]) >> 8;
- paintbuffer[i].sample[4] += ((sfx[0]+sfx[1]) * vol[4]) >> 9;
- paintbuffer[i].sample[5] += ((sfx[0]+sfx[1]) * vol[5]) >> 9;
- sfx += 2;
- }
- }
- else if (vol[2] + vol[3] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 8;
- paintbuffer[i].sample[1] += (sfx[1] * vol[1]) >> 8;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 8;
- paintbuffer[i].sample[3] += (sfx[1] * vol[3]) >> 8;
- sfx += 2;
- }
- }
- else if (vol[0] + vol[1] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 8;
- paintbuffer[i].sample[1] += (sfx[1] * vol[1]) >> 8;
- sfx += 2;
- }
- }
- }
- else if (ch->sfx->format.channels == 1)
- {
- if (vol[6] + vol[7] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 8;
- paintbuffer[i].sample[1] += (sfx[0] * vol[1]) >> 8;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 8;
- paintbuffer[i].sample[3] += (sfx[0] * vol[3]) >> 8;
- paintbuffer[i].sample[4] += (sfx[0] * vol[4]) >> 8;
- paintbuffer[i].sample[5] += (sfx[0] * vol[5]) >> 8;
- paintbuffer[i].sample[6] += (sfx[0] * vol[6]) >> 8;
- paintbuffer[i].sample[7] += (sfx[0] * vol[7]) >> 8;
- sfx += 1;
- }
- }
- else if (vol[4] + vol[5] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 8;
- paintbuffer[i].sample[1] += (sfx[0] * vol[1]) >> 8;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 8;
- paintbuffer[i].sample[3] += (sfx[0] * vol[3]) >> 8;
- paintbuffer[i].sample[4] += (sfx[0] * vol[4]) >> 8;
- paintbuffer[i].sample[5] += (sfx[0] * vol[5]) >> 8;
- sfx += 1;
- }
- }
- else if (vol[2] + vol[3] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 8;
- paintbuffer[i].sample[1] += (sfx[0] * vol[1]) >> 8;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 8;
- paintbuffer[i].sample[3] += (sfx[0] * vol[3]) >> 8;
- sfx += 1;
- }
- }
- else if (vol[0] + vol[1] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 8;
- paintbuffer[i].sample[1] += (sfx[0] * vol[1]) >> 8;
- sfx += 1;
- }
- }
- }
- else
- return true; // unsupported number of channels in sound
- }
- else if (ch->sfx->format.width == 2)
- {
- const signed short *sfx = (signed short *)sb->data + (ch->pos - sb->offset) * ch->sfx->format.channels;
- // Stereo sound support
- if (ch->sfx->format.channels == 2)
- {
- if (vol[6] + vol[7] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 16;
- paintbuffer[i].sample[1] += (sfx[1] * vol[1]) >> 16;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 16;
- paintbuffer[i].sample[3] += (sfx[1] * vol[3]) >> 16;
- paintbuffer[i].sample[4] += ((sfx[0]+sfx[1]) * vol[4]) >> 17;
- paintbuffer[i].sample[5] += ((sfx[0]+sfx[1]) * vol[5]) >> 17;
- paintbuffer[i].sample[6] += (sfx[0] * vol[6]) >> 16;
- paintbuffer[i].sample[7] += (sfx[1] * vol[7]) >> 16;
- sfx += 2;
- }
- }
- else if (vol[4] + vol[5] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 16;
- paintbuffer[i].sample[1] += (sfx[1] * vol[1]) >> 16;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 16;
- paintbuffer[i].sample[3] += (sfx[1] * vol[3]) >> 16;
- paintbuffer[i].sample[4] += ((sfx[0]+sfx[1]) * vol[4]) >> 17;
- paintbuffer[i].sample[5] += ((sfx[0]+sfx[1]) * vol[5]) >> 17;
- sfx += 2;
- }
- }
- else if (vol[2] + vol[3] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 16;
- paintbuffer[i].sample[1] += (sfx[1] * vol[1]) >> 16;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 16;
- paintbuffer[i].sample[3] += (sfx[1] * vol[3]) >> 16;
- sfx += 2;
- }
- }
- else if (vol[0] + vol[1] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 16;
- paintbuffer[i].sample[1] += (sfx[1] * vol[1]) >> 16;
- sfx += 2;
- }
- }
- }
- else if (ch->sfx->format.channels == 1)
- {
- if (vol[6] + vol[7] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 16;
- paintbuffer[i].sample[1] += (sfx[0] * vol[1]) >> 16;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 16;
- paintbuffer[i].sample[3] += (sfx[0] * vol[3]) >> 16;
- paintbuffer[i].sample[4] += (sfx[0] * vol[4]) >> 16;
- paintbuffer[i].sample[5] += (sfx[0] * vol[5]) >> 16;
- paintbuffer[i].sample[6] += (sfx[0] * vol[6]) >> 16;
- paintbuffer[i].sample[7] += (sfx[0] * vol[7]) >> 16;
- sfx += 1;
- }
- }
- else if (vol[4] + vol[5] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 16;
- paintbuffer[i].sample[1] += (sfx[0] * vol[1]) >> 16;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 16;
- paintbuffer[i].sample[3] += (sfx[0] * vol[3]) >> 16;
- paintbuffer[i].sample[4] += (sfx[0] * vol[4]) >> 16;
- paintbuffer[i].sample[5] += (sfx[0] * vol[5]) >> 16;
- sfx += 1;
- }
- }
- else if (vol[2] + vol[3] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 16;
- paintbuffer[i].sample[1] += (sfx[0] * vol[1]) >> 16;
- paintbuffer[i].sample[2] += (sfx[0] * vol[2]) >> 16;
- paintbuffer[i].sample[3] += (sfx[0] * vol[3]) >> 16;
- sfx += 1;
- }
- }
- else if (vol[0] + vol[1] > 0)
- {
- for (i = 0;i < count;i++)
- {
- paintbuffer[i].sample[0] += (sfx[0] * vol[0]) >> 16;
- paintbuffer[i].sample[1] += (sfx[0] * vol[1]) >> 16;
- sfx += 1;
- }
- }
- }
- else
- return true; // unsupported number of channels in sound